deffont.c - enscript - GNU Enscript
(HTM) git clone git://thinkerwim.org/enscript.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
deffont.c (8030B)
---
1 /*
2 * The default font.
3 * Copyright (c) 1995, 1996, 1997 Markku Rossi.
4 *
5 * Author: Markku Rossi <mtr@iki.fi>
6 */
7
8 /*
9 * Enscript is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Enscript is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Enscript. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "afmint.h"
24 #include "afm.h"
25
26
27 /*
28 * Static variables.
29 */
30
31 static AFMEncodingTable builtin_courier[] =
32 {
33 {32, "space"},
34 {33, "exclam"},
35 {34, "quotedbl"},
36 {35, "numbersign"},
37 {36, "dollar"},
38 {37, "percent"},
39 {38, "ampersand"},
40 {39, "quoteright"},
41 {40, "parenleft"},
42 {41, "parenright"},
43 {42, "asterisk"},
44 {43, "plus"},
45 {44, "comma"},
46 {45, "hyphen"},
47 {46, "period"},
48 {47, "slash"},
49 {48, "zero"},
50 {49, "one"},
51 {50, "two"},
52 {51, "three"},
53 {52, "four"},
54 {53, "five"},
55 {54, "six"},
56 {55, "seven"},
57 {56, "eight"},
58 {57, "nine"},
59 {58, "colon"},
60 {59, "semicolon"},
61 {60, "less"},
62 {61, "equal"},
63 {62, "greater"},
64 {63, "question"},
65 {64, "at"},
66 {65, "A"},
67 {66, "B"},
68 {67, "C"},
69 {68, "D"},
70 {69, "E"},
71 {70, "F"},
72 {71, "G"},
73 {72, "H"},
74 {73, "I"},
75 {74, "J"},
76 {75, "K"},
77 {76, "L"},
78 {77, "M"},
79 {78, "N"},
80 {79, "O"},
81 {80, "P"},
82 {81, "Q"},
83 {82, "R"},
84 {83, "S"},
85 {84, "T"},
86 {85, "U"},
87 {86, "V"},
88 {87, "W"},
89 {88, "X"},
90 {89, "Y"},
91 {90, "Z"},
92 {91, "bracketleft"},
93 {92, "backslash"},
94 {93, "bracketright"},
95 {94, "asciicircum"},
96 {95, "underscore"},
97 {96, "quoteleft"},
98 {97, "a"},
99 {98, "b"},
100 {99, "c"},
101 {100, "d"},
102 {101, "e"},
103 {102, "f"},
104 {103, "g"},
105 {104, "h"},
106 {105, "i"},
107 {106, "j"},
108 {107, "k"},
109 {108, "l"},
110 {109, "m"},
111 {110, "n"},
112 {111, "o"},
113 {112, "p"},
114 {113, "q"},
115 {114, "r"},
116 {115, "s"},
117 {116, "t"},
118 {117, "u"},
119 {118, "v"},
120 {119, "w"},
121 {120, "x"},
122 {121, "y"},
123 {122, "z"},
124 {123, "braceleft"},
125 {124, "bar"},
126 {125, "braceright"},
127 {126, "asciitilde"},
128 {161, "exclamdown"},
129 {162, "cent"},
130 {163, "sterling"},
131 {164, "fraction"},
132 {165, "yen"},
133 {166, "florin"},
134 {167, "section"},
135 {168, "currency"},
136 {169, "quotesingle"},
137 {170, "quotedblleft"},
138 {171, "guillemotleft"},
139 {172, "guilsinglleft"},
140 {173, "guilsinglright"},
141 {174, "fi"},
142 {175, "fl"},
143 {177, "endash"},
144 {178, "dagger"},
145 {179, "daggerdbl"},
146 {180, "periodcentered"},
147 {182, "paragraph"},
148 {183, "bullet"},
149 {184, "quotesinglbase"},
150 {185, "quotedblbase"},
151 {186, "quotedblright"},
152 {187, "guillemotright"},
153 {188, "ellipsis"},
154 {189, "perthousand"},
155 {191, "questiondown"},
156 {193, "grave"},
157 {194, "acute"},
158 {195, "circumflex"},
159 {196, "tilde"},
160 {197, "macron"},
161 {198, "breve"},
162 {199, "dotaccent"},
163 {200, "dieresis"},
164 {202, "ring"},
165 {203, "cedilla"},
166 {205, "hungarumlaut"},
167 {206, "ogonek"},
168 {207, "caron"},
169 {208, "emdash"},
170 {225, "AE"},
171 {227, "ordfeminine"},
172 {232, "Lslash"},
173 {233, "Oslash"},
174 {234, "OE"},
175 {235, "ordmasculine"},
176 {241, "ae"},
177 {245, "dotlessi"},
178 {248, "lslash"},
179 {249, "oslash"},
180 {250, "oe"},
181 {251, "germandbls"},
182 {-1, "Aacute"},
183 {-1, "Acircumflex"},
184 {-1, "Adieresis"},
185 {-1, "Agrave"},
186 {-1, "Aring"},
187 {-1, "Atilde"},
188 {-1, "Ccedilla"},
189 {-1, "Eacute"},
190 {-1, "Ecircumflex"},
191 {-1, "Edieresis"},
192 {-1, "Egrave"},
193 {-1, "Eth"},
194 {-1, "Gcaron"},
195 {-1, "IJ"},
196 {-1, "Iacute"},
197 {-1, "Icircumflex"},
198 {-1, "Idieresis"},
199 {-1, "Idot"},
200 {-1, "Igrave"},
201 {-1, "LL"},
202 {-1, "Ntilde"},
203 {-1, "Oacute"},
204 {-1, "Ocircumflex"},
205 {-1, "Odieresis"},
206 {-1, "Ograve"},
207 {-1, "Otilde"},
208 {-1, "Scaron"},
209 {-1, "Scedilla"},
210 {-1, "Thorn"},
211 {-1, "Uacute"},
212 {-1, "Ucircumflex"},
213 {-1, "Udieresis"},
214 {-1, "Ugrave"},
215 {-1, "Yacute"},
216 {-1, "Ydieresis"},
217 {-1, "Zcaron"},
218 {-1, "aacute"},
219 {-1, "acircumflex"},
220 {-1, "adieresis"},
221 {-1, "agrave"},
222 {-1, "aring"},
223 {-1, "arrowboth"},
224 {-1, "arrowdown"},
225 {-1, "arrowleft"},
226 {-1, "arrowright"},
227 {-1, "arrowup"},
228 {-1, "atilde"},
229 {-1, "brokenbar"},
230 {-1, "ccedilla"},
231 {-1, "center"},
232 {-1, "copyright"},
233 {-1, "dectab"},
234 {-1, "degree"},
235 {-1, "divide"},
236 {-1, "down"},
237 {-1, "eacute"},
238 {-1, "ecircumflex"},
239 {-1, "edieresis"},
240 {-1, "egrave"},
241 {-1, "eth"},
242 {-1, "format"},
243 {-1, "gcaron"},
244 {-1, "graybox"},
245 {-1, "iacute"},
246 {-1, "icircumflex"},
247 {-1, "idieresis"},
248 {-1, "igrave"},
249 {-1, "ij"},
250 {-1, "indent"},
251 {-1, "largebullet"},
252 {-1, "left"},
253 {-1, "lira"},
254 {-1, "ll"},
255 {-1, "logicalnot"},
256 {-1, "merge"},
257 {-1, "minus"},
258 {-1, "mu"},
259 {-1, "multiply"},
260 {-1, "notegraphic"},
261 {-1, "ntilde"},
262 {-1, "oacute"},
263 {-1, "ocircumflex"},
264 {-1, "odieresis"},
265 {-1, "ograve"},
266 {-1, "onehalf"},
267 {-1, "onequarter"},
268 {-1, "onesuperior"},
269 {-1, "otilde"},
270 {-1, "overscore"},
271 {-1, "plusminus"},
272 {-1, "prescription"},
273 {-1, "registered"},
274 {-1, "return"},
275 {-1, "scaron"},
276 {-1, "scedilla"},
277 {-1, "square"},
278 {-1, "stop"},
279 {-1, "tab"},
280 {-1, "thorn"},
281 {-1, "threequarters"},
282 {-1, "threesuperior"},
283 {-1, "trademark"},
284 {-1, "twosuperior"},
285 {-1, "uacute"},
286 {-1, "ucircumflex"},
287 {-1, "udieresis"},
288 {-1, "ugrave"},
289 {-1, "up"},
290 {-1, "yacute"},
291 {-1, "ydieresis"},
292 {-1, "zcaron"},
293 {0, NULL},
294 };
295
296 #define NUM_CHARACTER_METRICS \
297 (sizeof (builtin_courier) / sizeof (AFMEncodingTable) - 1)
298
299 /*
300 * Public functions.
301 */
302
303 AFMError
304 afm_open_default_font (AFMHandle handle, AFMFont *font_return)
305 {
306 AFMFont font;
307 AFMIndividualCharacterMetrics *cm;
308 int i;
309
310 /* Alloc memory. */
311
312 font = (AFMFont) calloc (1, sizeof (*font));
313 if (font == NULL)
314 goto error_out;
315 font->private
316 = (struct afm_font_private_data_st *) calloc (1, sizeof (*font->private));
317 if (font->private == NULL)
318 goto error_out;
319 font->private->fontnames = strhash_init ();
320 if (font->private->fontnames == NULL)
321 goto error_out;
322
323 /* Version. */
324 font->version = 4.0;
325
326 /* Global Font Info. */
327
328 font->global_info.FontName = (char *) malloc (strlen ("Courier") + 1);
329 if (font->global_info.FontName == NULL)
330 goto error_out;
331 strcpy (font->global_info.FontName, "Courier");
332
333 font->global_info.FontBBox_llx = -40.0;
334 font->global_info.FontBBox_lly = -290.0;
335 font->global_info.FontBBox_urx = 640.0;
336 font->global_info.FontBBox_ury = 795.0;
337
338 /* Writing directions. */
339 font->writing_direction_metrics[0].is_valid = AFMTrue;
340 font->writing_direction_metrics[0].IsFixedPitch = AFMTrue;
341 font->writing_direction_metrics[0].CharWidth_x = 600.0;
342 font->writing_direction_metrics[0].CharWidth_y = 0.0;
343
344 /* Character Metrics. */
345
346 font->num_character_metrics = NUM_CHARACTER_METRICS;
347 font->character_metrics
348 = (AFMIndividualCharacterMetrics *)
349 calloc (NUM_CHARACTER_METRICS, sizeof (AFMIndividualCharacterMetrics));
350 if (font->character_metrics == NULL)
351 goto error_out;
352
353 for (i = 0; builtin_courier[i].character; i++)
354 {
355 cm = &font->character_metrics[i];
356 cm->name = (char *) malloc (strlen (builtin_courier[i].character) + 1);
357 if (cm->name == NULL)
358 goto error_out;
359 strcpy (cm->name, builtin_courier[i].character);
360
361 if (!strhash_put (font->private->fontnames, cm->name,
362 strlen (cm->name), cm, NULL))
363 goto error_out;
364
365 cm->character_code = builtin_courier[i].code;
366 cm->w0x = 600.0;
367 cm->w0y = 0.0;
368 }
369
370 *font_return = font;
371
372 return AFM_SUCCESS;
373
374
375 error_out:
376 (void) afm_close_font (font);
377
378 return AFM_ERROR_MEMORY;
379 }