Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / generic / fontmanager / parseAFM.hxx
blob933e2fa7bfda16c020b49769fb5729d6deb9335f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * (C) 1988, 1989 by Adobe Systems Incorporated. All rights reserved.
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.
10 * PostScript, Display PostScript, and Adobe are registered trademarks of
11 * Adobe Systems Incorporated.
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 * ************************************************************************
25 * Changes made for OpenOffice.org
27 * 10/24/2000 pl - changed code to compile with c++-compilers
28 * - added namespace to avoid symbol clashes
29 * - replaced BOOL by bool
30 * - added function to free space allocated by parseFile
31 * 10/26/2000 pl - added additional keys
32 * - added ability to parse slightly broken files
33 * - added charwidth member to GlobalFontInfo
34 * 04/26/2001 pl - added OpenOffice header
35 * 10/19/2005 pl - changed parseFile to accept a file name instead of a stream
38 /* ParseAFM.h
40 * This header file is used in conjunction with the parseAFM.c file.
41 * Together these files provide the functionality to parse Adobe Font
42 * Metrics files and store the information in predefined data structures.
43 * It is intended to work with an application program that needs font metric
44 * information. The program can be used as is by making a procedure call to
45 * parse an AFM file and have the data stored, or an application developer
46 * may wish to customize the code.
48 * This header file defines the data structures used as well as the key
49 * strings that are currently recognized by this version of the AFM parser.
50 * This program is based on the document "Adobe Font Metrics Files,
51 * Specification Version 2.0".
53 * AFM files are separated into distinct sections of different data. Because
54 * of this, the parseAFM program can parse a specified file to only save
55 * certain sections of information based on the application's needs. A record
56 * containing the requested information will be returned to the application.
58 * AFM files are divided into five sections of data:
59 * 1) The Global Font Information
60 * 2) The Character Metrics Information
61 * 3) The Track Kerning Data
62 * 4) The Pair-Wise Kerning Data
63 * 5) The Composite Character Data
65 * Basically, the application can request any of these sections independent
66 * of what other sections are requested. In addition, in recognizing that
67 * many applications will want ONLY the x-width of characters and not all
68 * of the other character metrics information, there is a way to receive
69 * only the width information so as not to pay the storage cost for the
70 * unwanted data. An application should never request both the
71 * "quick and dirty" char metrics (widths only) and the Character Metrics
72 * Information since the Character Metrics Information will contain all
73 * of the character widths as well.
75 * There is a procedure in parseAFM.c, called parseFile, that can be
76 * called from any application wishing to get information from the AFM File.
77 * This procedure expects 3 parameters: a valid file descriptor, a pointer
78 * to a (FontInfo *) variable (for which space will be allocated and then
79 * will be filled in with the data requested), and a mask specifying
80 * which data from the AFM File should be saved in the FontInfo structure.
82 * The flags that can be used to set the appropriate mask are defined below.
83 * In addition, several commonly used masks have already been defined.
85 * History:
86 * original: DSM Thu Oct 20 17:39:59 PDT 1988
87 * modified: DSM Mon Jul 3 14:17:50 PDT 1989
88 * - added 'storageProblem' return code
89 * - fixed typos
92 #ifndef INCLUDED_VCL_GENERIC_FONTMANAGER_PARSEAFM_HXX
93 #define INCLUDED_VCL_GENERIC_FONTMANAGER_PARSEAFM_HXX
96 namespace psp {
98 /* your basic constants */
99 #define EOL '\n' /* end-of-line indicator */
100 #define MAX_NAME 4096 /* max length for identifiers */
101 #define FLAGS int
103 /* Flags that can be AND'ed together to specify exactly what
104 * information from the AFM file should be saved.
106 #define P_G 0x01 /* 0000 0001 */ /* Global Font Info */
107 #define P_W 0x02 /* 0000 0010 */ /* Character Widths ONLY */
108 #define P_M 0x06 /* 0000 0110 */ /* All Char Metric Info */
109 #define P_P 0x08 /* 0000 1000 */ /* Pair Kerning Info */
110 #define P_T 0x10 /* 0001 0000 */ /* Track Kerning Info */
111 #define P_C 0x20 /* 0010 0000 */ /* Composite Char Info */
113 /* Commonly used flags
115 #define P_GW (P_G | P_W)
116 #define P_GM (P_G | P_M)
117 #define P_GMP (P_G | P_M | P_P)
118 #define P_GMK (P_G | P_M | P_P | P_T)
119 #define P_ALL (P_G | P_M | P_P | P_T | P_C)
121 /* Possible return codes from the parseFile procedure.
123 * ok means there were no problems parsing the file.
125 * parseError means that there was some kind of parsing error, but the
126 * parser went on. This could include problems like the count for any given
127 * section does not add up to how many entries there actually were, or
128 * there was a key that was not recognized. The return record may contain
129 * valid data or it may not.
131 * earlyEOF means that an End of File was encountered before expected. This
132 * may mean that the AFM file had been truncated, or improperly formed.
134 * storageProblem means that there were problems allocating storage for
135 * the data structures that would have contained the AFM data.
138 enum afmError { ok = 0, parseError = -1, earlyEOF = -2, storageProblem = -3 };
140 /************************* TYPES *********************************/
141 /* Below are all of the data structure definitions. These structures
142 * try to map as closely as possible to grouping and naming of data
143 * in the AFM Files.
146 /* Bounding box definition. Used for the Font BBox as well as the
147 * Character BBox.
149 typedef struct
151 int llx; /* lower left x-position */
152 int lly; /* lower left y-position */
153 int urx; /* upper right x-position */
154 int ury; /* upper right y-position */
155 } BBox;
157 /* Global Font information.
158 * The key that each field is associated with is in comments. For an
159 * explanation about each key and its value please refer to the AFM
160 * documentation (full title & version given above).
162 typedef struct
164 char *afmVersion; /* key: StartFontMetrics */
165 char *fontName; /* key: FontName */
166 char *fullName; /* key: FullName */
167 char *familyName; /* key: FamilyName */
168 char *weight; /* key: Weight */
169 float italicAngle; /* key: ItalicAngle */
170 bool isFixedPitch; /* key: IsFixedPitch */
171 BBox fontBBox; /* key: FontBBox */
172 int underlinePosition; /* key: UnderlinePosition */
173 int underlineThickness; /* key: UnderlineThickness */
174 char *version; /* key: Version */
175 char *notice; /* key: Notice */
176 char *encodingScheme; /* key: EncodingScheme */
177 int capHeight; /* key: CapHeight */
178 int xHeight; /* key: XHeight */
179 int ascender; /* key: Ascender */
180 int descender; /* key: Descender */
181 int charwidth; /* key: CharWidth */
182 } GlobalFontInfo;
184 /* Ligature definition is a linked list since any character can have
185 * any number of ligatures.
187 typedef struct _t_ligature
189 char *succ, *lig;
190 struct _t_ligature *next;
191 } Ligature;
193 /* Character Metric Information. This structure is used only if ALL
194 * character metric information is requested. If only the character
195 * widths is requested, then only an array of the character x-widths
196 * is returned.
198 * The key that each field is associated with is in comments. For an
199 * explanation about each key and its value please refer to the
200 * Character Metrics section of the AFM documentation (full title
201 * & version given above).
203 typedef struct
205 int code, /* key: C */
206 wx, /* key: WX */
207 w0x, /* key: W0X */
208 wy; /* together wx and wy are associated with key: W */
209 char *name; /* key: N */
210 BBox charBBox; /* key: B */
211 Ligature *ligs; /* key: L (linked list; not a fixed number of Ls */
212 } CharMetricInfo;
214 /* Track kerning data structure.
215 * The fields of this record are the five values associated with every
216 * TrackKern entry.
218 * For an explanation about each value please refer to the
219 * Track Kerning section of the AFM documentation (full title
220 * & version given above).
222 typedef struct
224 int degree;
225 float minPtSize,
226 minKernAmt,
227 maxPtSize,
228 maxKernAmt;
229 } TrackKernData;
231 /* Pair Kerning data structure.
232 * The fields of this record are the four values associated with every
233 * KP entry. For KPX entries, the yamt will be zero.
235 * For an explanation about each value please refer to the
236 * Pair Kerning section of the AFM documentation (full title
237 * & version given above).
239 typedef struct
241 char *name1;
242 char *name2;
243 int xamt,
244 yamt;
245 } PairKernData;
247 /* PCC is a piece of a composite character. This is a sub structure of a
248 * compCharData described below.
249 * These fields will be filled in with the values from the key PCC.
251 * For an explanation about each key and its value please refer to the
252 * Composite Character section of the AFM documentation (full title
253 * & version given above).
255 typedef struct
257 char *pccName;
258 int deltax,
259 deltay;
260 } Pcc;
262 /* Composite Character Information data structure.
263 * The fields ccName and numOfPieces are filled with the values associated
264 * with the key CC. The field pieces points to an array (size = numOfPieces)
265 * of information about each of the parts of the composite character. That
266 * array is filled in with the values from the key PCC.
268 * For an explanation about each key and its value please refer to the
269 * Composite Character section of the AFM documentation (full title
270 * & version given above).
272 typedef struct
274 char *ccName;
275 int numOfPieces;
276 Pcc *pieces;
277 } CompCharData;
279 /* FontInfo
280 * Record type containing pointers to all of the other data
281 * structures containing information about a font.
282 * A record of this type is filled with data by the
283 * parseFile function.
285 typedef struct
287 GlobalFontInfo *gfi; /* ptr to a GlobalFontInfo record */
288 int *cwi; /* ptr to 256 element array of just char widths */
289 int numOfChars; /* number of entries in char metrics array */
290 CharMetricInfo *cmi; /* ptr to char metrics array */
291 int numOfTracks; /* number to entries in track kerning array */
292 TrackKernData *tkd; /* ptr to track kerning array */
293 int numOfPairs; /* number to entries in pair kerning array */
294 PairKernData *pkd; /* ptr to pair kerning array */
295 int numOfComps; /* number to entries in comp char array */
296 CompCharData *ccd; /* ptr to comp char array */
297 } FontInfo;
299 /************************* PROCEDURES ****************************/
301 /* Call this procedure to do the grunt work of parsing an AFM file.
303 * "fp" should be a valid file pointer to an AFM file.
305 * "fi" is a pointer to a pointer to a FontInfo record structure
306 * (defined above). Storage for the FontInfo structure will be
307 * allocated in parseFile and the structure will be filled in
308 * with the requested data from the AFM File.
310 * "flags" is a mask with bits set representing what data should
311 * be saved. Defined above are valid flags that can be used to set
312 * the mask, as well as a few commonly used masks.
314 * The possible return codes from parseFile are defined above.
317 int parseFile( const char* pFilename, FontInfo **fi, FLAGS flags );
318 void freeFontInfo(FontInfo *fi);
320 } // namespace
322 #endif // INCLUDED_VCL_GENERIC_FONTMANAGER_PARSEAFM_HXX
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */