📄 scanfont.c
字号:
objFormatInteger(objP, tokenValue.integer); } else return(SCAN_ERROR); N++; } while ( 1>0 ); /* NOTREACHED*/}/***================================================================***//* is not needed *//* 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))) ); return(SCAN_OK); }*//***================================================================***/static int getNbytes(N) int N;{ int I; if (N > vm_free_bytes()) { if (!vm_init()) return(SCAN_OUT_OF_MEMORY); } tokenStartP = vm_next_byte(); 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" or "ND" or "|-" or (noaccess) "def". If one of the latter three token appears, we are done even if still i < N-1. in this case, there aren磘 as much subroutines as fields in the array which is allowed (Fix thanks to Derek B. Noonburg) */ do { rc = getNextValue(TOKEN_NAME); if ( rc != SCAN_OK ) return(rc); if (!strncmp(tokenStartP, "ND", 2) || !strncmp(tokenStartP, "|-", 2) || !strncmp(tokenStartP, "def", 3)) { return SCAN_OK; } } while (strncmp(tokenStartP, "dup", 3)); 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); /* explicitly resetting the array is not necessary since the pointer as well as the subroutines both are located in VM and we can assume that only define subroutines are referenced. */ FontP->Subrs.len = N; FontP->Subrs.data.arrayP = arrayP; /* get N values for Subrs */ for (i=0;i<N;i++) { /* look for "dup" or "ND" or "|-" or (noaccess) "def". If one of the latter three token appears, we are done even if still i < N-1. in this case, there aren磘 as much subroutines as fields in the array which is allowed (Fix thanks to Derek B. Noonburg) */ do { rc = getNextValue(TOKEN_NAME); if ( rc != SCAN_OK ) return(rc); if (!strncmp(tokenStartP, "ND", 2) || !strncmp(tokenStartP, "|-", 2) || !strncmp(tokenStartP, "def", 3)) { return SCAN_OK; } } while (strncmp(tokenStartP, "dup", 3)); /* get 2 integers */ I = getInt(); /* index into array of Subroutines */ if (rc) return(rc); J = getInt(); /* number of binary bytes that follow */ 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=SCAN_END, the end of file has been reached. This means there were less than N charstrings. This is perfectly valid. */ 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 *//* "LenIV" corrected to be "lenIV", otherwise fonts with some specific lenIV value could not be decrypted. (RMz, Author of t1lib, 06/03/1998)*//***================================================================***/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 */ HintEntryP = &(PrivateDictP[OTHERBLUES].value); /* check to see if the entry exists and if it's an array */ if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 )) blues->numOtherBlues = 0; else { /* get the number of values in the array */ if (HintEntryP->len > NUMOTHERBLUES) { blues->numOtherBlues = NUMOTHERBLUES; } else blues->numOtherBlues = HintEntryP->len; for (i = 0; i<= blues->numOtherBlues-1; ++i) { if (objPIsInteger(&HintEntryP->data.arrayP[i])) blues->OtherBlues[i] = HintEntryP->data.arrayP[i].data.integer; else if (objPIsReal(&HintEntryP->data.arrayP[i])) blues->OtherBlues[i] = HintEntryP->data.arrayP[i].data.real; else blues->OtherBlues[i] = 0; } } /* fill in the FamilyBlues array */ HintEntryP = &(PrivateDictP[FAMILYBLUES].value); /* check to see if the entry exists and if it's an array */ if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 )) blues->numFamilyBlues = 0; else { /* get the number of values in the array */ if (HintEntryP->len > NUMFAMILYBLUES) { blues->numFamilyBlues = NUMFAMILYBLUES; } else blues->numFamilyBlues = HintEntryP->len; for (i = 0; i<= blues->numFamilyBlues-1; ++i) { if (objPIsInteger(&HintEntryP->data.arrayP[i])) blues->FamilyBlues[i] = HintEntryP->data.arrayP[i].data.integer; else if (objPIsReal(&HintEntryP->data.arrayP[i])) blues->FamilyBlues[i] = HintEntryP->data.arrayP[i].data.real; else blues->FamilyBlues[i] = 0; } } /* fill in the FamilyOtherBlues array */ HintEntryP = &(PrivateDictP[FAMILYOTHERBLUES].value); /* check to see if the entry exists and if it's an array */ if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 )) blues->numFamilyOtherBlues = 0; else { /* get the number of values in the array */ if (HintEntryP->len > NUMFAMILYOTHERBLUES) { blues->numFamilyOtherBlues = NUMFAMILYOTHERBLUES; } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -