home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gle / gle / parseafm.h < prev    next >
C/C++ Source or Header  |  1992-11-29  |  10KB  |  314 lines

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