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