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

📄 parseafm.c

📁 source code: Covert TXT to PDF
💻 C
📖 第 1 页 / 共 3 页
字号:
 *  a valid pointer to storage for the pair 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 parsePairKernData(fp, fi)     FILE *fp;     register FontInfo *fi;{    BOOL cont = T1LIB_TRUE, save = (fi->pkd != NULL);  int pos = 0, error = ok, pcount = 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 Pair Kerning Data */	/* section without saving any of the data */	switch(recognize(keyword))	  {	  case ENDKERNPAIRS:	  case ENDKERNDATA:	    cont = T1LIB_FALSE;	    break;	  case ENDFONTMETRICS:	    cont = T1LIB_FALSE;	    error = normalEOF;	    break;	  default:	    break;	  } /* switch */      else	/* otherwise parse entire Pair Kerning Data section, */	/* saving the data */	switch(recognize(keyword))	  {	  case COMMENT:	    keyword = linetoken(fp);	    break;	  case KERNPAIR:	    if (pcount < fi->numOfPairs)	      {		keyword = token(fp);		fi->pkd[pos].name1 = (char *) 		  malloc(strlen(keyword) + 1);		strcpy(fi->pkd[pos].name1, keyword);		keyword = token(fp);		fi->pkd[pos].name2 = (char *) 		  malloc(strlen(keyword) + 1);		strcpy(fi->pkd[pos].name2, keyword);		keyword = token(fp);		fi->pkd[pos].xamt = atoi(keyword);		keyword = token(fp);		fi->pkd[pos++].yamt = atoi(keyword);		pcount++;	      }	    else	      {		error = parseError;		cont = T1LIB_FALSE;	      }	    break;	  case KERNPAIRXAMT:	    if (pcount < fi->numOfPairs)	      {		keyword = token(fp);		fi->pkd[pos].name1 = (char *) 		  malloc(strlen(keyword) + 1);		strcpy(fi->pkd[pos].name1, keyword);		keyword = token(fp);		fi->pkd[pos].name2 = (char *) 		  malloc(strlen(keyword) + 1);		strcpy(fi->pkd[pos].name2, keyword);		keyword = token(fp);		fi->pkd[pos++].xamt = atoi(keyword);		pcount++;	      }	    else	      {		error = parseError;		cont = T1LIB_FALSE;	      }	    break;	  case ENDKERNPAIRS:	  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 && pcount != fi->numOfPairs)    error = parseError;          return(error);    } /* parsePairKernData */    /************************* parseCompCharData **************************//*  This function is called by "parseFile". It will parse the AFM File  *  up to the "EndComposites" keyword. It will save the composite  *  character data if requested by the caller of parseFile. * *  parseCompCharData is passed in a pointer to the FontInfo record, and  *  a boolean representing if the data should be saved. * *  This function will create the appropriate amount of storage for *  the composite character data and store a pointer to the storage *  in the FontInfo record. * *  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 parseCompCharData(fp, fi)  FILE *fp;  register FontInfo *fi;{      BOOL cont = T1LIB_TRUE, firstTime = T1LIB_TRUE, save = (fi->ccd != NULL);    int pos = 0, j = 0, error = ok, ccount = 0, pcount = 0;    register char *keyword;      while (cont)    {        keyword = token(fp);        if (keyword == NULL)          /* Have reached an early and unexpected EOF. */          /* Set flag and stop parsing */        {            error = earlyEOF;            break; /* get out of loop */        }        if (ccount > fi->numOfComps)        {            error = parseError;            break; /* get out of loop */        }        if (!save)          /* get tokens until the end of the Composite Character info */          /* section without saving any of the data */            switch(recognize(keyword))            {                case ENDCOMPOSITES:                    cont = T1LIB_FALSE;                    break;                case ENDFONTMETRICS:                    cont = T1LIB_FALSE;                    error = normalEOF;                    break;                default:                    break;            } /* switch */	else          /* otherwise parse entire Composite Character info section, */          /* saving the data */            switch(recognize(keyword))            {                case COMMENT:                    keyword = linetoken(fp);                    break;                case COMPCHAR:                    if (ccount < fi->numOfComps)                    {                        keyword = token(fp);                        if (pcount != fi->ccd[pos].numOfPieces)                            error = parseError;                        pcount = 0;                        if (firstTime) firstTime = T1LIB_FALSE;                        else pos++;                        fi->ccd[pos].ccName = (char *)                             malloc(strlen(keyword) + 1);                        strcpy(fi->ccd[pos].ccName, keyword);                        keyword = token(fp);                        fi->ccd[pos].numOfPieces = atoi(keyword);                        fi->ccd[pos].pieces = (Pcc *)                            calloc(fi->ccd[pos].numOfPieces, sizeof(Pcc));                        j = 0;                        ccount++;                    }                    else                    {                        error = parseError;                        cont = T1LIB_FALSE;                    }                    break;                case COMPCHARPIECE:                    if (pcount < fi->ccd[pos].numOfPieces)                    {                        keyword = token(fp);                        fi->ccd[pos].pieces[j].pccName = (char *)                                 malloc(strlen(keyword) + 1);                        strcpy(fi->ccd[pos].pieces[j].pccName, keyword);                        keyword = token(fp);                        fi->ccd[pos].pieces[j].deltax = atoi(keyword);                        keyword = token(fp);                        fi->ccd[pos].pieces[j++].deltay = atoi(keyword);                        pcount++;                    }                    else                        error = parseError;                    break;                case ENDCOMPOSITES:                    cont = T1LIB_FALSE;                    break;                case ENDFONTMETRICS:                    cont = T1LIB_FALSE;                    error = normalEOF;                    break;                case NOPE:                default:                    error = parseError;                    break;            } /* switch */    } /* while */        if (error == ok && ccount != fi->numOfComps)        error = parseError;        return(error);    } /* parseCompCharData */    /*************************** 'PUBLIC' FUNCTION ********************/ /*************************** parseFile *****************************//*  parseFile is the only 'public' procedure available. It is called  *  from an application wishing to get information from an AFM file. *  The caller of this function is responsible for locating and opening *  an AFM file and handling all errors associated with that task. * *  parseFile expects 3 parameters: a vaild file pointer, a pointer *  to a (FontInfo *) variable (for which storage will be allocated and *  the data requested filled in), and a mask specifying which *  data from the AFM File should be saved in the FontInfo structure. * *  The file will be parsed and the requested data will be stored in  *  a record of type FontInfo (refer to ParseAFM.h). * *  parseFile returns an error code as defined in parseAFM.h.  * *  The position of the read/write pointer associated with the file  *  pointer upon return of this function is undefined. *//* Note: function renamed to T1lib_parseFile in order to avoid name clushes   with other libraries that also use the Adobe parseAFM-package (RMz) */int T1lib_parseFile (fp, fi, flags)  FILE *fp;  FontInfo **fi;  FLAGS flags;{        int code = ok; 	/* return code from each of the parsing routines */    int error = ok;	/* used as the return code from this function */        register char *keyword; /* used to store a token */	        			          /* storage data for the global variable ident */			          ident = (char *) calloc(MAX_NAME, sizeof(char));     if (ident == NULL) {error = storageProblem; return(error);}            (*fi) = (FontInfo *) calloc(1, sizeof(FontInfo));    if ((*fi) == NULL) {error = storageProblem; return(error);}            if (flags & P_G)     {        (*fi)->gfi = (GlobalFontInfo *) calloc(1, sizeof(GlobalFontInfo));        if ((*fi)->gfi == NULL) {error = storageProblem; return(error);}          }        /* The AFM File begins with Global Font Information. This section */    /* will be parsed whether or not information should be saved. */         code = parseGlobals(fp, (*fi)->gfi);         if (code < 0) error = code;        /* The Global Font Information is followed by the Character Metrics */    /* section. Which procedure is used to parse this section depends on */    /* how much information should be saved. If all of the metrics info */    /* is wanted, parseCharMetrics is called. If only the character widths */    /* is wanted, parseCharWidths is called. parseCharWidths will also */    /* be called in the case that no character data is to be saved, just */    /* to parse through the section. */      if ((code != normalEOF) && (code != earlyEOF))    {        (*fi)->numOfChars = atoi(token(fp));	    if (flags & (P_M ^ P_W))        {            (*fi)->cmi = (CharMetricInfo *)                       calloc((*fi)->numOfChars, sizeof(CharMetricInfo));           if ((*fi)->cmi == NULL) {error = storageProblem; return(error);}            code = parseCharMetrics(fp, *fi);                     }        else        {            if (flags & P_W)            {                 (*fi)->cwi = (int *) calloc(256, sizeof(int));                 if ((*fi)->cwi == NULL)                 {                	error = storageProblem;                 	return(error);                }            }            /* parse section regardless */            code = parseCharWidths(fp, (*fi)->cwi);        } /* else */    } /* if */        if ((error != earlyEOF) && (code < 0)) error = code;        /* The remaining sections of the AFM are optional. This code will */    /* look at the next keyword in the file to determine what section */    /* is next, and then allocate the appropriate amount of storage */    /* for the data (if the data is to be saved) and call the */    /* appropriate parsing routine to parse the section. */        while ((code != normalEOF) && (code != earlyEOF)) {      keyword = token(fp);      if (keyword == NULL)	/* Have reached an early and unexpected EOF. */	/* Set flag and stop parsing */        {	  code = earlyEOF;	  break; /* get out of loop */        }      switch(recognize(keyword))        {	  /* this case has been added for t1lib because otherwise comment line	     between (i.e., outside) the main sections would lead to parse	     errors. The Adobe spec does not seem to forbid comments at	     such locations (2001-05-14, RMz) */	case COMMENT:	  keyword = linetoken(fp);	  break;	case STARTKERNDATA:	  break;	case ENDKERNDATA:	  break;	case STARTTRACKKERN:	  keyword = token(fp);	  if (flags & P_T)	    {	      (*fi)->numOfTracks = atoi(keyword);	      (*fi)->tkd = (TrackKernData *) 		calloc((*fi)->numOfTracks, sizeof(TrackKernData));	      if ((*fi)->tkd == NULL) 		{		  error = storageProblem; 		  return(error);		}	    } /* if */	  code = parseTrackKernData(fp, *fi);	  break;	case STARTKERNPAIRS:	  keyword = token(fp);	  if (flags & P_P)	    {	      (*fi)->numOfPairs = atoi(keyword);	      (*fi)->pkd = (PairKernData *) 		calloc((*fi)->numOfPairs, sizeof(PairKernData));	      if ((*fi)->pkd == NULL) 		{		  error = storageProblem; 		  return(error);		}	    } /* if */	  code = parsePairKernData(fp, *fi);	  break;	case STARTCOMPOSITES:	  keyword = token(fp);	  if (flags & P_C)	    { 	      (*fi)->numOfComps = atoi(keyword);	      (*fi)->ccd = (CompCharData *) 		calloc((*fi)->numOfComps, sizeof(CompCharData));	      if ((*fi)->ccd == NULL) 		{		  error = storageProblem; 		  return(error);		}	    } /* if */	  code = parseCompCharData(fp, *fi); 	  break;    	case ENDFONTMETRICS:	  code = normalEOF;	  break;	case NOPE:	default:	  code = parseError;	  break;        } /* switch */            if ((error != earlyEOF) && (code < 0)) error = code;          } /* while */        if ((error != earlyEOF) && (code < 0)) error = code;        if (ident != NULL) { free(ident); ident = NULL; }            return(error);  } /* parseFile */

⌨️ 快捷键说明

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