Added the $HOME variable to be used in AFMPATH
[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_ISO_8859_15,     /* ISO-8859-15 */
285   AFM_ENCODING_IBMPC,           /* IBM PC */
286   AFM_ENCODING_ASCII,           /* 7 bit ASCII */
287   AFM_ENCODING_MAC,             /* Mac */
288   AFM_ENCODING_VMS,             /* VMS multinational */
289   AFM_ENCODING_HP8,             /* HP Roman-8 */
290   AFM_ENCODING_KOI8             /* Adobe Standard Cyrillic Font KOI8 */
291 } AFMEncoding;
292
293 /* Special encoding types for individual characters. */
294 #define AFM_ENC_NONE            ((void *) 0)
295 #define AFM_ENC_NON_EXISTENT    ((void *) 1)
296
297
298 /* AFM information for a single PostScript font. */
299
300 struct afm_font_st
301 {
302   /* AFM Library's private data. */
303   struct afm_font_private_data_st *private;
304
305   AFMNumber version;            /* AFM format specification version number. */
306   unsigned int info_level;
307
308   /*
309    * Current font encoding.  Following values are valid:
310    *
311    *   AFM_ENC_NONE             character is not encoded
312    *   AFM_ENC_NON_EXISTENT     character is encoded, but font does not
313    *                            have the specified character
314    *   <pointer to character's metrics>
315    *                            character is encoded and it exists in font
316    */
317   AFMIndividualCharacterMetrics *encoding[256];
318
319   AFMGlobalFontInformation global_info;
320   AFMWritingDirectionMetrics writing_direction_metrics[2];
321
322   AFMInteger num_character_metrics;
323   AFMIndividualCharacterMetrics *character_metrics;
324
325   AFMInteger num_composites;
326   AFMComposite *composites;
327
328   AFMInteger num_kern_pairs;
329   AFMPairWiseKerning *kern_pairs;
330
331   AFMInteger num_track_kerns;
332   AFMTrackKern *track_kerns;
333 };
334
335 typedef struct afm_font_st *AFMFont;
336
337
338 \f
339 /*
340  * Prototypes for public functions.
341  */
342
343 /*
344  * Format error <error> to human readable format to buffer <buf>.
345  * Buffer must be long enough for error messages (256 bytes is good).
346  */
347 void afm_error_to_string ___P ((AFMError error, char *buf));
348
349 /*
350  * Open AFM library.  <path> specifies the search path for the AFM
351  * files.  A handle to the library is returned in <handle_return>.
352  */
353 AFMError afm_create ___P ((const char *path, unsigned int verbose_level,
354                            AFMHandle *handle_return));
355
356 /*
357  * Close AFM library handle <handle>.
358  */
359 AFMError afm_destroy ___P ((AFMHandle handle));
360
361 /*
362  * Set AFM library's verbose level to <level>.  Value 0 means "no output".
363  */
364 AFMError afm_set_verbose ___P ((AFMHandle handle, unsigned int level));
365
366 /*
367  * Return a prefix to the font <fontname>'s data.  Various font
368  * resource file names can be constructed from the returned prefix:
369  *   AFM        <prefix>.afm
370  *   PFA        <prefix>.pfa
371  *
372  * Returned prefix belongs to AFM library, user should not modify it.
373  */
374 AFMError afm_font_prefix ___P ((AFMHandle handle, const char *fontname,
375                                 const char **prefix_return));
376
377 /*
378  * Open font <name> and return font handle in <font_return>.
379  */
380 AFMError afm_open_font ___P ((AFMHandle handle, unsigned int info_level,
381                               const char *name, AFMFont *font_return));
382
383 /*
384  * Open AFM file <filename> and return font handle in <font_return>.
385  */
386 AFMError afm_open_file ___P ((AFMHandle handle, unsigned int info_level,
387                               const char *filename, AFMFont *font_return));
388
389 /*
390  * Open built-in default font (Courier).
391  */
392 AFMError afm_open_default_font ___P ((AFMHandle handle, AFMFont *font_return));
393
394 /*
395  * Close font <font>.
396  */
397 AFMError afm_close_font ___P ((AFMFont font));
398
399 /*
400  * Dump font information to file <fp>.
401  */
402 void afm_font_dump ___P ((FILE *fp, AFMFont font));
403
404 /*
405  * Return the width of the string <string, stringlen>.
406  */
407 AFMError afm_font_stringwidth ___P ((AFMFont font, AFMNumber ptsize,
408                                      char *string, unsigned int stringlen,
409                                      AFMNumber *w0x_return,
410                                      AFMNumber *w0y_return));
411
412 /*
413  * Return the width of the character <ch>.
414  */
415 AFMError afm_font_charwidth ___P ((AFMFont font, AFMNumber ptsize,
416                                    char ch, AFMNumber *w0x_return,
417                                    AFMNumber *w0y_return));
418
419 /*
420  * Encode character code <code> to print as character <name>.
421  * If <name> is NULL, encoding is removed.  <flags> can contain
422  * any combination of the AFM_ENCODE_* values.
423  */
424 AFMError afm_font_encode ___P ((AFMFont font, unsigned char code, char *name,
425                                 unsigned int flags));
426
427 /*
428  * Apply encoding <enc> to font <font>.  <flags> can contain any
429  * combination of the AFM_ENCODE_* values.
430  */
431 AFMError afm_font_encoding ___P ((AFMFont font, AFMEncoding enc,
432                                   unsigned int flags));
433
434 #endif /* not AFM_H */