First attempt at debianization
[erwise] / Xl / XlStyle.c
1 /*
2  * XlStyle.c --
3  *
4  * Author: Teemu Rantanen <tvr@cs.hut.fi>
5  * Copyright (c) 1992 Teemu Rantanen
6  *                    All rights reserved
7  *
8  * Created: Thu Mar  5 00:56:46 1992 tvr
9  * Last modified: Wed May 13 06:21:48 1992 tvr
10  *
11  */
12
13 #include <stdio.h>
14 #include <X11/Xlib.h>
15
16 #include "HTAnchor.h"
17 #include "HTStyle.h"
18 #include "../HText/HText.h"
19
20 #include "Xl.h"
21 #include "XlStyle.h"
22 #include "XlTypes.h"
23 #include "XlFormatText.h"
24
25 #include "XlDefaultFonts.h"
26
27 #include "XlConfig.h"
28
29 int xl_object_mode();
30
31 /*
32  * All hypertext styles. Also needed configure data (font configure-name)
33  */
34
35 #define CREATE_STYLE(font, cname, tag, mode, first, left, right) \
36 {NULL, font, 0, cname, tag, 0, mode, first, left, right, 140, 100, 100, 50}
37
38 XlStyle_t XlStyles[] =
39 {
40     CREATE_STYLE(FONT_NORMAL,
41                  C_FONT_NORMAL,
42                  "P",
43                  STYLE_LEFTIFY,
44                  0, 0, 100),
45
46     CREATE_STYLE(FONT_LIST,
47                  C_FONT_LIST,
48                  "UL",
49                  STYLE_LEFTIFY,
50                  0, 5, 95),
51
52     CREATE_STYLE(FONT_LISTCOMPACT,
53                  C_FONT_LISTCOMPACT,
54                  "ULC",
55                  STYLE_LEFTIFY,
56                  0, 5, 95),
57
58     CREATE_STYLE(FONT_GLOSSARY,
59                  C_FONT_GLOSSARY,
60                  "DL",
61                  STYLE_LEFTIFY | STYLE_CHANGE_REGION_ON_TAB,
62                  0, 0, 100),
63
64     CREATE_STYLE(FONT_GLOSSARYCOMPACT,
65                  C_FONT_GLOSSARYCOMPACT,
66                  "DLC",
67                  STYLE_LEFTIFY | STYLE_CHANGE_REGION_ON_TAB,
68                  0, 0, 100),
69
70     CREATE_STYLE(FONT_EXAMPLE,
71                  C_FONT_EXAMPLE,
72                  "XMP",
73                  STYLE_LEFTIFY | STYLE_RAW,
74                  0, 0, 100),
75
76     CREATE_STYLE(FONT_LISTING,
77                  C_FONT_LISTING,
78                  "LISTING",
79                  STYLE_LEFTIFY | STYLE_RAW,
80                  0, 0, 100),
81
82     CREATE_STYLE(FONT_ADDRESS,
83                  C_FONT_ADDRESS,
84                  "ADDRESS",
85                  STYLE_LEFTIFY,
86                  0, 0, 100),
87
88     CREATE_STYLE(FONT_HEADER1,
89                  C_FONT_HEADER1,
90                  "H1",
91                  STYLE_CENTER,
92                  0, 0, 100),
93
94     CREATE_STYLE(FONT_HEADER2,
95                  C_FONT_HEADER2,
96                  "H2",
97                  STYLE_CENTER,
98                  0, 0, 100),
99
100     CREATE_STYLE(FONT_HEADER3,
101                  C_FONT_HEADER3,
102                  "H3",
103                  STYLE_CENTER,
104                  0, 0, 100),
105
106     CREATE_STYLE(FONT_HEADER4,
107                  C_FONT_HEADER4,
108                  "H4",
109                  STYLE_CENTER,
110                  0, 0, 100),
111
112     CREATE_STYLE(FONT_HEADER5,
113                  C_FONT_HEADER5,
114                  "H5",
115                  STYLE_CENTER,
116                  0, 0, 100),
117
118     CREATE_STYLE(FONT_HEADER6,
119                  C_FONT_HEADER6,
120                  "H6",
121                  STYLE_CENTER,
122                  0, 0, 100),
123
124     CREATE_STYLE(FONT_HEADER7,
125                  C_FONT_HEADER7,
126                  "H7",
127                  STYLE_CENTER,
128                  0, 0, 100),
129
130     CREATE_STYLE(NULL,
131                  NULL,
132                  NULL,
133                  0,
134                  0, 0, 0),
135 };
136
137
138 /*
139  * How much to increase y coordinate after this line ?
140  */
141 /* ARGS_IN_USE */
142
143 int xl_linespace(p_start, p_end)
144 HTextObject_t *p_start;
145 HTextObject_t *p_end;
146 {
147     if (p_start->xl_data->style->fontinfo) {
148
149         return ((p_start->xl_data->style->fontinfo->ascent +
150                  p_start->xl_data->style->fontinfo->descent) *
151                 p_start->xl_data->style->space_line) / 100;
152     } else {
153
154         return p_start->xl_data->style->space_line / 100;
155     }
156 }
157
158
159 int xl_paragraphspace(p_start, p_end)
160 HTextObject_t *p_start;
161 HTextObject_t *p_end;
162 {
163     if (p_start->xl_data->style->fontinfo) {
164
165         return ((p_start->xl_data->style->fontinfo->ascent +
166                  p_start->xl_data->style->fontinfo->descent) *
167                 p_start->xl_data->style->space_paragraph) / 100;
168     } else {
169
170         return p_start->xl_data->style->space_paragraph / 100;
171     }
172 }
173
174
175 int xl_stylespace(p_start, p_end)
176 HTextObject_t *p_start;
177 HTextObject_t *p_end;
178 {
179     if (p_start->xl_data->style->fontinfo) {
180
181         return ((p_start->xl_data->style->fontinfo->ascent +
182                  p_start->xl_data->style->fontinfo->descent) *
183                 p_start->xl_data->style->space_style) / 100;
184
185     } else {
186
187         return 1;
188     }
189 }
190
191
192 int xl_stylespace_before(p_start, p_end)
193 HTextObject_t *p_start;
194 HTextObject_t *p_end;
195 {
196     if (p_start->xl_data->style->fontinfo) {
197
198         return ((p_start->xl_data->style->fontinfo->ascent +
199                  p_start->xl_data->style->fontinfo->descent) *
200                 p_start->xl_data->style->space_style_before) / 100;
201     } else {
202
203         return 1;
204     }
205 }
206
207
208 /*
209  * How much to increase x-coordinate after this object ?
210  */
211 /* ARGS_IN_USE */
212 int xl_wordgap(p)
213 HTextObject_t *p;
214 {
215     if (xl_object_mode(p) & STYLE_RAW)
216         return 0;
217     else
218         return p->xl_data->style->char_width;
219 }
220
221
222 /*
223  * Return width of a character 'a'. Used to mostly when calculating
224  * tabulator spaces.
225  */
226 int xl_character_width(p)
227 HTextObject_t *p;
228 {
229     return p->xl_data->style->char_width;
230 }
231
232
233 /*
234  * Return style of this object
235  */
236 int xl_object_style(p)
237 HTextObject_t *p;
238 {
239     return p->xl_data->style->mode & STYLE_MASK;
240 }
241
242
243 /*
244  * Return mode of this object
245  */
246 int xl_object_mode(p)
247 HTextObject_t *p;
248 {
249     return p->xl_data->style->mode;
250 }
251
252
253 /*
254  * Calculate position of a coordinate according to left and right margins
255  */
256
257 int xl_calc_position(p, which, left, right)
258 HTextObject_t *p;
259 int which;
260 int left;
261 int right;
262 {
263     int r = 0;
264     int delta = right - left;
265
266     XlStyle_t *s = p->xl_data->style;
267
268     if (which & I_LEFT) {
269         r += (s->left * delta) / 100;
270     }
271     if (which & I_MIDDLE_L) {
272         r += (MIDDLE_L_HACK * delta) / 100;
273     }
274     if (which & I_MIDDLE_R) {
275         r += (MIDDLE_R_HACK * delta) / 100;
276     }
277     if (which & I_RIGHT) {
278         r += (s->right * delta) / 100;
279     }
280     if (which & I_FIRST) {
281         r += (s->indent1st * delta) / 100;
282     }
283     r += left;
284
285     return r;
286 }