Fix buffer overflow in dump_ps_page_header
[enscript.git] / afmlib / afm.h
1 /*
2  * Public header file.
3  * Copyright (c) 1995-1998 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 #ifndef AFM_H
24 #define AFM_H
25
26 #ifndef ___P
27 #if PROTOTYPES
28 #define ___P(protos) protos
29 #else /* no PROTOTYPES */
30 #define ___P(protos) ()
31 #endif /* no PROTOTYPES */
32 #endif
33
34 /**********************************************************************
35  *
36  *      AFM file entities.
37  *
38  **********************************************************************/
39
40 /* AFM types. */
41
42 #define AFM_TYPE_STRING         1
43 #define AFM_TYPE_NAME           2
44 #define AFM_TYPE_NUMBER         3
45 #define AFM_TYPE_INTEGER        4
46 #define AFM_TYPE_ARRAY          5
47 #define AFM_TYPE_BOOLEAN        6
48
49 typedef char *AFMString;
50 typedef char *AFMName;
51 typedef double AFMNumber;
52 typedef long AFMInteger;
53
54 typedef enum
55 {
56   AFMFalse = 0,
57   AFMTrue = 1
58 } AFMBoolean;
59
60 typedef struct afm_array_st *AFMArray;
61
62 struct afm_node_st
63 {
64   int type;
65
66   union
67     {
68       AFMString string;
69       AFMName name;
70       AFMNumber number;
71       AFMInteger integer;
72       AFMArray array;
73       AFMBoolean boolean;
74     } u;
75 };
76
77 typedef struct afm_node_st AFMNode;
78
79 struct afm_array_st
80 {
81   AFMNumber num_items;
82   AFMNode *items;
83 };
84
85
86 /* AFM file data structures. */
87
88 /*
89  * Sorry!  I know that those mixed case variable names are ugly,
90  * but this is the way how they are written in Adobe's document
91  * so I think that this is the best way for documentary reasons.
92  */
93
94 /* Global Font Information*/
95 struct global_font_information_st
96 {
97   AFMString FontName;
98   AFMString FullName;
99   AFMString FamilyName;
100   AFMString Weight;
101   AFMNumber FontBBox_llx;
102   AFMNumber FontBBox_lly;
103   AFMNumber FontBBox_urx;
104   AFMNumber FontBBox_ury;
105   AFMString Version;
106   AFMString Notice;
107   AFMString EncodingScheme;
108   AFMInteger MappingScheme;
109   AFMInteger EscChar;
110   AFMString CharacterSet;
111   AFMInteger Characters;
112   AFMBoolean IsBaseFont;
113   AFMNumber VVector_0;
114   AFMNumber VVector_1;
115   AFMBoolean IsFixedV;
116   AFMNumber CapHeight;
117   AFMNumber XHeight;
118   AFMNumber Ascender;
119   AFMNumber Descender;
120   AFMArray BlendAxisTypes;
121   AFMArray BlendDesignPositions;
122   AFMArray BlendDesignMap;
123   AFMArray WeightVector;
124 };
125
126 typedef struct global_font_information_st AFMGlobalFontInformation;
127
128
129 /* Writing Direction Metrics. */
130 struct writing_direction_metrics_st
131 {
132   AFMBoolean is_valid;
133   AFMNumber UnderlinePosition;
134   AFMNumber UnderlineThickness;
135   AFMNumber ItalicAngle;
136   AFMNumber CharWidth_x;
137   AFMNumber CharWidth_y;
138   AFMBoolean IsFixedPitch;
139 };
140
141 typedef struct writing_direction_metrics_st AFMWritingDirectionMetrics;
142
143
144 /* Multiple Master Axis Information. */
145 struct multiple_master_axis_info_st
146 {
147   AFMString AxisType;
148   AFMString AxisLabel;
149 };
150
151 typedef struct multiple_master_axis_info_st AFMMultipleMasterAxisInformation;
152
153
154 /* Individual Character Metrics. */
155
156 struct ligature_st
157 {
158   AFMName successor;
159   AFMName ligature;
160 };
161
162 typedef struct ligature_st AFMLigature;
163
164 /* Single individual character. */
165 struct individual_character_metrics_st
166 {
167   AFMInteger character_code;    /* default charcode (-1 if not encoded) */
168   AFMNumber w0x;                /* character width x in writing direction 0 */
169   AFMNumber w0y;                /* character width y in writing direction 0 */
170   AFMNumber w1x;                /* character width x in writing direction 1 */
171   AFMNumber w1y;                /* character width y in writing direction 1 */
172   AFMName name;                 /* character name */
173   AFMNumber vv_x;               /* local VVector x */
174   AFMNumber vv_y;               /* local VVector y */
175
176   /* character bounding box. */
177   AFMNumber llx;
178   AFMNumber lly;
179   AFMNumber urx;
180   AFMNumber ury;
181
182   AFMNumber num_ligatures;
183   AFMLigature *ligatures;
184 };
185
186 typedef struct individual_character_metrics_st AFMIndividualCharacterMetrics;
187
188
189 /* Kerning Data. */
190
191 /* Track Kerning Data. */
192 struct track_kern_st
193 {
194   AFMInteger degree;
195   AFMNumber min_ptsize;
196   AFMNumber min_kern;
197   AFMNumber max_ptsize;
198   AFMNumber max_kern;
199 };
200
201 typedef struct track_kern_st AFMTrackKern;
202
203
204 /* Pair-Wise Kerning. */
205 struct pair_wise_kerning_st
206 {
207   AFMName name1;
208   AFMName name2;
209   AFMNumber kx;
210   AFMNumber ky;
211 };
212
213 typedef struct pair_wise_kerning_st AFMPairWiseKerning;
214
215
216 /* Composite fonts. */
217
218 /* Single composite component. */
219 struct composite_component_st
220 {
221   AFMName name;
222   AFMNumber deltax;
223   AFMNumber deltay;
224 };
225
226 typedef struct composite_component_st AFMCompositeComponent;
227
228 struct composite_st
229 {
230   AFMName name;
231   AFMInteger num_components;
232   AFMCompositeComponent *components;
233 };
234
235 typedef struct composite_st AFMComposite;
236
237 \f
238 /**********************************************************************
239  *
240  *      Library API.
241  *
242  **********************************************************************/
243
244 /* Constants. */
245
246 #define UNITS_PER_POINT 1000
247
248 /* Successful operation. */
249 #define AFM_SUCCESS     0
250
251 /*
252  * AFM information levels.  The AFM libarary returns always Global
253  * Font information, Writing Direction Metrics and Individual
254  * Character Metrics.  Other fields can be retrieved by defining some
255  * of the following flags to afm_open_{font, file}() functions.
256  */
257 #define AFM_I_MINIMUM           0x00
258 #define AFM_I_COMPOSITES        0x01
259 #define AFM_I_KERN_PAIRS        0x02
260 #define AFM_I_TRACK_KERNS       0x04
261 #define AFM_I_ALL               0xffffffff
262
263 /*
264  * Flags for the encoding functions.
265  */
266 #define AFM_ENCODE_ACCEPT_COMPOSITES    0x01
267
268 typedef unsigned int AFMError;
269
270 typedef struct afm_handle_st *AFMHandle;
271
272 /* Supported encoding types. */
273 typedef enum
274 {
275   AFM_ENCODING_DEFAULT,         /* Font's default encoding. */
276   AFM_ENCODING_ISO_8859_1,      /* ISO-8859-1 */
277   AFM_ENCODING_ISO_8859_2,      /* ISO-8859-2 */
278   AFM_ENCODING_ISO_8859_3,      /* ISO-8859-3 */
279   AFM_ENCODING_ISO_8859_4,      /* ISO-8859-4 */
280   AFM_ENCODING_ISO_8859_5,      /* ISO-8859-5 */
281   AFM_ENCODING_ISO_8859_7,      /* ISO-8859-7 */
282   AFM_ENCODING_ISO_8859_9,      /* ISO-8859-9 */
283   AFM_ENCODING_ISO_8859_10,     /* ISO-8859-10 */
284   AFM_ENCODING_IBMPC,           /* IBM PC */
285   AFM_ENCODING_ASCII,           /* 7 bit ASCII */
286   AFM_ENCODING_MAC,             /* Mac */
287   AFM_ENCODING_VMS,             /* VMS multinational */
288   AFM_ENCODING_HP8,             /* HP Roman-8 */
289   AFM_ENCODING_KOI8             /* Adobe Standard Cyrillic Font KOI8 */
290 } AFMEncoding;
291
292 /* Special encoding types for individual characters. */
293 #define AFM_ENC_NONE            ((void *) 0)
294 #define AFM_ENC_NON_EXISTENT    ((void *) 1)
295
296
297 /* AFM information for a single PostScript font. */
298
299 struct afm_font_st
300 {
301   /* AFM Library's private data. */
302   struct afm_font_private_data_st *private;
303
304   AFMNumber version;            /* AFM format specification version number. */
305   unsigned int info_level;
306
307   /*
308    * Current font encoding.  Following values are valid:
309    *
310    *   AFM_ENC_NONE             character is not encoded
311    *   AFM_ENC_NON_EXISTENT     character is encoded, but font does not
312    *                            have the specified character
313    *   <pointer to character's metrics>
314    *                            character is encoded and it exists in font
315    */
316   AFMIndividualCharacterMetrics *encoding[256];
317
318   AFMGlobalFontInformation global_info;
319   AFMWritingDirectionMetrics writing_direction_metrics[2];
320
321   AFMInteger num_character_metrics;
322   AFMIndividualCharacterMetrics *character_metrics;
323
324   AFMInteger num_composites;
325   AFMComposite *composites;
326
327   AFMInteger num_kern_pairs;
328   AFMPairWiseKerning *kern_pairs;
329
330   AFMInteger num_track_kerns;
331   AFMTrackKern *track_kerns;
332 };
333
334 typedef struct afm_font_st *AFMFont;
335
336
337 \f
338 /*
339  * Prototypes for public functions.
340  */
341
342 /*
343  * Format error <error> to human readable format to buffer <buf>.
344  * Buffer must be long enough for error messages (256 bytes is good).
345  */
346 void afm_error_to_string ___P ((AFMError error, char *buf));
347
348 /*
349  * Open AFM library.  <path> specifies the search path for the AFM
350  * files.  A handle to the library is returned in <handle_return>.
351  */
352 AFMError afm_create ___P ((const char *path, unsigned int verbose_level,
353                            AFMHandle *handle_return));
354
355 /*
356  * Close AFM library handle <handle>.
357  */
358 AFMError afm_destroy ___P ((AFMHandle handle));
359
360 /*
361  * Set AFM library's verbose level to <level>.  Value 0 means "no output".
362  */
363 AFMError afm_set_verbose ___P ((AFMHandle handle, unsigned int level));
364
365 /*
366  * Return a prefix to the font <fontname>'s data.  Various font
367  * resource file names can be constructed from the returned prefix:
368  *   AFM        <prefix>.afm
369  *   PFA        <prefix>.pfa
370  *
371  * Returned prefix belongs to AFM library, user should not modify it.
372  */
373 AFMError afm_font_prefix ___P ((AFMHandle handle, const char *fontname,
374                                 const char **prefix_return));
375
376 /*
377  * Open font <name> and return font handle in <font_return>.
378  */
379 AFMError afm_open_font ___P ((AFMHandle handle, unsigned int info_level,
380                               const char *name, AFMFont *font_return));
381
382 /*
383  * Open AFM file <filename> and return font handle in <font_return>.
384  */
385 AFMError afm_open_file ___P ((AFMHandle handle, unsigned int info_level,
386                               const char *filename, AFMFont *font_return));
387
388 /*
389  * Open built-in default font (Courier).
390  */
391 AFMError afm_open_default_font ___P ((AFMHandle handle, AFMFont *font_return));
392
393 /*
394  * Close font <font>.
395  */
396 AFMError afm_close_font ___P ((AFMFont font));
397
398 /*
399  * Dump font information to file <fp>.
400  */
401 void afm_font_dump ___P ((FILE *fp, AFMFont font));
402
403 /*
404  * Return the width of the string <string, stringlen>.
405  */
406 AFMError afm_font_stringwidth ___P ((AFMFont font, AFMNumber ptsize,
407                                      char *string, unsigned int stringlen,
408                                      AFMNumber *w0x_return,
409                                      AFMNumber *w0y_return));
410
411 /*
412  * Return the width of the character <ch>.
413  */
414 AFMError afm_font_charwidth ___P ((AFMFont font, AFMNumber ptsize,
415                                    char ch, AFMNumber *w0x_return,
416                                    AFMNumber *w0y_return));
417
418 /*
419  * Encode character code <code> to print as character <name>.
420  * If <name> is NULL, encoding is removed.  <flags> can contain
421  * any combination of the AFM_ENCODE_* values.
422  */
423 AFMError afm_font_encode ___P ((AFMFont font, unsigned char code, char *name,
424                                 unsigned int flags));
425
426 /*
427  * Apply encoding <enc> to font <font>.  <flags> can contain any
428  * combination of the AFM_ENCODE_* values.
429  */
430 AFMError afm_font_encoding ___P ((AFMFont font, AFMEncoding enc,
431                                   unsigned int flags));
432
433 #endif /* not AFM_H */