Back to index

tetex-bin  3.0
parseAFM.h
Go to the documentation of this file.
00001 /*--------------------------------------------------------------------------
00002   ----- File:        parseAFM.h
00003   ----- Author:      Adobe Systems Inc., modifications by
00004                      Rainer Menzner (Rainer.Menzner@web.de)
00005   ----- Date:        2001-04-01
00006   ----- Description: This file is part of the t1-library. It is the original
00007                      parseAFM.h modified at a few points.
00008   ----- Copyright:   t1lib is copyrighted (c) Rainer Menzner, 1996-2001. 
00009                      As of version 0.5, t1lib is distributed under the
00010                    GNU General Public Library Lincense. The
00011                    conditions can be found in the files LICENSE and
00012                    LGPL, which should reside in the toplevel
00013                    directory of the distribution.  Please note that 
00014                    there are parts of t1lib that are subject to
00015                    other licenses:
00016                    The parseAFM-package is copyrighted by Adobe Systems
00017                    Inc.
00018                    The type1 rasterizer is copyrighted by IBM and the
00019                    X11-consortium.
00020   ----- Warranties:  Of course, there's NO WARRANTY OF ANY KIND :-)
00021   ----- Credits:     I want to thank IBM and the X11-consortium for making
00022                      their rasterizer freely available.
00023                    Also thanks to Piet Tutelaers for his ps2pk, from
00024                    which I took the rasterizer sources in a format
00025                    independent from X11.
00026                      Thanks to all people who make free software living!
00027 --------------------------------------------------------------------------*/
00028 
00029 /*
00030  * (C) 1988, 1989 by Adobe Systems Incorporated. All rights reserved.
00031  *
00032  * This file may be freely copied and redistributed as long as:
00033  *   1) This entire notice continues to be included in the file, 
00034  *   2) If the file has been modified in any way, a notice of such
00035  *      modification is conspicuously indicated.
00036  *
00037  * PostScript, Display PostScript, and Adobe are registered trademarks of
00038  * Adobe Systems Incorporated.
00039  * 
00040  * ************************************************************************
00041  * THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO CHANGE WITHOUT
00042  * NOTICE, AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY ADOBE SYSTEMS
00043  * INCORPORATED. ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY OR 
00044  * LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO WARRANTY OF ANY 
00045  * KIND (EXPRESS, IMPLIED OR STATUTORY) WITH RESPECT TO THIS INFORMATION, 
00046  * AND EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY, 
00047  * FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
00048  * ************************************************************************
00049  */
00050 
00051 /* ParseAFM.h
00052  *
00053  * This header file is used in conjuction with the parseAFM.c file.
00054  * Together these files provide the functionality to parse Adobe Font
00055  * Metrics files and store the information in predefined data structures.
00056  * It is intended to work with an application program that needs font metric
00057  * information. The program can be used as is by making a procedure call to 
00058  * parse an AFM file and have the data stored, or an application developer
00059  * may wish to customize the code. 
00060  *
00061  * This header file defines the data structures used as well as the key 
00062  * strings that are currently recognized by this version of the AFM parser.
00063  * This program is based on the document "Adobe Font Metrics Files, 
00064  * Specification Version 2.0".
00065  *
00066  * AFM files are separated into distinct sections of different data. Because
00067  * of this, the parseAFM program can parse a specified file to only save
00068  * certain sections of information based on the application's needs. A record 
00069  * containing the requested information will be returned to the application.
00070  * 
00071  * AFM files are divided into five sections of data:
00072  *     1) The Global Font Information
00073  *     2) The Character Metrics Information 
00074  *     3) The Track Kerning Data
00075  *     4) The Pair-Wise Kerning Data
00076  *     5) The Composite Character Data
00077  *
00078  * Basically, the application can request any of these sections independent
00079  * of what other sections are requested. In addition, in recognizing that
00080  * many applications will want ONLY the x-width of characters and not all
00081  * of the other character metrics information, there is a way to receive
00082  * only the width information so as not to pay the storage cost for the 
00083  * unwanted data. An application should never request both the 
00084  * "quick and dirty" char metrics (widths only) and the Character Metrics 
00085  * Information since the Character Metrics Information will contain all 
00086  * of the character widths as well.
00087  * 
00088  * There is a procedure in parseAFM.c, called parseFile, that can be 
00089  * called from any application wishing to get information from the AFM File.
00090  * This procedure expects 3 parameters: a vaild file descriptor, a pointer
00091  * to a (FontInfo *) variable (for which space will be allocated and then 
00092  * will be filled in with the data requested), and a mask specifying
00093  * which data from the AFM File should be saved in the FontInfo structure.
00094  * 
00095  * The flags that can be used to set the appropriate mask are defined below.
00096  * In addition, several commonly used masks have already been defined. 
00097  * 
00098  * History:
00099  *     original: DSM  Thu Oct 20 17:39:59 PDT 1988
00100  *  modified: DSM  Mon Jul  3 14:17:50 PDT 1989
00101  *    - added 'storageProblem' return code
00102  *       - fixed typos
00103  */
00104 
00105 #include <stdio.h>
00106 
00107 
00108 
00109 /* your basic constants */
00110 #define T1LIB_TRUE 1
00111 #define T1LIB_FALSE 0
00112 #define EOL '\n'                /* end-of-line indicator */
00113 #define MAX_NAME 4096           /* max length for identifiers */
00114 #define BOOL int
00115 #define FLAGS int
00116 
00117 
00118 
00119 /* Flags that can be AND'ed together to specify exactly what
00120  * information from the AFM file should be saved.
00121  */
00122 #define P_G   0x01   /* 0000 0001 */   /* Global Font Info      */
00123 #define P_W   0x02   /* 0000 0010 */   /* Character Widths ONLY */
00124 #define P_M   0x06   /* 0000 0110 */   /* All Char Metric Info  */
00125 #define P_P   0x08   /* 0000 1000 */   /* Pair Kerning Info     */
00126 #define P_T   0x10   /* 0001 0000 */   /* Track Kerning Info    */
00127 #define P_C   0x20   /* 0010 0000 */   /* Composite Char Info   */
00128 
00129 
00130 /* Commonly used flags
00131  */
00132 #define P_GW  (P_G | P_W) 
00133 #define P_GM  (P_G | P_M)
00134 #define P_GMP (P_G | P_M | P_P)
00135 #define P_GMK (P_G | P_M | P_P | P_T) 
00136 #define P_ALL (P_G | P_M | P_P | P_T | P_C)
00137 
00138 
00139 
00140 /* Possible return codes from the parseFile procedure.
00141  * 
00142  * ok means there were no problems parsing the file.
00143  *
00144  * parseError means that there was some kind of parsing error, but the
00145  * parser went on. This could include problems like the count for any given
00146  * section does not add up to how many entries there actually were, or
00147  * there was a key that was not recognized. The return record may contain
00148  * vaild data or it may not. 
00149  *
00150  * earlyEOF means that an End of File was encountered before expected. This
00151  * may mean that the AFM file had been truncated, or improperly formed.
00152  * 
00153  * storageProblem means that there were problems allocating storage for
00154  * the data structures that would have contained the AFM data.
00155  */
00156 #define ok 0
00157 #define parseError -1
00158 #define earlyEOF -2
00159 #define storageProblem -3
00160 
00161 
00162 
00163 /************************* TYPES *********************************/
00164 /* Below are all of the data structure definitions. These structures
00165  * try to map as closely as possible to grouping and naming of data 
00166  * in the AFM Files.
00167  */
00168 
00169 
00170 /* Bounding box definition. Used for the Font BBox as well as the 
00171  * Character BBox.
00172  */
00173 typedef struct
00174 { 
00175    int llx;   /* lower left x-position  */
00176    int lly;   /* lower left y-position  */
00177    int urx;   /* upper right x-position */
00178    int ury;   /* upper right y-position */
00179 } BBox;
00180 
00181 
00182 /* Global Font information.
00183  * The key that each field is associated with is in comments. For an 
00184  * explanation about each key and its value please refer to the AFM
00185  * documentation (full title & version given above). 
00186  */
00187 typedef struct
00188 {  
00189    char *afmVersion;        /* key: StartFontMetrics */
00190    char *fontName;          /* key: FontName */
00191    char *fullName;          /* key: FullName */
00192    char *familyName;        /* key: FamilyName */
00193    char *weight;            /* key: Weight */
00194    float italicAngle;              /* key: ItalicAngle */
00195    BOOL isFixedPitch;              /* key: IsFixedPitch */
00196    BBox fontBBox;           /* key: FontBBox */
00197    int underlinePosition;   /* key: UnderlinePosition */
00198    int underlineThickness;  /* key: UnderlineThickness */
00199    char *version;           /* key: Version */
00200    char *notice;            /* key: Notice */
00201    char *encodingScheme;    /* key: EncodingScheme */
00202    int capHeight;           /* key: CapHeight */
00203    int xHeight;                    /* key: XHeight */
00204    int ascender;            /* key: Ascender */
00205    int descender;           /* key: Descender */
00206 } GlobalFontInfo;
00207 
00208 
00209 /* Ligature definition is a linked list since any character can have
00210  * any number of ligatures.
00211  */
00212 typedef struct _t_ligature
00213 {
00214     char *succ, *lig;
00215     struct _t_ligature *next;
00216 } Ligature;
00217 
00218 
00219 /* Character Metric Information. This structure is used only if ALL 
00220  * character metric information is requested. If only the character
00221  * widths is requested, then only an array of the character x-widths
00222  * is returned.
00223  *
00224  * The key that each field is associated with is in comments. For an 
00225  * explanation about each key and its value please refer to the 
00226  * Character Metrics section of the AFM documentation (full title
00227  * & version given above). 
00228  */
00229 typedef struct
00230 {
00231     int code,               /* key: C */
00232         wx,          /* key: WX */
00233         wy;          /* together wx and wy are associated with key: W */
00234     char *name;      /* key: N */
00235     BBox charBBox;   /* key: B */
00236     Ligature *ligs;  /* key: L (linked list; not a fixed number of Ls */
00237 } CharMetricInfo;
00238 
00239 
00240 /* Track kerning data structure.
00241  * The fields of this record are the five values associated with every 
00242  * TrackKern entry.
00243  *  
00244  * For an explanation about each value please refer to the 
00245  * Track Kerning section of the AFM documentation (full title
00246  * & version given above). 
00247  */
00248 typedef struct 
00249 {
00250     int degree;  
00251     float minPtSize, 
00252           minKernAmt, 
00253           maxPtSize, 
00254           maxKernAmt;
00255 } TrackKernData;
00256 
00257 
00258 /* Pair Kerning data structure.
00259  * The fields of this record are the four values associated with every
00260  * KP entry. For KPX entries, the yamt will be zero.
00261  *
00262  * For an explanation about each value please refer to the 
00263  * Pair Kerning section of the AFM documentation (full title
00264  * & version given above). 
00265  */
00266 typedef struct 
00267 {
00268     char *name1;
00269     char *name2;
00270     int xamt,
00271         yamt;
00272 } PairKernData;
00273 
00274 
00275 /* PCC is a piece of a composite character. This is a sub structure of a
00276  * compCharData described below.
00277  * These fields will be filled in with the values from the key PCC.
00278  * 
00279  * For an explanation about each key and its value please refer to the 
00280  * Composite Character section of the AFM documentation (full title
00281  * & version given above).  
00282  */
00283 typedef struct
00284 {
00285     char *pccName;
00286     int deltax,
00287         deltay;
00288 } Pcc;
00289 
00290 
00291 /* Composite Character Information data structure. 
00292  * The fields ccName and numOfPieces are filled with the values associated
00293  * with the key CC. The field pieces points to an array (size = numOfPieces)
00294  * of information about each of the parts of the composite character. That
00295  * array is filled in with the values from the key PCC.
00296  * 
00297  * For an explanation about each key and its value please refer to the 
00298  * Composite Character section of the AFM documentation (full title
00299  * & version given above).  
00300  
00301  structure extended for use with t1lib. The fields "width" and bbox store
00302  the composite characters escapement and its bounding box (2001-05-027, RMz)
00303  */
00304 typedef struct
00305 {
00306   int  wx;   /* these two will be filled by T1_LoadFont() */
00307   BBox charBBox;
00308   char *ccName;
00309   int numOfPieces;
00310   Pcc *pieces;
00311 } CompCharData;
00312 
00313 
00314 /*  FontInfo
00315  *  Record type containing pointers to all of the other data
00316  *  structures containing information about a font.
00317  *  A a record of this type is filled with data by the
00318  *  parseFile function.
00319  */
00320 typedef struct
00321 { 
00322   GlobalFontInfo *gfi;      /* ptr to a GlobalFontInfo record */
00323   int *cwi;                 /* ptr to 256 element array of just char widths */
00324   int numOfChars;           /* number of entries in char metrics array */
00325   CharMetricInfo *cmi;              /* ptr to char metrics array */
00326   int numOfTracks;          /* number to entries in track kerning array */
00327   TrackKernData *tkd;              /* ptr to track kerning array */
00328   int numOfPairs;           /* number to entries in pair kerning array */
00329   PairKernData *pkd;        /* ptr to pair kerning array */
00330   int numOfComps;           /* number to entries in comp char array */
00331   CompCharData *ccd;        /* ptr to comp char array */
00332 } FontInfo;
00333 
00334 
00335 
00336 /************************* PROCEDURES ****************************/
00337 
00338 /*  Call this procedure to do the grunt work of parsing an AFM file.
00339  *
00340  *  "fp" should be a valid file pointer to an AFM file.
00341  *
00342  *  "fi" is a pointer to a pointer to a FontInfo record sturcture 
00343  *  (defined above). Storage for the FontInfo structure will be
00344  *  allocated in parseFile and the structure will be filled in
00345  *  with the requested data from the AFM File.
00346  *
00347  *  "flags" is a mask with bits set representing what data should
00348  *  be saved. Defined above are valid flags that can be used to set
00349  *  the mask, as well as a few commonly used masks.
00350  *
00351  *  The possible return codes from parseFile are defined above.
00352  */
00353 
00354 extern int T1lib_parseFile ( FILE *fp, FontInfo **fi, FLAGS flags );