📄 scanfont.c
字号:
arrayP->data.valueP = (char *) objP; arrayP->len = 256; for (i=0; i<256; i++, objP++) { scan_token(inputP); if (tokenType != TOKEN_LITERAL_NAME) return(SCAN_ERROR); if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY); objFormatName(objP,tokenLength,tokenStartP); } scan_token(inputP); if ( (tokenType == TOKEN_RIGHT_BRACE) || (tokenType == TOKEN_RIGHT_BRACKET) ) return(SCAN_OK); } else { /* Must be sequences of ``dup <index> <charactername> put" */ psobj *objP; int i; objP = (psobj *)vm_alloc(256*(sizeof(psobj))); if (!(objP)) return(SCAN_OUT_OF_MEMORY); arrayP->data.valueP = (char *) objP; arrayP->len = 256; for (i=0; i<256; i++) objFormatName(objP + i, 7, ".notdef"); while (TRUE) { scan_token(inputP); switch (tokenType) { case TOKEN_NAME: if (tokenLength == 3) { if (strncmp(tokenStartP,"dup",3) == 0) { /* get <index> */ scan_token(inputP); if (tokenType != TOKEN_INTEGER || tokenValue.integer < 0 || tokenValue.integer > 255) return (SCAN_ERROR); i = tokenValue.integer; /* get <characer_name> */ scan_token(inputP); if (tokenType != TOKEN_LITERAL_NAME) return(SCAN_ERROR); if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY); objFormatName(objP + i,tokenLength,tokenStartP); /* get "put" */ scan_token(inputP); if (tokenType != TOKEN_NAME) return(SCAN_ERROR); } else if (strncmp(tokenStartP,"def",3) == 0) return (SCAN_OK); } break; case TOKEN_EOF: case TOKEN_NONE: case TOKEN_INVALID: return (SCAN_ERROR); } } } return (SCAN_ERROR);}/***================================================================***/static int getArray(arrayP) psobj *arrayP;{ int N; /* count the items in the array */ psobj *objP; /* That is totally a kludge. If some stupid font file has * /foo/foo # ftp://ftp.cdrom.com/pub/os2/fonts/future.zip * we will treat it as /foo. * H.J. */ char tmp [1024]; strncpy (tmp, tokenStartP, sizeof (tmp)); tmp [sizeof (tmp) - 1] = '\0';restart: scan_token(inputP); switch (tokenType) { case TOKEN_LEFT_BRACE: case TOKEN_LEFT_BRACKET: break; case TOKEN_LITERAL_NAME: tokenStartP[tokenLength] = '\0'; if (strcmp (tokenStartP, tmp) == 0) { /* Ok, We see /foo/foo. Let's restart. */ goto restart; } default: return(SCAN_ERROR); } /* format the array in memory, save pointer to the beginning */ arrayP->data.valueP = tokenStartP; /* loop, picking up next object, until right BRACE or BRACKET */ N = 0; do { scan_token(inputP); if ( (tokenType == TOKEN_RIGHT_BRACE) || (tokenType == TOKEN_RIGHT_BRACKET) ) { /* save then number of items in the array */ arrayP->len = N; return(SCAN_OK); } /* allocate the space for the object */ objP = (psobj *)vm_alloc(sizeof(psobj)); if (!(objP)) return(SCAN_OUT_OF_MEMORY); /* array is an array of numbers, (real or integer) */ if (tokenType == TOKEN_REAL) { objFormatReal(objP, tokenValue.real); } else if (tokenType == TOKEN_INTEGER) { objFormatInteger(objP, tokenValue.integer); } else return(SCAN_ERROR); N++; } while ( 1>0 ); /* NOTREACHED*/}/***================================================================***/static int getName(nameP) char *nameP;{ do { scan_token(inputP); if (tokenType <= TOKEN_NONE) { if (tokenTooLong) return(SCAN_OUT_OF_MEMORY); return(SCAN_ERROR); } } while ((tokenType != TOKEN_NAME) || (0 != strncmp(tokenStartP,nameP,strlen(nameP))) ); /* found */ return(SCAN_OK);}/***================================================================***/static int getNbytes(N) int N;{ int I; tokenStartP = vm_next_byte(); tokenMaxP = tokenStartP + MIN(vm_free_bytes(), MAX_STRING_LEN); if (N > vm_free_bytes()) { return(SCAN_OUT_OF_MEMORY); } I = fread(tokenStartP,1,N,inputP->data.fileP); if ( I != N ) return(SCAN_FILE_EOF); return(SCAN_OK);} /***================================================================***//* getLiteralName(nameObjP) *//* scan for next literal. *//* if we encounter the name 'end' then terminate and say ok. *//* It means that the CharStrings does not have as many characters *//* as the dictionary said it would and that is ok. *//***================================================================***/static int getLiteralName(nameObjP) psobj *nameObjP;{ do { scan_token(inputP); if (tokenType <= TOKEN_NONE) { if (tokenTooLong) return(SCAN_OUT_OF_MEMORY); return(SCAN_ERROR); } if (tokenType == TOKEN_NAME) { if (0 == strncmp(tokenStartP,"end",3) ) { return(SCAN_END); } } } while (tokenType != TOKEN_LITERAL_NAME) ; nameObjP->len = tokenLength; /* allocate all the names in the CharStrings Structure */ if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY); nameObjP->data.valueP = tokenStartP; /* found */ return(SCAN_OK);} /***================================================================***//* * BuildSubrs routine *//***================================================================***/ static int BuildSubrs(FontP) psfont *FontP;{ int N; /* number of values in Subrs */ int I; /* index into Subrs */ int i; /* loop thru Subrs */ int J; /* length of Subrs entry */ psobj *arrayP; /* next token should be a positive int */ /* note: rc is set by getInt. */ N = getInt(); if (rc) return(rc); if (N < 0 ) return(SCAN_ERROR); /* if we already have a Subrs, then skip the second one */ /* The second one is for hiresolution devices. */ if (FontP->Subrs.data.arrayP != NULL) { TwoSubrs = TRUE; /* process all the Subrs, but do not update anything */ /* can not just skip them because of the binary data */ for (i=0;i<N;i++) { /* look for dup */ rc = getName("dup"); if (rc) return(rc); /* get 2 integers */ I = getInt(); if (rc) return(rc); J = getInt(); if (rc) return(rc); if ( (I < 0) || (J < 0 ) ) return (SCAN_ERROR); /* get the next token, it should be RD or -|, either is ok */ rc = getNextValue(TOKEN_NAME); if ( rc != SCAN_OK ) return(rc); rc = getNbytes(J); if (rc) return(rc); } return(SCAN_OK); } arrayP = (psobj *)vm_alloc(N*sizeof(psobj)); if (!(arrayP) ) return(SCAN_OUT_OF_MEMORY); FontP->Subrs.len = N; FontP->Subrs.data.arrayP = arrayP; /* get N values for Subrs */ for (i=0;i<N;i++) { /* look for dup */ rc = getName("dup"); if (rc) return(rc); /* get 2 integers */ I = getInt(); if (rc) return(rc); J = getInt(); if (rc) return(rc); if ( (I < 0) || (J < 0 ) ) return (SCAN_ERROR); arrayP[I].len = J; /* get the next token, it should be RD or -|, either is ok */ rc = getNextValue(TOKEN_NAME); if ( rc != SCAN_OK ) return(rc); rc = getNbytes(J); if (rc == SCAN_OK) { arrayP[I].data.valueP = tokenStartP; if ( !(vm_alloc(J)) ) return(SCAN_OUT_OF_MEMORY); } else return(rc); } return(SCAN_OK); }/***================================================================***//***================================================================***//* * BuildCharStrings routine *//***================================================================***/ static int BuildCharStrings(FontP) psfont *FontP;{ int N; /* number of values in CharStrings */ int i; /* loop thru Subrs */ int J; /* length of Subrs entry */ psdict *dictP; /* next token should be a positive int */ N = getInt(); if (rc) { /* check if file had TwoSubrs, hi resolution stuff is in file*/ if (TwoSubrs) { do { scan_token(inputP); if (tokenType <= TOKEN_NONE) { if (tokenTooLong) return(SCAN_OUT_OF_MEMORY); return(SCAN_ERROR); } } while (tokenType != TOKEN_INTEGER); N = tokenValue.integer; } else return(rc); /* if next token was not an Int */ } if (N<=0) return(SCAN_ERROR); /* save number of entries in the dictionary */ dictP = (psdict *)vm_alloc((N+1)*sizeof(psdict)); if (!(dictP)) return(SCAN_OUT_OF_MEMORY); FontP->CharStringsP = dictP; dictP[0].key.len = N; /* get N values for CharStrings */ for (i=1;i<=N;i++) { /* look for next literal name */ rc = getLiteralName(&(dictP[i].key)); if (rc) return(rc); /* get 1 integer */ J = getInt(); if (rc) return(rc); /* if next token was not an Int */ if (J<0) return (SCAN_ERROR); dictP[i].value.len = J; /* get the next token, it should be RD or -|, either is ok */ rc = getNextValue(TOKEN_NAME); if ( rc != SCAN_OK ) return(rc); rc = getNbytes(J); if (rc == SCAN_OK) { dictP[i].value.data.valueP = tokenStartP; if ( !(vm_alloc(J)) ) return(SCAN_OUT_OF_MEMORY); } else return(rc); } return(SCAN_OK); }/***================================================================***//***================================================================***//* * BuildFontInfo Dictionary *//***================================================================***/static int BuildFontInfo(fontP) psfont *fontP;{ psdict *dictP; /* allocate the private dictionary */ dictP = (psdict *)vm_alloc(20*sizeof(psdict)); if (!(dictP)) return(SCAN_OUT_OF_MEMORY); fontP->fontInfoP = dictP; fontP->fontInfoP[0].key.len = 17; /* number of actual entries */ objFormatName(&(dictP[FONTNAME].key),8,"FontName"); objFormatName(&(dictP[FONTNAME].value),0,NULL); objFormatName(&(dictP[PAINTTYPE].key),9,"PaintType"); objFormatInteger(&(dictP[PAINTTYPE].value),0); objFormatName(&(dictP[FONTTYPENUM].key),8,"FontType"); objFormatInteger(&(dictP[FONTTYPENUM].value),0); objFormatName(&(dictP[FONTMATRIX].key),10,"FontMatrix"); objFormatArray(&(dictP[FONTMATRIX].value),0,NULL); objFormatName(&(dictP[FONTBBOX].key),8,"FontBBox"); objFormatArray(&(dictP[FONTBBOX].value),0,NULL); objFormatName(&(dictP[ENCODING].key),8,"Encoding"); objFormatEncoding(&(dictP[ENCODING].value),0,NULL); objFormatName(&(dictP[UNIQUEID].key),8,"UniqueID"); objFormatInteger(&(dictP[UNIQUEID].value),0); objFormatName(&(dictP[STROKEWIDTH].key),11,"StrokeWidth"); objFormatReal(&(dictP[STROKEWIDTH].value),0.0); objFormatName(&(dictP[VERSION].key),7,"version"); objFormatString(&(dictP[VERSION].value),0,NULL); objFormatName(&(dictP[NOTICE].key),6,"Notice"); objFormatString(&(dictP[NOTICE].value),0,NULL); objFormatName(&(dictP[FULLNAME].key),8,"FullName"); objFormatString(&(dictP[FULLNAME].value),0,NULL); objFormatName(&(dictP[FAMILYNAME].key),10,"FamilyName"); objFormatString(&(dictP[FAMILYNAME].value),0,NULL); objFormatName(&(dictP[WEIGHT].key),6,"Weight"); objFormatString(&(dictP[WEIGHT].value),0,NULL); objFormatName(&(dictP[ITALICANGLE].key),11,"ItalicAngle"); objFormatReal(&(dictP[ITALICANGLE].value),0.0); objFormatName(&(dictP[ISFIXEDPITCH].key),12,"isFixedPitch"); objFormatBoolean(&(dictP[ISFIXEDPITCH].value),FALSE); objFormatName(&(dictP[UNDERLINEPOSITION].key),17,"UnderlinePosition"); objFormatReal(&(dictP[UNDERLINEPOSITION].value),0.0); objFormatName(&(dictP[UNDERLINETHICKNESS].key),18,"UnderlineThickness"); objFormatReal(&(dictP[UNDERLINETHICKNESS].value),0.0); return(SCAN_OK);}/***================================================================***//* * BuildPrivate Dictionary *//***================================================================***/static int BuildPrivate(fontP) psfont *fontP;{ psdict *Private; /* allocate the private dictionary */ Private = (psdict *)vm_alloc(20*sizeof(psdict)); if (!(Private)) return(SCAN_OUT_OF_MEMORY); fontP->Private = Private; fontP->Private[0].key.len = 16; /* number of actual entries */ objFormatName(&(Private[BLUEVALUES].key),10,"BlueValues"); objFormatArray(&(Private[BLUEVALUES].value),0,NULL); objFormatName(&(Private[OTHERBLUES].key),10,"OtherBlues"); objFormatArray(&(Private[OTHERBLUES].value),0,NULL); objFormatName(&(Private[FAMILYBLUES].key),11,"FamilyBlues"); objFormatArray(&(Private[FAMILYBLUES].value),0,NULL); objFormatName(&(Private[FAMILYOTHERBLUES].key),16,"FamilyOtherBlues"); objFormatArray(&(Private[FAMILYOTHERBLUES].value),0,NULL); objFormatName(&(Private[BLUESCALE].key),9,"BlueScale"); objFormatReal(&(Private[BLUESCALE].value),DEFAULTBLUESCALE); objFormatName(&(Private[BLUESHIFT].key),9,"BlueShift"); objFormatInteger(&(Private[BLUESHIFT].value),DEFAULTBLUESHIFT); objFormatName(&(Private[BLUEFUZZ].key),8,"BlueFuzz"); objFormatInteger(&(Private[BLUEFUZZ].value),DEFAULTBLUEFUZZ); objFormatName(&(Private[STDHW].key),5,"StdHW"); objFormatArray(&(Private[STDHW].value),0,NULL); objFormatName(&(Private[STDVW].key),5,"StdVW"); objFormatArray(&(Private[STDVW].value),0,NULL); objFormatName(&(Private[STEMSNAPH].key),9,"StemSnapH"); objFormatArray(&(Private[STEMSNAPH].value),0,NULL); objFormatName(&(Private[STEMSNAPV].key),9,"StemSnapV"); objFormatArray(&(Private[STEMSNAPV].value),0,NULL); objFormatName(&(Private[FORCEBOLD].key),9,"ForceBold"); objFormatBoolean(&(Private[FORCEBOLD].value),DEFAULTFORCEBOLD); objFormatName(&(Private[LANGUAGEGROUP].key),13,"LanguageGroup"); objFormatInteger(&(Private[LANGUAGEGROUP].value),DEFAULTLANGUAGEGROUP); objFormatName(&(Private[LENIV].key),5,"lenIV"); objFormatInteger(&(Private[LENIV].value),DEFAULTLENIV); objFormatName(&(Private[RNDSTEMUP].key),9,"RndStemUp"); objFormatBoolean(&(Private[RNDSTEMUP].value),DEFAULTRNDSTEMUP); objFormatName(&(Private[EXPANSIONFACTOR].key),9,"ExpansionFactor"); objFormatReal(&(Private[EXPANSIONFACTOR].value), DEFAULTEXPANSIONFACTOR); return(SCAN_OK);}/***================================================================***//**********************************************************************//* GetType1Blues(fontP) *//* *//* Routine to support font-level hints. *//* *//* Gets all the Blues information from the Private dictionary *//* for the font. *//* *//* *//**********************************************************************/static int GetType1Blues(fontP) psfont *fontP;{ psdict *PrivateDictP; /* the Private dict relating to hints */ struct blues_struct *blues; /* ptr for the blues struct we will allocate */ int i; psobj *HintEntryP; /* get the Private dictionary pointer */ PrivateDictP = fontP->Private; /* allocate the memory for the blues structure */ blues = (struct blues_struct *) vm_alloc(sizeof(struct blues_struct)); if (!blues) return(SCAN_OUT_OF_MEMORY); /* Make fontP's blues ptr point to this newly allocated structure. */ fontP->BluesP = blues; /* fill in the BlueValues array */ HintEntryP = &(PrivateDictP[BLUEVALUES].value); /* check to see if the entry exists and if it's an array */ if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 )) blues->numBlueValues = 0; else { /* get the number of values in the array */ if (HintEntryP->len > NUMBLUEVALUES) { blues->numBlueValues = NUMBLUEVALUES; } else blues->numBlueValues = HintEntryP->len; for (i = 0; i<= blues->numBlueValues-1; ++i) { if (objPIsInteger(&HintEntryP->data.arrayP[i])) blues->BlueValues[i] = HintEntryP->data.arrayP[i].data.integer; else if (objPIsReal(&HintEntryP->data.arrayP[i])) blues->BlueValues[i] = HintEntryP->data.arrayP[i].data.real; else blues->BlueValues[i] = 0; } } /* fill in the OtherBlues array */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -