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