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