]> www.fi.muni.cz Git - evince.git/blob - backend/dvi/mdvi-lib/afmparse.h
Reorganize source tree.
[evince.git] / backend / dvi / mdvi-lib / afmparse.h
1 /* modified for MDVI -- some names changed to avoid conflicts with T1lib */
2 /*
3  * (C) 1988, 1989 by Adobe Systems Incorporated. All rights reserved.
4  *
5  * This file may be freely copied and redistributed as long as:
6  *   1) This entire notice continues to be included in the file, 
7  *   2) If the file has been modified in any way, a notice of such
8  *      modification is conspicuously indicated.
9  *
10  * PostScript, Display PostScript, and Adobe are registered trademarks of
11  * Adobe Systems Incorporated.
12  * 
13  * ************************************************************************
14  * THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO CHANGE WITHOUT
15  * NOTICE, AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY ADOBE SYSTEMS
16  * INCORPORATED. ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY OR 
17  * LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO WARRANTY OF ANY 
18  * KIND (EXPRESS, IMPLIED OR STATUTORY) WITH RESPECT TO THIS INFORMATION, 
19  * AND EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY, 
20  * FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
21  * ************************************************************************
22  */
23
24 /* ParseAFM.h
25  *
26  * This header file is used in conjuction with the parseAFM.c file.
27  * Together these files provide the functionality to parse Adobe Font
28  * Metrics files and store the information in predefined data structures.
29  * It is intended to work with an application program that needs font metric
30  * information. The program can be used as is by making a procedure call to 
31  * parse an AFM file and have the data stored, or an application developer
32  * may wish to customize the code. 
33  *
34  * This header file defines the data structures used as well as the key 
35  * strings that are currently recognized by this version of the AFM parser.
36  * This program is based on the document "Adobe Font Metrics Files, 
37  * Specification Version 2.0".
38  *
39  * AFM files are separated into distinct sections of different data. Because
40  * of this, the parseAFM program can parse a specified file to only save
41  * certain sections of information based on the application's needs. A record 
42  * containing the requested information will be returned to the application.
43  * 
44  * AFM files are divided into five sections of data:
45  *      1) The Global Font Information
46  *      2) The Character Metrics Information 
47  *      3) The Track Kerning Data
48  *      4) The Pair-Wise Kerning Data
49  *      5) The Composite Character Data
50  *
51  * Basically, the application can request any of these sections independent
52  * of what other sections are requested. In addition, in recognizing that
53  * many applications will want ONLY the x-width of characters and not all
54  * of the other character metrics information, there is a way to receive
55  * only the width information so as not to pay the storage cost for the 
56  * unwanted data. An application should never request both the 
57  * "quick and dirty" char metrics (widths only) and the Character Metrics 
58  * Information since the Character Metrics Information will contain all 
59  * of the character widths as well.
60  * 
61  * There is a procedure in parseAFM.c, called parseFile, that can be 
62  * called from any application wishing to get information from the AFM File.
63  * This procedure expects 3 parameters: a vaild file descriptor, a pointer
64  * to a (FontInfo *) variable (for which space will be allocated and then 
65  * will be filled in with the data requested), and a mask specifying
66  * which data from the AFM File should be saved in the FontInfo structure.
67  * 
68  * The flags that can be used to set the appropriate mask are defined below.
69  * In addition, several commonly used masks have already been defined. 
70  * 
71  * History:
72  *      original: DSM  Thu Oct 20 17:39:59 PDT 1988
73  *  modified: DSM  Mon Jul  3 14:17:50 PDT 1989
74  *    - added 'storageProblem' return code
75  *        - fixed typos
76  */
77 #ifndef _MDVI_PARSEAFM_H
78 #define _MDVI_PARSEAFM_H 1
79
80 #include "sysdeps.h"
81
82 #include <stdio.h>
83
84 /* your basic constants */
85 #define TRUE 1
86 #define FALSE 0
87 #define EOL '\n'                /* end-of-line indicator */
88 #define MAX_NAME 4096           /* max length for identifiers */
89 #define BOOL int
90 #define FLAGS int
91
92 /* Flags that can be AND'ed together to specify exactly what
93  * information from the AFM file should be saved. */
94 #define P_G     0x01    /* 0000 0001 */   /* Global Font Info      */
95 #define P_W     0x02    /* 0000 0010 */   /* Character Widths ONLY */
96 #define P_M     0x06    /* 0000 0110 */   /* All Char Metric Info  */
97 #define P_P     0x08    /* 0000 1000 */   /* Pair Kerning Info     */
98 #define P_T     0x10    /* 0001 0000 */   /* Track Kerning Info    */
99 #define P_C     0x20    /* 0010 0000 */   /* Composite Char Info   */
100
101 /* Commonly used flags */
102 #define P_GW    (P_G | P_W) 
103 #define P_GM    (P_G | P_M)
104 #define P_GMP   (P_G | P_M | P_P)
105 #define P_GMK   (P_G | P_M | P_P | P_T) 
106 #define P_ALL   (P_G | P_M | P_P | P_T | P_C)
107
108 /* Possible return codes from the parseFile procedure.
109  * 
110  * ok means there were no problems parsing the file.
111  *
112  * parseError means that there was some kind of parsing error, but the
113  * parser went on. This could include problems like the count for any given
114  * section does not add up to how many entries there actually were, or
115  * there was a key that was not recognized. The return record may contain
116  * vaild data or it may not. 
117  *
118  * earlyEOF means that an End of File was encountered before expected. This
119  * may mean that the AFM file had been truncated, or improperly formed.
120  * 
121  * storageProblem means that there were problems allocating storage for
122  * the data structures that would have contained the AFM data.
123  */
124 #define ok 0
125 #define parseError -1
126 #define earlyEOF -2
127 #define storageProblem -3
128
129 /************************* TYPES *********************************/
130 /* Below are all of the data structure definitions. These structures
131  * try to map as closely as possible to grouping and naming of data 
132  * in the AFM Files.
133  */
134
135 /* Bounding box definition. Used for the Font BBox as well as the 
136  * Character BBox.
137  */
138 typedef struct
139
140    int llx;     /* lower left x-position  */
141    int lly;     /* lower left y-position  */
142    int urx;     /* upper right x-position */
143    int ury;     /* upper right y-position */
144 } BBox;
145
146 /* Global Font information.
147  * The key that each field is associated with is in comments. For an 
148  * explanation about each key and its value please refer to the AFM
149  * documentation (full title & version given above). 
150  */
151 typedef struct
152 {  
153    char *afmVersion;            /* key: StartFontMetrics */
154    char *fontName;              /* key: FontName */
155    char *fullName;              /* key: FullName */
156    char *familyName;            /* key: FamilyName */
157    char *weight;                /* key: Weight */
158    float italicAngle;           /* key: ItalicAngle */
159    BOOL isFixedPitch;           /* key: IsFixedPitch */
160    BBox fontBBox;               /* key: FontBBox */
161    int underlinePosition;       /* key: UnderlinePosition */
162    int underlineThickness;      /* key: UnderlineThickness */
163    char *version;               /* key: Version */
164    char *notice;                /* key: Notice */
165    char *encodingScheme;        /* key: EncodingScheme */
166    int capHeight;               /* key: CapHeight */
167    int xHeight;                 /* key: XHeight */
168    int ascender;                /* key: Ascender */
169    int descender;               /* key: Descender */
170 } GlobalFontInfo;
171
172 /* Ligature definition is a linked list since any character can have
173  * any number of ligatures.
174  */
175 typedef struct _t_ligature
176 {
177     char *succ, *lig;
178     struct _t_ligature *next;
179 } Ligature;
180
181 /* Character Metric Information. This structure is used only if ALL 
182  * character metric information is requested. If only the character
183  * widths is requested, then only an array of the character x-widths
184  * is returned.
185  *
186  * The key that each field is associated with is in comments. For an 
187  * explanation about each key and its value please refer to the 
188  * Character Metrics section of the AFM documentation (full title
189  * & version given above). 
190  */
191 typedef struct
192 {
193     int code,           /* key: C */
194         wx,             /* key: WX */
195         wy;             /* together wx and wy are associated with key: W */
196     char *name;         /* key: N */
197     BBox charBBox;      /* key: B */
198     Ligature *ligs;     /* key: L (linked list; not a fixed number of Ls */
199 } CharMetricInfo;
200
201 /* Track kerning data structure.
202  * The fields of this record are the five values associated with every 
203  * TrackKern entry.
204  *  
205  * For an explanation about each value please refer to the 
206  * Track Kerning section of the AFM documentation (full title
207  * & version given above). 
208  */
209 typedef struct 
210 {
211     int degree;  
212     float minPtSize, 
213           minKernAmt, 
214           maxPtSize, 
215           maxKernAmt;
216 } TrackKernData;
217
218 /* Pair Kerning data structure.
219  * The fields of this record are the four values associated with every
220  * KP entry. For KPX entries, the yamt will be zero.
221  *
222  * For an explanation about each value please refer to the 
223  * Pair Kerning section of the AFM documentation (full title
224  * & version given above). 
225  */
226 typedef struct 
227 {
228     char *name1;
229     char *name2;
230     int xamt,
231         yamt;
232 } PairKernData;
233
234 /* PCC is a piece of a composite character. This is a sub structure of a
235  * compCharData described below.
236  * These fields will be filled in with the values from the key PCC.
237  * 
238  * For an explanation about each key and its value please refer to the 
239  * Composite Character section of the AFM documentation (full title
240  * & version given above).  
241  */
242 typedef struct
243 {
244     char *pccName;
245     int deltax,
246         deltay;
247 } Pcc;
248
249 /* Composite Character Information data structure. 
250  * The fields ccName and numOfPieces are filled with the values associated
251  * with the key CC. The field pieces points to an array (size = numOfPieces)
252  * of information about each of the parts of the composite character. That
253  * array is filled in with the values from the key PCC.
254  * 
255  * For an explanation about each key and its value please refer to the 
256  * Composite Character section of the AFM documentation (full title
257  * & version given above).  
258  */
259 typedef struct
260 {
261     char *ccName;
262     int numOfPieces;
263     Pcc *pieces;
264 } CompCharData;
265
266 /*  FontInfo
267  *  Record type containing pointers to all of the other data
268  *  structures containing information about a font.
269  *  A a record of this type is filled with data by the
270  *  parseFile function.
271  */
272 typedef struct
273
274     GlobalFontInfo *gfi;        /* ptr to a GlobalFontInfo record */
275     int *cwi;                   /* ptr to 256 element array of just char widths */ 
276     int numOfChars;             /* number of entries in char metrics array */
277     CharMetricInfo *cmi;        /* ptr to char metrics array */
278     int numOfTracks;            /* number to entries in track kerning array */
279     TrackKernData *tkd;         /* ptr to track kerning array */
280     int numOfPairs;             /* number to entries in pair kerning array */
281     PairKernData *pkd;          /* ptr to pair kerning array */
282     int numOfComps;             /* number to entries in comp char array */
283     CompCharData *ccd;          /* ptr to comp char array */
284 } FontInfo;
285
286 /************************* PROCEDURES ****************************/
287
288 /*  Call this procedure to do the grunt work of parsing an AFM file.
289  *
290  *  "fp" should be a valid file pointer to an AFM file.
291  *
292  *  "fi" is a pointer to a pointer to a FontInfo record sturcture 
293  *  (defined above). Storage for the FontInfo structure will be
294  *  allocated in parseFile and the structure will be filled in
295  *  with the requested data from the AFM File.
296  *
297  *  "flags" is a mask with bits set representing what data should
298  *  be saved. Defined above are valid flags that can be used to set
299  *  the mask, as well as a few commonly used masks.
300  *
301  *  The possible return codes from parseFile are defined above.
302  */
303
304 extern int afm_parse_file __PROTO((FILE *, FontInfo **, FLAGS)); 
305 extern void afm_free_fontinfo __PROTO((FontInfo *));
306
307 #endif /* _MDVI_PARSEAFM_H */