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

📄 parseafm.c

📁 source code: Covert TXT to PDF
💻 C
📖 第 1 页 / 共 3 页
字号:
                    break;                case ENDFONTMETRICS:                    cont = T1LIB_FALSE;                    error = normalEOF;                    break;                case NOPE:                default:                    error = parseError;                    break;            } /* switch */    } /* while */        return(error);    } /* parseGlobals */    /************************* initializeArray ************************//*  Unmapped character codes are (at Adobe Systems) assigned the *  width of the space character (if one exists) else they get the *  value of 250 ems. This function initializes all entries in the *  char widths array to have this value. Then any mapped character  *  codes will be replaced with the width of the appropriate character  *  when parsing the character metric section.  *  This function parses the Character Metrics Section looking *  for a space character (by comparing character names). If found, *  the width of the space character will be used to initialize the *  values in the array of character widths.  * *  Before returning, the position of the read/write pointer of the *  file is reset to be where it was upon entering this function. *//* We comment out the following function since it is not needed in t1lib   and we don't want compiler warnings *//*static int initializeArray(fp, cwi)   FILE *fp;  register int *cwi;{      BOOL cont = T1LIB_TRUE, found = T1LIB_FALSE;    long opos = ftell(fp);    int code = 0, width = 0, i = 0, error = 0;    register char *keyword;      while (cont)    {        keyword = token(fp);        if (keyword == NULL)        {	    error = earlyEOF;            break;         }        switch(recognize(keyword))        {            case COMMENT:                keyword = linetoken(fp);                break;            case CODE:                code = atoi(token(fp));                break;            case XWIDTH:                width = atoi(token(fp));                break;            case CHARNAME:                 keyword = token(fp);                if (MATCH(keyword, Space))                {                        cont = T1LIB_FALSE;                    found = T1LIB_TRUE;                }                 break;                        case ENDCHARMETRICS:                cont = T1LIB_FALSE;                break;             case ENDFONTMETRICS:                cont = T1LIB_FALSE;                error = normalEOF;                break;            case NOPE:            default:                 error = parseError;                break;        }     }         if (!found)        width = 250;        for (i = 0; i < 256; ++i)        cwi[i] = width;        fseek(fp, opos, 0);        return(error);        }*/ /************************* parseCharWidths **************************//*  This function is called by "parseFile". It will parse the AFM File *  up to the "EndCharMetrics" keyword. It will save the character  *  width info (as opposed to all of the character metric information) *  if requested by the caller of parseFile. Otherwise, it will just *  parse through the section without saving any information. * *  If data is to be saved, parseCharWidths is passed in a pointer  *  to an array of widths that has already been initialized by the *  standard value for unmapped character codes. This function parses *  the Character Metrics section only storing the width information *  for the encoded characters into the array using the character code *  as the index into that array. * *  This function returns an error code specifying whether there was  *  a premature EOF or a parsing error. This return value is used by  *  parseFile to determine if there is more file to parse. */ static int parseCharWidths(fp, cwi)  FILE *fp;  register int *cwi;{      BOOL cont = T1LIB_TRUE, save = (cwi != NULL);    int pos = 0, error = ok;    register char *keyword;        while (cont)    {        keyword = token(fp);          /* Have reached an early and unexpected EOF. */          /* Set flag and stop parsing */        if (keyword == NULL)        {            error = earlyEOF;            break; /* get out of loop */        }        if (!save)	          /* get tokens until the end of the Char Metrics section without */          /* saving any of the data*/            switch (recognize(keyword))              {				                case ENDCHARMETRICS:                    cont = T1LIB_FALSE;                    break;                 case ENDFONTMETRICS:                    cont = T1LIB_FALSE;                    error = normalEOF;                    break;                default:                     break;            } /* switch */        else          /* otherwise parse entire char metrics section, saving */          /* only the char x-width info */            switch(recognize(keyword))            {                case COMMENT:                    keyword = linetoken(fp);                    break;                case CODE:                    keyword = token(fp);                    pos = atoi(keyword);                    break;                case XYWIDTH:                /* PROBLEM: Should be no Y-WIDTH when doing "quick & dirty" */                    keyword = token(fp); keyword = token(fp); /* eat values */                    error = parseError;                    break;                case XWIDTH:                    keyword = token(fp);                    if (pos >= 0) /* ignore unmapped chars */                        cwi[pos] = atoi(keyword);                    break;                case ENDCHARMETRICS:                    cont = T1LIB_FALSE;                    break;                 case ENDFONTMETRICS:                    cont = T1LIB_FALSE;                    error = normalEOF;                    break;                case CHARNAME:	/* eat values (so doesn't cause parseError) */                    keyword = token(fp);                     break;            	case CHARBBOX:                     keyword = token(fp); keyword = token(fp);                    keyword = token(fp); keyword = token(fp);		    break;		case LIGATURE:                    keyword = token(fp); keyword = token(fp);		    break;                case NOPE:                default:                     error = parseError;                    break;            } /* switch */    } /* while */        return(error);    } /* parseCharWidths */    /************************* parseCharMetrics ************************//*  This function is called by parseFile if the caller of parseFile *  requested that all character metric information be saved *  (as opposed to only the character width information). * *  parseCharMetrics is passed in a pointer to an array of records *  to hold information on a per character basis. This function *  parses the Character Metrics section storing all character *  metric information for the ALL characters (mapped and unmapped)  *  into the array. * *  This function returns an error code specifying whether there was  *  a premature EOF or a parsing error. This return value is used by  *  parseFile to determine if there is more file to parse. */ static int parseCharMetrics(fp, fi)  FILE *fp;  register FontInfo *fi;{      BOOL cont = T1LIB_TRUE, firstTime = T1LIB_TRUE;    int error = ok, count = 0;    register CharMetricInfo *temp = fi->cmi;    register char *keyword;      while (cont)    {        keyword = token(fp);        if (keyword == NULL)        {            error = earlyEOF;            break; /* get out of loop */        }        switch(recognize(keyword))        {            case COMMENT:                keyword = linetoken(fp);                break;             case CODE:                if (count < fi->numOfChars)                {                     if (firstTime) firstTime = T1LIB_FALSE;                    else temp++;                    temp->code = atoi(token(fp));                    count++;                }                else                {                    error = parseError;                    cont = T1LIB_FALSE;                }                break;            case XYWIDTH:                temp->wx = atoi(token(fp));                temp->wy = atoi(token(fp));                break;                             case XWIDTH:                 temp->wx = atoi(token(fp));                break;            case CHARNAME:                 keyword = token(fp);                temp->name = (char *) malloc(strlen(keyword) + 1);                strcpy(temp->name, keyword);                break;                        case CHARBBOX:                 temp->charBBox.llx = atoi(token(fp));                temp->charBBox.lly = atoi(token(fp));                temp->charBBox.urx = atoi(token(fp));                temp->charBBox.ury = atoi(token(fp));                break;            case LIGATURE: {                Ligature **tail = &(temp->ligs);                Ligature *node = *tail;                                if (*tail != NULL)                {                    while (node->next != NULL)                        node = node->next;                    tail = &(node->next);                 }                                *tail = (Ligature *) calloc(1, sizeof(Ligature));                keyword = token(fp);                (*tail)->succ = (char *) malloc(strlen(keyword) + 1);                strcpy((*tail)->succ, keyword);                keyword = token(fp);                (*tail)->lig = (char *) malloc(strlen(keyword) + 1);                strcpy((*tail)->lig, keyword);                break; }            case ENDCHARMETRICS:                cont = T1LIB_FALSE;;                break;             case ENDFONTMETRICS:                 cont = T1LIB_FALSE;                error = normalEOF;                break;             case NOPE:            default:                error = parseError;                 break;         } /* switch */    } /* while */        if ((error == ok) && (count != fi->numOfChars))        error = parseError;        return(error);    } /* parseCharMetrics */    /************************* parseTrackKernData ***********************//*  This function is called by "parseFile". It will parse the AFM File  *  up to the "EndTrackKern" or "EndKernData" keywords. It will save the *  track kerning data if requested by the caller of parseFile. * *  parseTrackKernData is passed in a pointer to the FontInfo record. *  If data is to be saved, the FontInfo record will already contain  *  a valid pointer to storage for the track kerning data. * *  This function returns an error code specifying whether there was  *  a premature EOF or a parsing error. This return value is used by  *  parseFile to determine if there is more file to parse. */ static int parseTrackKernData(fp, fi)  FILE *fp;  register FontInfo *fi;{      BOOL cont = T1LIB_TRUE, save = (fi->tkd != NULL);    int pos = 0, error = ok, tcount = 0;    register char *keyword;      while (cont)    {        keyword = token(fp);                if (keyword == NULL)        {            error = earlyEOF;            break; /* get out of loop */        }        if (!save)          /* get tokens until the end of the Track Kerning Data */          /* section without saving any of the data */            switch(recognize(keyword))            {                case ENDTRACKKERN:                case ENDKERNDATA:                    cont = T1LIB_FALSE;                    break;                case ENDFONTMETRICS:                    cont = T1LIB_FALSE;                    error = normalEOF;                    break;                default:                    break;            } /* switch */	else          /* otherwise parse entire Track Kerning Data section, */          /* saving the data */            switch(recognize(keyword))            {                case COMMENT:                    keyword = linetoken(fp);                    break;                case TRACKKERN:                    if (tcount < fi->numOfTracks)                    {                        keyword = token(fp);                        fi->tkd[pos].degree = atoi(keyword);                        keyword = token(fp);                        fi->tkd[pos].minPtSize = atof(keyword);                        if (errno == ERANGE) error = parseError;                        keyword = token(fp);                        fi->tkd[pos].minKernAmt = atof(keyword);                        if (errno == ERANGE) error = parseError;                        keyword = token(fp);                        fi->tkd[pos].maxPtSize = atof(keyword);                        if (errno == ERANGE) error = parseError;                        keyword = token(fp);                        fi->tkd[pos++].maxKernAmt = atof(keyword);                        if (errno == ERANGE) error = parseError;                        tcount++;                    }                    else                    {                        error = parseError;                        cont = T1LIB_FALSE;                    }                    break;                case ENDTRACKKERN:                case ENDKERNDATA:                    cont = T1LIB_FALSE;                    break;                case ENDFONTMETRICS:                    cont = T1LIB_FALSE;                    error = normalEOF;                    break;                case NOPE:                default:                    error = parseError;                    break;            } /* switch */    } /* while */        if (error == ok && tcount != fi->numOfTracks)        error = parseError;            return(error);    } /* parseTrackKernData */    /************************* parsePairKernData ************************//*  This function is called by "parseFile". It will parse the AFM File  *  up to the "EndKernPairs" or "EndKernData" keywords. It will save *  the pair kerning data if requested by the caller of parseFile. * *  parsePairKernData is passed in a pointer to the FontInfo record. *  If data is to be saved, the FontInfo record will already contain 

⌨️ 快捷键说明

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