📄 parseafm.shar
字号:
X }X elseX {X error = parseError;X cont = FALSE;X }X break;X case XYWIDTH:X temp->wx = atoi(token(fp));X temp->wy = atoi(token(fp));X break; X case XWIDTH: X temp->wx = atoi(token(fp));X break;X case CHARNAME: X keyword = token(fp);X temp->name = (char *) malloc(strlen(keyword) + 1);X strcpy(temp->name, keyword);X break; X case CHARBBOX: X temp->charBBox.llx = atoi(token(fp));X temp->charBBox.lly = atoi(token(fp));X temp->charBBox.urx = atoi(token(fp));X temp->charBBox.ury = atoi(token(fp));X break;X case LIGATURE: {X Ligature **tail = &(temp->ligs);X Ligature *node = *tail;X X if (*tail != NULL)X {X while (node->next != NULL)X node = node->next;X tail = &(node->next); X }X X *tail = (Ligature *) calloc(1, sizeof(Ligature));X keyword = token(fp);X (*tail)->succ = (char *) malloc(strlen(keyword) + 1);X strcpy((*tail)->succ, keyword);X keyword = token(fp);X (*tail)->lig = (char *) malloc(strlen(keyword) + 1);X strcpy((*tail)->lig, keyword);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 ((error == ok) && (count != fi->numOfChars))X error = parseError;X X return(error);X } /* parseCharMetrics */ XXX/************************* parseTrackKernData ***********************/X/* This function is called by "parseFile". It will parse the AFM File X * up to the "EndTrackKern" or "EndKernData" keywords. It will save theX * track kerning data if requested by the caller of parseFile.X *X * parseTrackKernData is passed in a pointer to the FontInfo record.X * If data is to be saved, the FontInfo record will already contain X * a valid pointer to storage for the track kerning data.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 parseTrackKernData(fp, fi)X FILE *fp;X register FontInfo *fi;{ X BOOL cont = TRUE, save = (fi->tkd != NULL);X int pos = 0, error = ok, tcount = 0;X register char *keyword;X X while (cont)X {X keyword = token(fp);X 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 Track Kerning Data */X /* section without saving any of the data */X switch(recognize(keyword))X {X case ENDTRACKKERN:X case ENDKERNDATA: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 Track Kerning Data section, */X /* saving the data */X switch(recognize(keyword))X {X case COMMENT:X keyword = linetoken(fp);X break;X case TRACKKERN:X if (tcount < fi->numOfTracks)X {X keyword = token(fp);X fi->tkd[pos].degree = atoi(keyword);X keyword = token(fp);X fi->tkd[pos].minPtSize = atof(keyword);X if (errno == ERANGE) error = parseError;X keyword = token(fp);X fi->tkd[pos].minKernAmt = atof(keyword);X if (errno == ERANGE) error = parseError;X keyword = token(fp);X fi->tkd[pos].maxPtSize = atof(keyword);X if (errno == ERANGE) error = parseError;X keyword = token(fp);X fi->tkd[pos++].maxKernAmt = atof(keyword);X if (errno == ERANGE) error = parseError;X tcount++;X }X elseX {X error = parseError;X cont = FALSE;X }X break;X case ENDTRACKKERN:X case ENDKERNDATA: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 && tcount != fi->numOfTracks)X error = parseError;X X return(error);X } /* parseTrackKernData */ XX/************************* parsePairKernData ************************/X/* This function is called by "parseFile". It will parse the AFM File X * up to the "EndKernPairs" or "EndKernData" keywords. It will saveX * the pair kerning data if requested by the caller of parseFile.X *X * parsePairKernData is passed in a pointer to the FontInfo record.X * If data is to be saved, the FontInfo record will already contain X * a valid pointer to storage for the pair kerning data.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 parsePairKernData(fp, fi)X FILE *fp;X register FontInfo *fi;{ X BOOL cont = TRUE, save = (fi->pkd != NULL);X int pos = 0, error = ok, pcount = 0;X register char *keyword;X X while (cont)X {X keyword = token(fp);X 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 Pair Kerning Data */X /* section without saving any of the data */X switch(recognize(keyword))X {X case ENDKERNPAIRS:X case ENDKERNDATA: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 Pair Kerning Data section, */X /* saving the data */X switch(recognize(keyword))X {X case COMMENT:X keyword = linetoken(fp);X break;X case KERNPAIR:X if (pcount < fi->numOfPairs)X {X keyword = token(fp);X fi->pkd[pos].name1 = (char *) X malloc(strlen(keyword) + 1);X strcpy(fi->pkd[pos].name1, keyword);X keyword = token(fp);X fi->pkd[pos].name2 = (char *) X malloc(strlen(keyword) + 1);X strcpy(fi->pkd[pos].name2, keyword);X keyword = token(fp);X fi->pkd[pos].xamt = atoi(keyword);X keyword = token(fp);X fi->pkd[pos++].yamt = atoi(keyword);X pcount++;X }X elseX {X error = parseError;X cont = FALSE;X }X break;X case KERNPAIRXAMT:X if (pcount < fi->numOfPairs)X {X keyword = token(fp);X fi->pkd[pos].name1 = (char *) X malloc(strlen(keyword) + 1);X strcpy(fi->pkd[pos].name1, keyword);X keyword = token(fp);X fi->pkd[pos].name2 = (char *) X malloc(strlen(keyword) + 1);X strcpy(fi->pkd[pos].name2, keyword);X keyword = token(fp);X fi->pkd[pos++].xamt = atoi(keyword);X pcount++;X }X elseX {X error = parseError;X cont = FALSE;X }X break;X case ENDKERNPAIRS:X case ENDKERNDATA: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 && pcount != fi->numOfPairs)X error = parseError;X X return(error);X } /* parsePairKernData */ XX/************************* parseCompCharData **************************/X/* This function is called by "parseFile". It will parse the AFM File X * up to the "EndComposites" keyword. It will save the composite X * character data if requested by the caller of parseFile.X *X * parseCompCharData is passed in a pointer to the FontInfo record, and X * a boolean representing if the data should be saved.X *X * This function will create the appropriate amount of storage forX * the composite character data and store a pointer to the storageX * in the FontInfo record.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 parseCompCharData(fp, fi)X FILE *fp;X register FontInfo *fi;{ X BOOL cont = TRUE, firstTime = TRUE, save = (fi->ccd != NULL);X int pos = 0, j = 0, error = ok, ccount = 0, pcount = 0;X register char *keyword;X X while (cont)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 error = earlyEOF;X break; /* get out of loop */X }X if (ccount > fi->numOfComps)X {X error = parseError;X break; /* get out of loop */X }X if (!save)X /* get tokens until the end of the Composite Character info */X /* section without saving any of the data */X switch(recognize(keyword))X {X case ENDCOMPOSITES: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 Composite Character info section, */X /* saving the data */X switch(recognize(keyword))X {X case COMMENT:X keyword = linetoken(fp);X break;X case COMPCHAR:X if (ccount < fi->numOfComps)X {X keyword = token(fp);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -