home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / FTREE0.3.LHA / ftree / src / RCS / parseAFM.h,v < prev    next >
Encoding:
Text File  |  1994-04-27  |  11.5 KB  |  341 lines

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