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