⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parseafm.shar

📁 source code: Covert TXT to PDF
💻 SHAR
📖 第 1 页 / 共 5 页
字号:
XX/* Possible return codes from the parseFile procedure.X * X * ok means there were no problems parsing the file.X *X * parseError means that there was some kind of parsing error, but theX * parser went on. This could include problems like the count for any givenX * section does not add up to how many entries there actually were, orX * there was a key that was not recognized. The return record may containX * vaild data or it may not. X *X * earlyEOF means that an End of File was encountered before expected. ThisX * may mean that the AFM file had been truncated, or improperly formed.X * X * storageProblem means that there were problems allocating storage forX * the data structures that would have contained the AFM data.X */#define ok 0#define parseError -1#define earlyEOF -2#define storageProblem -3XXX/************************* TYPES *********************************//* Below are all of the data structure definitions. These structuresX * try to map as closely as possible to grouping and naming of data X * in the AFM Files.X */XX/* Bounding box definition. Used for the Font BBox as well as the X * Character BBox.X */typedef struct{ X   int llx;	/* lower left x-position  */X   int lly;	/* lower left y-position  */X   int urx;	/* upper right x-position */X   int ury;	/* upper right y-position */} BBox;XX/* Global Font information.X * The key that each field is associated with is in comments. For an X * explanation about each key and its value please refer to the AFMX * documentation (full title & version given above). X */typedef struct{  X   char *afmVersion;		/* key: StartFontMetrics */X   char *fontName;		/* key: FontName */X   char *fullName;		/* key: FullName */X   char *familyName;		/* key: FamilyName */X   char *weight;		/* key: Weight */X   float italicAngle;		/* key: ItalicAngle */X   BOOL isFixedPitch;		/* key: IsFixedPitch */X   BBox fontBBox;		/* key: FontBBox */X   int underlinePosition;  	/* key: UnderlinePosition */X   int underlineThickness; 	/* key: UnderlineThickness */X   char *version;		/* key: Version */X   char *notice;		/* key: Notice */X   char *encodingScheme;	/* key: EncodingScheme */X   int capHeight;		/* key: CapHeight */X   int xHeight;			/* key: XHeight */X   int ascender;		/* key: Ascender */X   int descender;		/* key: Descender */} GlobalFontInfo;XX/* Ligature definition is a linked list since any character can haveX * any number of ligatures.X */typedef struct _t_ligature{X    char *succ, *lig;X    struct _t_ligature *next;} Ligature;XX/* Character Metric Information. This structure is used only if ALL X * character metric information is requested. If only the characterX * widths is requested, then only an array of the character x-widthsX * is returned.X *X * The key that each field is associated with is in comments. For an X * explanation about each key and its value please refer to the X * Character Metrics section of the AFM documentation (full titleX * & version given above). X */typedef struct{X    int code, 		/* key: C */X        wx,		/* key: WX */X        wy;		/* together wx and wy are associated with key: W */X    char *name; 	/* key: N */X    BBox charBBox;	/* key: B */X    Ligature *ligs;	/* key: L (linked list; not a fixed number of Ls */} CharMetricInfo;XX/* Track kerning data structure.X * The fields of this record are the five values associated with every X * TrackKern entry.X *  X * For an explanation about each value please refer to the X * Track Kerning section of the AFM documentation (full titleX * & version given above). X */typedef struct {X    int degree;  X    float minPtSize, X          minKernAmt, X          maxPtSize, X          maxKernAmt;} TrackKernData;XX/* Pair Kerning data structure.X * The fields of this record are the four values associated with everyX * KP entry. For KPX entries, the yamt will be zero.X *X * For an explanation about each value please refer to the X * Pair Kerning section of the AFM documentation (full titleX * & version given above). X */typedef struct {X    char *name1;X    char *name2;X    int xamt,X        yamt;} PairKernData;XX/* PCC is a piece of a composite character. This is a sub structure of aX * compCharData described below.X * These fields will be filled in with the values from the key PCC.X * X * For an explanation about each key and its value please refer to the X * Composite Character section of the AFM documentation (full titleX * & version given above).  X */typedef struct{X    char *pccName;X    int deltax,X        deltay;} Pcc;XX/* Composite Character Information data structure. X * The fields ccName and numOfPieces are filled with the values associatedX * with the key CC. The field pieces points to an array (size = numOfPieces)X * of information about each of the parts of the composite character. ThatX * array is filled in with the values from the key PCC.X * X * For an explanation about each key and its value please refer to the X * Composite Character section of the AFM documentation (full titleX * & version given above).  X */typedef struct{X    char *ccName;X    int numOfPieces;X    Pcc *pieces;} CompCharData;XX/*  FontInfoX *  Record type containing pointers to all of the other dataX *  structures containing information about a font.X *  A a record of this type is filled with data by theX *  parseFile function.X */typedef struct{ X    GlobalFontInfo *gfi;	/* ptr to a GlobalFontInfo record */X    int *cwi;			/* ptr to 256 element array of just char widths */ X    int numOfChars;		/* number of entries in char metrics array */X    CharMetricInfo *cmi;	/* ptr to char metrics array */X    int numOfTracks;		/* number to entries in track kerning array */X    TrackKernData *tkd;		/* ptr to track kerning array */X    int numOfPairs;		/* number to entries in pair kerning array */X    PairKernData *pkd;		/* ptr to pair kerning array */X    int numOfComps;		/* number to entries in comp char array */X    CompCharData *ccd;		/* ptr to comp char array */} FontInfo;XXX/************************* PROCEDURES ****************************/X/*  Call this procedure to do the grunt work of parsing an AFM file.X *X *  "fp" should be a valid file pointer to an AFM file.X *X *  "fi" is a pointer to a pointer to a FontInfo record sturcture X *  (defined above). Storage for the FontInfo structure will beX *  allocated in parseFile and the structure will be filled inX *  with the requested data from the AFM File.X *X *  "flags" is a mask with bits set representing what data shouldX *  be saved. Defined above are valid flags that can be used to setX *  the mask, as well as a few commonly used masks.X *X *  The possible return codes from parseFile are defined above.X */Xextern int parseFile ( /* FILE *fp; FontInfo **fi; FLAGS flags; */ ); SHAR_EOF  $shar_touch -am 1018085596 'parseAFM.h' &&  chmod 0644 'parseAFM.h' ||  $echo 'restore of' 'parseAFM.h' 'failed'  shar_count="`wc -c < 'parseAFM.h'`"  test 11502 -eq "$shar_count" ||    $echo 'parseAFM.h:' 'original size' '11502,' 'current size' "$shar_count"fi# ============= parseAFMclient.c ==============if test -f 'parseAFMclient.c' && test X"$1" != X"-c"; then  $echo 'x -' SKIPPING 'parseAFMclient.c' '(file already exists)'else  $echo 'x -' extracting 'parseAFMclient.c' '(text)'  sed 's/^X//' << 'SHAR_EOF' > 'parseAFMclient.c' &&/*X * (C) 1988, 1989 by Adobe Systems Incorporated. All rights reserved.X *X * This file may be freely copied and redistributed as long as:X *   1) This entire notice continues to be included in the file, X *   2) If the file has been modified in any way, a notice of suchX *      modification is conspicuously indicated.X *X * PostScript, Display PostScript, and Adobe are registered trademarks ofX * Adobe Systems Incorporated.X * X * ************************************************************************X * THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO CHANGE WITHOUTX * NOTICE, AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY ADOBE SYSTEMSX * INCORPORATED. ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY OR X * LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO WARRANTY OF ANY X * KIND (EXPRESS, IMPLIED OR STATUTORY) WITH RESPECT TO THIS INFORMATION, X * AND EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY, X * FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.X * ************************************************************************X */X/*  parseAFMclient.cX *X *  This file is an example of how an application might use the providedX *  AFM Parser (parseAFM.c).X *X *  In a nutshell, the client of the parser (like this file) choosesX *  the AFM File that it wishes to have parsed, opens the file for X *  reading (and does any/all error handling associated with that task),X *  and passes the resulting file pointer to the procedure "parseFile"X *  (in parseAFM.c). In addition to the file pointer, the client alsoX *  needs to pass a pointer to a FontInfo record type (for which storageX *  will be allocated and data filled in), and a mask representing whichX *  sections of the AFM should be saved in the FontInfo record.X *X *  In the procedure "main", the mask is built from command line switches, X *  but your application, of course, can set that mask any way you prefer.X *  "main" then calls the "parseFile" procedure (of parseAFM.c) to do theX *  grunt work, and checks the error codes upon "parseFile"'s return.X *X *  The rest of this sample application is a collection of print routines X *  that show how to reference each of the sections of data and a X *  "freeStorage" routine (that many unix programmers may feel they X *  don't need but is included for portability to other systems that do X *  need to manage storage). The print procedures are there just toX *  give meaning to this application, and hopefully your applicationX *  will use the data collected from the AFM file in a more useful way.X *  X * History:X *	original: DSM  Thu Oct 20 17:39:59 PDT 1988X *  modified: DSM  Mon Jul  3 14:17:50 PDT 1989X *    - added 'storageProblem' check in mainX */X#include <stdio.h>#include "parseAFM.h"XX/*************************** GLOBALS ***************************/FontInfo *fi;FLAGS myflags = 0;X  X/*************************** printGlobals **********************/XprintGlobals(){X    printf("\nThis AFM is of Version %s\n", fi->gfi->afmVersion);X    printf("The font name is %s\n", fi->gfi->fontName);X    printf("The full name is %s\n", fi->gfi->fullName);X    printf("The family name is %s\n", fi->gfi->familyName);X    printf("The weight is %s\n", fi->gfi->weight);X    printf("Italic Angle is %3.1f\n", fi->gfi->italicAngle);X    if (fi->gfi->isFixedPitch)X        printf("This font IS fixed-pitch\n");X    elseX        printf("This font is NOT fixed-pitch\n");X    printf("Underline position is %d\n", fi->gfi->underlinePosition);X    printf("Underline thickness is %d\n", fi->gfi->underlineThickness);X    printf("Version is %s\n", fi->gfi->version);X    printf("FontBBox is [%d, %d, %d, %d]\n", X        fi->gfi->fontBBox.llx, fi->gfi->fontBBox.lly, X        fi->gfi->fontBBox.urx, fi->gfi->fontBBox.ury);X    printf("%s\n", fi->gfi->notice);X    printf("Encoding Scheme is %s\n", fi->gfi->encodingScheme);X    printf("CapHeight is %d\n", fi->gfi->capHeight);X    printf("XHeight is %d\n", fi->gfi->xHeight);X    printf("Descender is %d\n", fi->gfi->descender);X    printf("Ascender is %d\n\n", fi->gfi->ascender);X    } /* printGlobals */XX/*************************** printCharWidths *********************/printCharWidths(){X    int i = 0;X    printf("Here come some character widths ...\n");X    for (i = 0; i < 256; ++i)X        printf("  code: %3d   width: %4d\n", i, fi->cwi[i]);X    printf("\n");X } /* printCharWidths */XX/*************************** printAllCharMetrics *****************/printAllCharMetrics(){X    int i = 0;X    CharMetricInfo *temp = fi->cmi;X    Ligature *node = temp->ligs;X  X    printf("Here come some character metrics ...\n");X    for (i = 0; i < fi->numOfChars; ++i)X    {X        printf(X          "  code: %3d   x-width: %4d   y-width: %4d   name: %-12s   bbox: [%d, %d, %d, %d]\n",X            temp->code, temp->wx, temp->wy, temp->name, temp->charBBox.llx, X            temp->charBBox.lly, temp->charBBox.urx, temp->charBBox.ury);X        for (node = temp->ligs; node != NULL; node = node->next)X        {X            printf("      Ligatures:  successor: %s  ligature: %s\n", X                node->succ, node->lig);X        }X        temp++;X    } /* for */X    printf("\n");X} /* printAllCharMetrics */XX/******

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -