📄 parseafm.shar
字号:
X if (pcount != fi->ccd[pos].numOfPieces)X error = parseError;X pcount = 0;X if (firstTime) firstTime = FALSE;X else pos++;X fi->ccd[pos].ccName = (char *) X malloc(strlen(keyword) + 1);X strcpy(fi->ccd[pos].ccName, keyword);X keyword = token(fp);X fi->ccd[pos].numOfPieces = atoi(keyword);X fi->ccd[pos].pieces = (Pcc *)X calloc(fi->ccd[pos].numOfPieces, sizeof(Pcc));X j = 0;X ccount++;X }X elseX {X error = parseError;X cont = FALSE;X }X break;X case COMPCHARPIECE:X if (pcount < fi->ccd[pos].numOfPieces)X {X keyword = token(fp);X fi->ccd[pos].pieces[j].pccName = (char *) X malloc(strlen(keyword) + 1);X strcpy(fi->ccd[pos].pieces[j].pccName, keyword);X keyword = token(fp);X fi->ccd[pos].pieces[j].deltax = atoi(keyword);X keyword = token(fp);X fi->ccd[pos].pieces[j++].deltay = atoi(keyword);X pcount++;X }X elseX error = parseError;X break;X case ENDCOMPOSITES:X cont = FALSE;X break;X case ENDFONTMETRICS:X cont = FALSE;X error = normalEOF;X break;X case NOPE:X default:X error = parseError;X break;X } /* switch */X } /* while */X X if (error == ok && ccount != fi->numOfComps)X error = parseError;X X return(error);X } /* parseCompCharData */ XXXX/*************************** 'PUBLIC' FUNCTION ********************/ XX/*************************** parseFile *****************************/X/* parseFile is the only 'public' procedure available. It is called X * from an application wishing to get information from an AFM file.X * The caller of this function is responsible for locating and openingX * an AFM file and handling all errors associated with that task.X *X * parseFile expects 3 parameters: a vaild file pointer, a pointerX * to a (FontInfo *) variable (for which storage will be allocated andX * the data requested filled in), and a mask specifying whichX * data from the AFM File should be saved in the FontInfo structure.X *X * The file will be parsed and the requested data will be stored in X * a record of type FontInfo (refer to ParseAFM.h).X *X * parseFile returns an error code as defined in parseAFM.h. X *X * The position of the read/write pointer associated with the file X * pointer upon return of this function is undefined.X */Xextern int parseFile (fp, fi, flags)X FILE *fp;X FontInfo **fi;X FLAGS flags;{X X int code = ok; /* return code from each of the parsing routines */X int error = ok; /* used as the return code from this function */X X register char *keyword; /* used to store a token */ X X X /* storage data for the global variable ident */ X ident = (char *) calloc(MAX_NAME, sizeof(char)); X if (ident == NULL) {error = storageProblem; return(error);} X X (*fi) = (FontInfo *) calloc(1, sizeof(FontInfo));X if ((*fi) == NULL) {error = storageProblem; return(error);} X X if (flags & P_G) X {X (*fi)->gfi = (GlobalFontInfo *) calloc(1, sizeof(GlobalFontInfo));X if ((*fi)->gfi == NULL) {error = storageProblem; return(error);} X }X X /* The AFM File begins with Global Font Information. This section */X /* will be parsed whether or not information should be saved. */ X code = parseGlobals(fp, (*fi)->gfi); X X if (code < 0) error = code;X X /* The Global Font Information is followed by the Character Metrics */X /* section. Which procedure is used to parse this section depends on */X /* how much information should be saved. If all of the metrics info */X /* is wanted, parseCharMetrics is called. If only the character widths */X /* is wanted, parseCharWidths is called. parseCharWidths will also */X /* be called in the case that no character data is to be saved, just */X /* to parse through the section. */X X if ((code != normalEOF) && (code != earlyEOF))X {X (*fi)->numOfChars = atoi(token(fp));X if (flags & (P_M ^ P_W))X {X (*fi)->cmi = (CharMetricInfo *) X calloc((*fi)->numOfChars, sizeof(CharMetricInfo));X if ((*fi)->cmi == NULL) {error = storageProblem; return(error);}X code = parseCharMetrics(fp, *fi); X }X elseX {X if (flags & P_W)X { X (*fi)->cwi = (int *) calloc(256, sizeof(int)); X if ((*fi)->cwi == NULL) X {X error = storageProblem; X return(error);X }X }X /* parse section regardless */X code = parseCharWidths(fp, (*fi)->cwi);X } /* else */X } /* if */X X if ((error != earlyEOF) && (code < 0)) error = code;X X /* The remaining sections of the AFM are optional. This code will */X /* look at the next keyword in the file to determine what section */X /* is next, and then allocate the appropriate amount of storage */X /* for the data (if the data is to be saved) and call the */X /* appropriate parsing routine to parse the section. */X X while ((code != normalEOF) && (code != earlyEOF))X {X keyword = token(fp);X if (keyword == NULL)X /* Have reached an early and unexpected EOF. */X /* Set flag and stop parsing */X {X code = earlyEOF;X break; /* get out of loop */X }X switch(recognize(keyword))X {X case STARTKERNDATA:X break;X case ENDKERNDATA:X break;X case STARTTRACKKERN:X keyword = token(fp);X if (flags & P_T)X {X (*fi)->numOfTracks = atoi(keyword);X (*fi)->tkd = (TrackKernData *) X calloc((*fi)->numOfTracks, sizeof(TrackKernData));X if ((*fi)->tkd == NULL) X {X error = storageProblem; X return(error);X }X } /* if */X code = parseTrackKernData(fp, *fi);X break;X case STARTKERNPAIRS:X keyword = token(fp);X if (flags & P_P)X {X (*fi)->numOfPairs = atoi(keyword);X (*fi)->pkd = (PairKernData *) X calloc((*fi)->numOfPairs, sizeof(PairKernData));X if ((*fi)->pkd == NULL) X {X error = storageProblem; X return(error);X }X } /* if */X code = parsePairKernData(fp, *fi);X break;X case STARTCOMPOSITES:X keyword = token(fp);X if (flags & P_C)X { X (*fi)->numOfComps = atoi(keyword);X (*fi)->ccd = (CompCharData *) X calloc((*fi)->numOfComps, sizeof(CompCharData));X if ((*fi)->ccd == NULL) X {X error = storageProblem; X return(error);X }X } /* if */X code = parseCompCharData(fp, *fi); X break; X case ENDFONTMETRICS:X code = normalEOF;X break;X case NOPE:X default:X code = parseError;X break;X } /* switch */X X if ((error != earlyEOF) && (code < 0)) error = code;X X } /* while */X X if ((error != earlyEOF) && (code < 0)) error = code;X X if (ident != NULL) { free(ident); ident = NULL; }X X return(error);X } /* parseFile */SHAR_EOF $shar_touch -am 1018085596 'parseAFM.c' && chmod 0644 'parseAFM.c' || $echo 'restore of' 'parseAFM.c' 'failed' shar_count="`wc -c < 'parseAFM.c'`" test 43280 -eq "$shar_count" || $echo 'parseAFM.c:' 'original size' '43280,' 'current size' "$shar_count"fi# ============= parseAFM.h ==============if test -f 'parseAFM.h' && test X"$1" != X"-c"; then $echo 'x -' SKIPPING 'parseAFM.h' '(file already exists)'else $echo 'x -' extracting 'parseAFM.h' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'parseAFM.h' &&/*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/* ParseAFM.hX *X * This header file is used in conjuction with the parseAFM.c file.X * Together these files provide the functionality to parse Adobe FontX * Metrics files and store the information in predefined data structures.X * It is intended to work with an application program that needs font metricX * information. The program can be used as is by making a procedure call to X * parse an AFM file and have the data stored, or an application developerX * may wish to customize the code. X *X * This header file defines the data structures used as well as the key X * strings that are currently recognized by this version of the AFM parser.X * This program is based on the document "Adobe Font Metrics Files, X * Specification Version 2.0".X *X * AFM files are separated into distinct sections of different data. BecauseX * of this, the parseAFM program can parse a specified file to only saveX * certain sections of information based on the application's needs. A record X * containing the requested information will be returned to the application.X * X * AFM files are divided into five sections of data:X * 1) The Global Font InformationX * 2) The Character Metrics Information X * 3) The Track Kerning DataX * 4) The Pair-Wise Kerning DataX * 5) The Composite Character DataX *X * Basically, the application can request any of these sections independentX * of what other sections are requested. In addition, in recognizing thatX * many applications will want ONLY the x-width of characters and not allX * of the other character metrics information, there is a way to receiveX * only the width information so as not to pay the storage cost for the X * unwanted data. An application should never request both the X * "quick and dirty" char metrics (widths only) and the Character Metrics X * Information since the Character Metrics Information will contain all X * of the character widths as well.X * X * There is a procedure in parseAFM.c, called parseFile, that can be X * called from any application wishing to get information from the AFM File.X * This procedure expects 3 parameters: a vaild file descriptor, a pointerX * to a (FontInfo *) variable (for which space will be allocated and then X * will be filled in with the data requested), and a mask specifyingX * which data from the AFM File should be saved in the FontInfo structure.X * X * The flags that can be used to set the appropriate mask are defined below.X * In addition, several commonly used masks have already been defined. 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' return codeX * - fixed typosX */X#include <stdio.h>XXX/* your basic constants */#define TRUE 1#define FALSE 0#define EOL '\n' /* end-of-line indicator */#define MAX_NAME 4096 /* max length for identifiers */#define BOOL int#define FLAGS intXXX/* Flags that can be AND'ed together to specify exactly whatX * information from the AFM file should be saved.X */#define P_G 0x01 /* 0000 0001 */ /* Global Font Info */#define P_W 0x02 /* 0000 0010 */ /* Character Widths ONLY */#define P_M 0x06 /* 0000 0110 */ /* All Char Metric Info */#define P_P 0x08 /* 0000 1000 */ /* Pair Kerning Info */#define P_T 0x10 /* 0001 0000 */ /* Track Kerning Info */#define P_C 0x20 /* 0010 0000 */ /* Composite Char Info */XX/* Commonly used flagsX */#define P_GW (P_G | P_W) #define P_GM (P_G | P_M)#define P_GMP (P_G | P_M | P_P)#define P_GMK (P_G | P_M | P_P | P_T) #define P_ALL (P_G | P_M | P_P | P_T | P_C)X
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -