merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / source / fontmanager / parseAFM.hxx
blob492dfad8582f34b2cef9919ae55890ada819fe24
1 /*
2 * (C) 1988, 1989 by Adobe Systems Incorporated. All rights reserved.
4 * This file may be freely copied and redistributed as long as:
5 * 1) This entire notice continues to be included in the file,
6 * 2) If the file has been modified in any way, a notice of such
7 * modification is conspicuously indicated.
9 * PostScript, Display PostScript, and Adobe are registered trademarks of
10 * Adobe Systems Incorporated.
12 * ************************************************************************
13 * THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO CHANGE WITHOUT
14 * NOTICE, AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY ADOBE SYSTEMS
15 * INCORPORATED. ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY OR
16 * LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO WARRANTY OF ANY
17 * KIND (EXPRESS, IMPLIED OR STATUTORY) WITH RESPECT TO THIS INFORMATION,
18 * AND EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
20 * ************************************************************************
24 * Changes made for OpenOffice.org
26 * 10/24/2000 pl - changed code to compile with c++-compilers
27 * - added namespace to avoid symbol clashes
28 * - replaced BOOL by bool
29 * - added function to free space allocated by parseFile
30 * 10/26/2000 pl - added additional keys
31 * - added ability to parse slightly broken files
32 * - added charwidth member to GlobalFontInfo
33 * 04/26/2001 pl - added OpenOffice header
34 * 10/19/2005 pl - changed parseFile to accept a file name instead of a stream
37 /*************************************************************************
39 * $RCSfile: parseAFM.hxx,v $
41 * $Revision: 1.2 $
43 * last change: $Author: hr $ $Date: 2005-12-28 17:08:50 $
45 ************************************************************************/
47 /* ParseAFM.h
49 * This header file is used in conjuction with the parseAFM.c file.
50 * Together these files provide the functionality to parse Adobe Font
51 * Metrics files and store the information in predefined data structures.
52 * It is intended to work with an application program that needs font metric
53 * information. The program can be used as is by making a procedure call to
54 * parse an AFM file and have the data stored, or an application developer
55 * may wish to customize the code.
57 * This header file defines the data structures used as well as the key
58 * strings that are currently recognized by this version of the AFM parser.
59 * This program is based on the document "Adobe Font Metrics Files,
60 * Specification Version 2.0".
62 * AFM files are separated into distinct sections of different data. Because
63 * of this, the parseAFM program can parse a specified file to only save
64 * certain sections of information based on the application's needs. A record
65 * containing the requested information will be returned to the application.
67 * AFM files are divided into five sections of data:
68 * 1) The Global Font Information
69 * 2) The Character Metrics Information
70 * 3) The Track Kerning Data
71 * 4) The Pair-Wise Kerning Data
72 * 5) The Composite Character Data
74 * Basically, the application can request any of these sections independent
75 * of what other sections are requested. In addition, in recognizing that
76 * many applications will want ONLY the x-width of characters and not all
77 * of the other character metrics information, there is a way to receive
78 * only the width information so as not to pay the storage cost for the
79 * unwanted data. An application should never request both the
80 * "quick and dirty" char metrics (widths only) and the Character Metrics
81 * Information since the Character Metrics Information will contain all
82 * of the character widths as well.
84 * There is a procedure in parseAFM.c, called parseFile, that can be
85 * called from any application wishing to get information from the AFM File.
86 * This procedure expects 3 parameters: a vaild file descriptor, a pointer
87 * to a (FontInfo *) variable (for which space will be allocated and then
88 * will be filled in with the data requested), and a mask specifying
89 * which data from the AFM File should be saved in the FontInfo structure.
91 * The flags that can be used to set the appropriate mask are defined below.
92 * In addition, several commonly used masks have already been defined.
94 * History:
95 * original: DSM Thu Oct 20 17:39:59 PDT 1988
96 * modified: DSM Mon Jul 3 14:17:50 PDT 1989
97 * - added 'storageProblem' return code
98 * - fixed typos
101 #include <stdio.h>
103 namespace psp {
105 /* your basic constants */
106 #define EOL '\n' /* end-of-line indicator */
107 #define MAX_NAME 4096 /* max length for identifiers */
108 #define FLAGS int
112 /* Flags that can be AND'ed together to specify exactly what
113 * information from the AFM file should be saved.
115 #define P_G 0x01 /* 0000 0001 */ /* Global Font Info */
116 #define P_W 0x02 /* 0000 0010 */ /* Character Widths ONLY */
117 #define P_M 0x06 /* 0000 0110 */ /* All Char Metric Info */
118 #define P_P 0x08 /* 0000 1000 */ /* Pair Kerning Info */
119 #define P_T 0x10 /* 0001 0000 */ /* Track Kerning Info */
120 #define P_C 0x20 /* 0010 0000 */ /* Composite Char Info */
123 /* Commonly used flags
125 #define P_GW (P_G | P_W)
126 #define P_GM (P_G | P_M)
127 #define P_GMP (P_G | P_M | P_P)
128 #define P_GMK (P_G | P_M | P_P | P_T)
129 #define P_ALL (P_G | P_M | P_P | P_T | P_C)
133 /* Possible return codes from the parseFile procedure.
135 * ok means there were no problems parsing the file.
137 * parseError means that there was some kind of parsing error, but the
138 * parser went on. This could include problems like the count for any given
139 * section does not add up to how many entries there actually were, or
140 * there was a key that was not recognized. The return record may contain
141 * vaild data or it may not.
143 * earlyEOF means that an End of File was encountered before expected. This
144 * may mean that the AFM file had been truncated, or improperly formed.
146 * storageProblem means that there were problems allocating storage for
147 * the data structures that would have contained the AFM data.
150 enum afmError { ok = 0, parseError = -1, earlyEOF = -2, storageProblem = -3 };
153 /************************* TYPES *********************************/
154 /* Below are all of the data structure definitions. These structures
155 * try to map as closely as possible to grouping and naming of data
156 * in the AFM Files.
160 /* Bounding box definition. Used for the Font BBox as well as the
161 * Character BBox.
163 typedef struct
165 int llx; /* lower left x-position */
166 int lly; /* lower left y-position */
167 int urx; /* upper right x-position */
168 int ury; /* upper right y-position */
169 } BBox;
172 /* Global Font information.
173 * The key that each field is associated with is in comments. For an
174 * explanation about each key and its value please refer to the AFM
175 * documentation (full title & version given above).
177 typedef struct
179 char *afmVersion; /* key: StartFontMetrics */
180 char *fontName; /* key: FontName */
181 char *fullName; /* key: FullName */
182 char *familyName; /* key: FamilyName */
183 char *weight; /* key: Weight */
184 float italicAngle; /* key: ItalicAngle */
185 bool isFixedPitch; /* key: IsFixedPitch */
186 BBox fontBBox; /* key: FontBBox */
187 int underlinePosition; /* key: UnderlinePosition */
188 int underlineThickness; /* key: UnderlineThickness */
189 char *version; /* key: Version */
190 char *notice; /* key: Notice */
191 char *encodingScheme; /* key: EncodingScheme */
192 int capHeight; /* key: CapHeight */
193 int xHeight; /* key: XHeight */
194 int ascender; /* key: Ascender */
195 int descender; /* key: Descender */
196 int charwidth; /* key: CharWidth */
197 } GlobalFontInfo;
200 /* Ligature definition is a linked list since any character can have
201 * any number of ligatures.
203 typedef struct _t_ligature
205 char *succ, *lig;
206 struct _t_ligature *next;
207 } Ligature;
210 /* Character Metric Information. This structure is used only if ALL
211 * character metric information is requested. If only the character
212 * widths is requested, then only an array of the character x-widths
213 * is returned.
215 * The key that each field is associated with is in comments. For an
216 * explanation about each key and its value please refer to the
217 * Character Metrics section of the AFM documentation (full title
218 * & version given above).
220 typedef struct
222 int code, /* key: C */
223 wx, /* key: WX */
224 w0x, /* key: W0X */
225 wy; /* together wx and wy are associated with key: W */
226 char *name; /* key: N */
227 BBox charBBox; /* key: B */
228 Ligature *ligs; /* key: L (linked list; not a fixed number of Ls */
229 } CharMetricInfo;
232 /* Track kerning data structure.
233 * The fields of this record are the five values associated with every
234 * TrackKern entry.
236 * For an explanation about each value please refer to the
237 * Track Kerning section of the AFM documentation (full title
238 * & version given above).
240 typedef struct
242 int degree;
243 float minPtSize,
244 minKernAmt,
245 maxPtSize,
246 maxKernAmt;
247 } TrackKernData;
250 /* Pair Kerning data structure.
251 * The fields of this record are the four values associated with every
252 * KP entry. For KPX entries, the yamt will be zero.
254 * For an explanation about each value please refer to the
255 * Pair Kerning section of the AFM documentation (full title
256 * & version given above).
258 typedef struct
260 char *name1;
261 char *name2;
262 int xamt,
263 yamt;
264 } PairKernData;
267 /* PCC is a piece of a composite character. This is a sub structure of a
268 * compCharData described below.
269 * These fields will be filled in with the values from the key PCC.
271 * For an explanation about each key and its value please refer to the
272 * Composite Character section of the AFM documentation (full title
273 * & version given above).
275 typedef struct
277 char *pccName;
278 int deltax,
279 deltay;
280 } Pcc;
283 /* Composite Character Information data structure.
284 * The fields ccName and numOfPieces are filled with the values associated
285 * with the key CC. The field pieces points to an array (size = numOfPieces)
286 * of information about each of the parts of the composite character. That
287 * array is filled in with the values from the key PCC.
289 * For an explanation about each key and its value please refer to the
290 * Composite Character section of the AFM documentation (full title
291 * & version given above).
293 typedef struct
295 char *ccName;
296 int numOfPieces;
297 Pcc *pieces;
298 } CompCharData;
301 /* FontInfo
302 * Record type containing pointers to all of the other data
303 * structures containing information about a font.
304 * A a record of this type is filled with data by the
305 * parseFile function.
307 typedef struct
309 GlobalFontInfo *gfi; /* ptr to a GlobalFontInfo record */
310 int *cwi; /* ptr to 256 element array of just char widths */
311 int numOfChars; /* number of entries in char metrics array */
312 CharMetricInfo *cmi; /* ptr to char metrics array */
313 int numOfTracks; /* number to entries in track kerning array */
314 TrackKernData *tkd; /* ptr to track kerning array */
315 int numOfPairs; /* number to entries in pair kerning array */
316 PairKernData *pkd; /* ptr to pair kerning array */
317 int numOfComps; /* number to entries in comp char array */
318 CompCharData *ccd; /* ptr to comp char array */
319 } FontInfo;
323 /************************* PROCEDURES ****************************/
325 /* Call this procedure to do the grunt work of parsing an AFM file.
327 * "fp" should be a valid file pointer to an AFM file.
329 * "fi" is a pointer to a pointer to a FontInfo record sturcture
330 * (defined above). Storage for the FontInfo structure will be
331 * allocated in parseFile and the structure will be filled in
332 * with the requested data from the AFM File.
334 * "flags" is a mask with bits set representing what data should
335 * be saved. Defined above are valid flags that can be used to set
336 * the mask, as well as a few commonly used masks.
338 * The possible return codes from parseFile are defined above.
341 int parseFile( const char* pFilename, FontInfo **fi, FLAGS flags );
342 void freeFontInfo(FontInfo *fi);
344 } // namespace