📄 parseafm.shar
字号:
X }X if (!save) X /* get tokens until the end of the Global Font info section */X /* without saving any of the data */X switch (recognize(keyword)) X { X case STARTCHARMETRICS:X cont = FALSE;X break;X case ENDFONTMETRICS: X cont = FALSE;X error = normalEOF;X break;X default:X break;X } /* switch */X elseX /* otherwise parse entire global font info section, */X /* saving the data */X switch(recognize(keyword))X {X case STARTFONTMETRICS:X keyword = token(fp);X gfi->afmVersion = (char *) malloc(strlen(keyword) + 1);X strcpy(gfi->afmVersion, keyword);X break;X case COMMENT:X keyword = linetoken(fp);X break;X case FONTNAME:X keyword = token(fp);X gfi->fontName = (char *) malloc(strlen(keyword) + 1);X strcpy(gfi->fontName, keyword);X break;X case ENCODINGSCHEME:X keyword = token(fp);X gfi->encodingScheme = (char *) X malloc(strlen(keyword) + 1);X strcpy(gfi->encodingScheme, keyword);X break; X case FULLNAME:X keyword = linetoken(fp);X gfi->fullName = (char *) malloc(strlen(keyword) + 1);X strcpy(gfi->fullName, keyword);X break; X case FAMILYNAME: X keyword = linetoken(fp);X gfi->familyName = (char *) malloc(strlen(keyword) + 1);X strcpy(gfi->familyName, keyword);X break; X case WEIGHT:X keyword = token(fp);X gfi->weight = (char *) malloc(strlen(keyword) + 1);X strcpy(gfi->weight, keyword);X break;X case ITALICANGLE:X keyword = token(fp);X gfi->italicAngle = atof(keyword);X if (errno == ERANGE) error = parseError;X break;X case ISFIXEDPITCH:X keyword = token(fp);X if (MATCH(keyword, False))X gfi->isFixedPitch = 0;X else X gfi->isFixedPitch = 1;X break; X case UNDERLINEPOSITION:X keyword = token(fp);X gfi->underlinePosition = atoi(keyword);X break; X case UNDERLINETHICKNESS:X keyword = token(fp);X gfi->underlineThickness = atoi(keyword);X break;X case VERSION:X keyword = token(fp);X gfi->version = (char *) malloc(strlen(keyword) + 1);X strcpy(gfi->version, keyword);X break; X case NOTICE:X keyword = linetoken(fp);X gfi->notice = (char *) malloc(strlen(keyword) + 1);X strcpy(gfi->notice, keyword);X break; X case FONTBBOX:X keyword = token(fp);X gfi->fontBBox.llx = atoi(keyword);X keyword = token(fp);X gfi->fontBBox.lly = atoi(keyword);X keyword = token(fp);X gfi->fontBBox.urx = atoi(keyword);X keyword = token(fp);X gfi->fontBBox.ury = atoi(keyword);X break;X case CAPHEIGHT:X keyword = token(fp);X gfi->capHeight = atoi(keyword);X break;X case XHEIGHT:X keyword = token(fp);X gfi->xHeight = atoi(keyword);X break;X case DESCENDER:X keyword = token(fp);X gfi->descender = atoi(keyword);X break;X case ASCENDER:X keyword = token(fp);X gfi->ascender = atoi(keyword);X break;X case STARTCHARMETRICS: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 return(error);X } /* parseGlobals */ XXX/************************* initializeArray ************************/X/* Unmapped character codes are (at Adobe Systems) assigned theX * width of the space character (if one exists) else they get theX * value of 250 ems. This function initializes all entries in theX * char widths array to have this value. Then any mapped character X * codes will be replaced with the width of the appropriate character X * when parsing the character metric section.X X * This function parses the Character Metrics Section lookingX * for a space character (by comparing character names). If found,X * the width of the space character will be used to initialize theX * values in the array of character widths. X *X * Before returning, the position of the read/write pointer of theX * file is reset to be where it was upon entering this function.X */X static int initializeArray(fp, cwi)X FILE *fp;X register int *cwi;{ X BOOL cont = TRUE, found = FALSE;X long opos = ftell(fp);X int code = 0, width = 0, i = 0, error = 0;X register char *keyword;X X while (cont)X {X keyword = token(fp);X if (keyword == NULL)X {X error = earlyEOF;X break; /* get out of loop */X }X switch(recognize(keyword))X {X case COMMENT:X keyword = linetoken(fp);X break;X case CODE:X code = atoi(token(fp));X break;X case XWIDTH:X width = atoi(token(fp));X break;X case CHARNAME: X keyword = token(fp);X if (MATCH(keyword, Space))X { X cont = FALSE;X found = TRUE;X } X break; X case ENDCHARMETRICS: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 (!found)X width = 250;X X for (i = 0; i < 256; ++i)X cwi[i] = width;X X fseek(fp, opos, 0);X X return(error);X } /* initializeArray */ XX/************************* parseCharWidths **************************/X/* This function is called by "parseFile". It will parse the AFM FileX * up to the "EndCharMetrics" keyword. It will save the character X * width info (as opposed to all of the character metric information)X * if requested by the caller of parseFile. Otherwise, it will justX * parse through the section without saving any information.X *X * If data is to be saved, parseCharWidths is passed in a pointer X * to an array of widths that has already been initialized by theX * standard value for unmapped character codes. This function parsesX * the Character Metrics section only storing the width informationX * for the encoded characters into the array using the character codeX * as the index into that array.X *X * This function returns an error code specifying whether there was X * a premature EOF or a parsing error. This return value is used by X * parseFile to determine if there is more file to parse.X */X static parseCharWidths(fp, cwi)X FILE *fp;X register int *cwi;{ X BOOL cont = TRUE, save = (cwi != NULL);X int pos = 0, error = ok;X register char *keyword;X X while (cont)X {X keyword = token(fp);X /* Have reached an early and unexpected EOF. */X /* Set flag and stop parsing */X if (keyword == NULL)X {X error = earlyEOF;X break; /* get out of loop */X }X if (!save) X /* get tokens until the end of the Char Metrics section without */X /* saving any of the data*/X switch (recognize(keyword)) X { X case ENDCHARMETRICS:X cont = FALSE;X break; X case ENDFONTMETRICS:X cont = FALSE;X error = normalEOF;X break;X default: X break;X } /* switch */X elseX /* otherwise parse entire char metrics section, saving */X /* only the char x-width info */X switch(recognize(keyword))X {X case COMMENT:X keyword = linetoken(fp);X break;X case CODE:X keyword = token(fp);X pos = atoi(keyword);X break;X case XYWIDTH:X /* PROBLEM: Should be no Y-WIDTH when doing "quick & dirty" */X keyword = token(fp); keyword = token(fp); /* eat values */X error = parseError;X break;X case XWIDTH:X keyword = token(fp);X if (pos >= 0) /* ignore unmapped chars */X cwi[pos] = atoi(keyword);X break;X case ENDCHARMETRICS:X cont = FALSE;X break; X case ENDFONTMETRICS:X cont = FALSE;X error = normalEOF;X break;X case CHARNAME: /* eat values (so doesn't cause parseError) */X keyword = token(fp); X break;X case CHARBBOX: X keyword = token(fp); keyword = token(fp);X keyword = token(fp); keyword = token(fp);X break;X case LIGATURE:X keyword = token(fp); keyword = token(fp);X break;X case NOPE:X default: X error = parseError;X break;X } /* switch */X } /* while */X X return(error);X } /* parseCharWidths */ XX/************************* parseCharMetrics ************************/X/* This function is called by parseFile if the caller of parseFileX * requested that all character metric information be savedX * (as opposed to only the character width information).X *X * parseCharMetrics is passed in a pointer to an array of recordsX * to hold information on a per character basis. This functionX * parses the Character Metrics section storing all characterX * metric information for the ALL characters (mapped and unmapped) X * into the array.X *X * This function returns an error code specifying whether there was X * a premature EOF or a parsing error. This return value is used by X * parseFile to determine if there is more file to parse.X */X static parseCharMetrics(fp, fi)X FILE *fp;X register FontInfo *fi;{ X BOOL cont = TRUE, firstTime = TRUE;X int error = ok, count = 0;X register CharMetricInfo *temp = fi->cmi;X register char *keyword;X X while (cont)X {X keyword = token(fp);X if (keyword == NULL)X {X error = earlyEOF;X break; /* get out of loop */X }X switch(recognize(keyword))X {X case COMMENT:X keyword = linetoken(fp);X break; X case CODE:X if (count < fi->numOfChars)X { X if (firstTime) firstTime = FALSE;X else temp++;X temp->code = atoi(token(fp));X count++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -