📄 t1load.c
字号:
i=pFontBase->pFontArray[FontID].pType1Data->fontInfoP[0].key.len; for (j=1; j<=i; j++){ if ((pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_ARRAY) || (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_STRING) || (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_NAME) || (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_FILE)){ ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.valueP=(char *)ldummy; } /* The encoding needs special treatment: */ if (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_ENCODING){ /* If a builtin encoding is used, it is sufficient to shift the pointer to the Encoding since the character-namestrings of builtin encodings are static and thus located on the heap. For font-specific encoding, character-namestrings reside in VM and thus each entry has to be shifted. Caution: We still have to shift the builtin encoding-pointer, since they also point to are located in VM: */ ldummy=(long)StdEncArrayP; ldummy -=shift; StdEncArrayP=(psobj *)ldummy; ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.valueP=(char *)ldummy; if (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.arrayP == StdEncArrayP){ /* Font uses builtin encoding */ ; } else{ /* Font-specific encoding */ for (k=0; k<256; k++){ ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.arrayP[k].data.arrayP; /* The ".notdef" is also static and may not be shifted (Thanks, Derek ;) */ if (ldummy != (unsigned long)not_def) { ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.arrayP[k].data.arrayP=(struct ps_obj *)ldummy; } } } } /* end of encoding-handling */ ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].key.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].key.data.valueP=(char *)ldummy; } /* fontinfo-dict done */ /* Private-dictionary: All name-pointers and the pointers to all array types have to be shifted: */ i=pFontBase->pFontArray[FontID].pType1Data->Private[0].key.len; for (j=1; j<=i; j++){ if ((pFontBase->pFontArray[FontID].pType1Data->Private[j].value.type==OBJ_ARRAY) || (pFontBase->pFontArray[FontID].pType1Data->Private[j].value.type==OBJ_STRING) || (pFontBase->pFontArray[FontID].pType1Data->Private[j].value.type==OBJ_NAME) || (pFontBase->pFontArray[FontID].pType1Data->Private[j].value.type==OBJ_FILE)){ ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Private[j].value.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->Private[j].value.data.valueP=(char *)ldummy; } ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Private[j].key.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->Private[j].key.data.valueP=(char *)ldummy; } /* BluesP: The entry "next" is the only pointer in blues_struct. Although it is not used anywhere we should shift it for correctness reasons (in case its not NULL)! */ if (pFontBase->pFontArray[FontID].pType1Data->BluesP->next != NULL){ ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->BluesP->next; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->BluesP->next=(struct blues_struct *)ldummy; } /* The CharStrings-dictionary: Every namepointer and its corresponding charstring has to be shifted: */ i=pFontBase->pFontArray[FontID].pType1Data->CharStringsP[0].key.len; for (j=1; j<=i; j++){ ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->CharStringsP[j].value.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->CharStringsP[j].value.data.valueP=(char *)ldummy; ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->CharStringsP[j].key.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->CharStringsP[j].key.data.valueP=(char *)ldummy; } /* The Subroutines have also to be reorganized: */ i=pFontBase->pFontArray[FontID].pType1Data->Subrs.len; /* First, shift pointer to array-start and after that the pointers to each command string: */ ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Subrs.data.arrayP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->Subrs.data.arrayP=(struct ps_obj *)ldummy; for (j=0; j<i; j++) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Subrs.data.arrayP[j].data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->Subrs.data.arrayP[j].data.valueP=(char *)ldummy; } } /* end of if( vm_base > tmp_ptr ) */ else{ /* VM addess has not changed during reallocation */ sprintf( err_warn_msg_buf, "Old VM and new VM at 0x%lX, no pointer-shifting", (unsigned long)vm_base); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); }#endif /* Generate a message how much VM the current font consumes */ sprintf( err_warn_msg_buf, "VM for Font %d: %d bytes", FontID, (int) tmp_size); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_STATISTIC); /* Set the matrix for common transformations to "no transformations" */ pFontBase->pFontArray[FontID].FontTransform[0]=1.0; pFontBase->pFontArray[FontID].FontTransform[1]=0.0; pFontBase->pFontArray[FontID].FontTransform[2]=0.0; pFontBase->pFontArray[FontID].FontTransform[3]=1.0; /* Now, that the font has been loaded into memory, try to find the FontMatrix in the font info dictionary. If it exists, load it into our local fontmatrix, otherwise use a default matrix which scales to 1/1000 (since font outlines are defined in a 1000 point space) and does no further transformations. */ if (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[FONTMATRIX].value.data.arrayP == NULL){ pFontBase->pFontArray[FontID].FontMatrix[0]=0.001; pFontBase->pFontArray[FontID].FontMatrix[1]=0.0; pFontBase->pFontArray[FontID].FontMatrix[2]=0.0; pFontBase->pFontArray[FontID].FontMatrix[3]=0.001; } else{ pFontBase->pFontArray[FontID].FontMatrix[0]= (double)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[FONTMATRIX].value.data.arrayP[0].data.real; pFontBase->pFontArray[FontID].FontMatrix[1]= (double)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[FONTMATRIX].value.data.arrayP[1].data.real; pFontBase->pFontArray[FontID].FontMatrix[2]= (double)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[FONTMATRIX].value.data.arrayP[2].data.real; pFontBase->pFontArray[FontID].FontMatrix[3]= (double)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[FONTMATRIX].value.data.arrayP[3].data.real; } /* Set the default values for transformation: */ pFontBase->pFontArray[FontID].slant=0.0; pFontBase->pFontArray[FontID].extend=1.0; /* Now try to load afm-structures from corresponding .afm-file (if not suppressed by the user). */ if ((pFontBase->t1lib_flags & T1_NO_AFM)!=0) { pFontBase->pFontArray[FontID].pAFMData = NULL; T1_PrintLog( "T1_LoadFont()", "Suppressing AFM data handling on user request", T1LOG_STATISTIC); } else { if ((i=openFontMetricsFile( FontID, 0))){ /* Try a fallback, opening sloppy: */ if ((i=openFontMetricsFile( FontID, 1))) { sprintf( err_warn_msg_buf, "Alert: Error (%d) sloppy-processing afm-file for Font %d!", i ,FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_STATISTIC); if ((pFontBase->pFontArray[FontID].pAFMData= T1_GenerateAFMFallbackInfo(FontID))==NULL){ sprintf( err_warn_msg_buf, "Ultimately failed to generate metrics information Font %d!", FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_WARNING); } else { pFontBase->pFontArray[FontID].info_flags |=AFM_SELFGEN_SUCCESS; T1_PrintLog( "T1_LoadFont()", "Generating AFM-information from fontfile successful!", T1LOG_STATISTIC); } } else { pFontBase->pFontArray[FontID].info_flags |=AFM_SLOPPY_SUCCESS; sprintf( err_warn_msg_buf, "Alert: Limited afm-information for Font %d",FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_STATISTIC); } } else { pFontBase->pFontArray[FontID].info_flags |=AFM_SUCCESS; } } /* Now, set Encodingvector entry to default if the font's internal encoding is "StandardEncoding". */ if (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[ENCODING].value.data.arrayP == StdEncArrayP) { pFontBase->pFontArray[FontID].info_flags |=USES_STANDARD_ENCODING; pFontBase->pFontArray[FontID].pFontEnc=pFontBase->default_enc; sprintf( err_warn_msg_buf, "Font %d reencoded to default",FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); } else { sprintf( err_warn_msg_buf, "Font %d not reencoded to default",FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); pFontBase->pFontArray[FontID].pFontEnc = NULL; } /* If AFM-Info available we try to speed up some things: */ if (pFontBase->pFontArray[FontID].pAFMData != NULL) { /* We have to fill the array that maps the current encodings' indices to the indices used in afm file. The interpretation has been changed in in t1lib-1.2. We now use positive values for indexing into the charmetrics array and negative values for indexing into the composite character array. an index of zero indicates that no metrics are defined for this character. This may happen because (a) not all AFM-files define metrics for the .notdef character, and (b) because font and AFM-file do not match. */ if ((pFontBase->pFontArray[FontID].pEncMap= (int *)calloc(256,sizeof(int)))==NULL) { sprintf( err_warn_msg_buf, "Error allocating memory for encoding map (FontID=%d)", FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_WARNING); T1_errno=T1ERR_ALLOC_MEM; return(-1); } for (i=0; i<256; i++) { charname=T1_GetCharName( FontID, i); /* in a first loop check for ordinary characters */ for ( j=0; j<pFontBase->pFontArray[FontID].pAFMData->numOfChars; j++) { if (strcmp( charname, pFontBase->pFontArray[FontID].pAFMData->cmi[j].name)==0) { pFontBase->pFontArray[FontID].pEncMap[i]=j+1; /* index 0 is reserved! */ continue; } } /* if nothing has been found, check for composite characters */ for ( j=0; j<pFontBase->pFontArray[FontID].pAFMData->numOfComps; j++) { if (strcmp( charname, pFontBase->pFontArray[FontID].pAFMData->ccd[j].ccName)==0) { pFontBase->pFontArray[FontID].pEncMap[i]=-(j+1); /* index 0 is reserved! */ continue; } } } /* For composite characters, we still have to compute the width and bbox */ for ( j=0; j<pFontBase->pFontArray[FontID].pAFMData->numOfComps; j++) { /*and bounding box by ourselves. First, set up an identity charspace matrix and then generate an edgelist for the composite character at size 1000bp using no transformation and current encoding. Note: This action is only required when loading a font at first time, but not when reencoding a font. */ S=(struct XYspace *)IDENTITY; S=(struct XYspace *)Permanent (Transform(S, pFontBase->pFontArray[FontID].FontTransform[0], pFontBase->pFontArray[FontID].FontTransform[1], pFontBase->pFontArray[FontID].FontTransform[2], pFontBase->pFontArray[FontID].FontTransform[3])); area=fontfcnB_ByName( FontID, 0, S, pFontBase->pFontArray[FontID].pAFMData->ccd[j].ccName, &mode, pFontBase->pFontArray[FontID].pType1Data, DO_RASTER); /* Store bounding box ... */ pFontBase->pFontArray[FontID].pAFMData->ccd[j].charBBox.llx=area->xmin; pFontBase->pFontArray[FontID].pAFMData->ccd[j].charBBox.urx=area->xmax; pFontBase->pFontArray[FontID].pAFMData->ccd[j].charBBox.lly=area->ymin; pFontBase->pFontArray[FontID].pAFMData->ccd[j].charBBox.ury=area->ymax; /* ... and character width. This should be the width of the base character of the composite! */ pFontBase->pFontArray[FontID].pAFMData->ccd[j].wx=NEARESTPEL(area->ending.x); /* clean up. */ KillRegion (area); if (S!=NULL) { KillSpace (S); S=NULL; } } /* We now create an encoding-specific kerning table which will speed up looking for kerning pairs! */ /* First, get number of defined kerning pairs: */ k=pFontBase->pFontArray[FontID].pAFMData->numOfPairs; if (k>0){ /* i.e., there are any pairs */ /* OK, it does not suffice to alloc numOfPairs METRICS_ENTRYs, because a given character might be encoded at several locations and kerning should still work. As a worst case estimation, we allocate 256^2 and realloc later. */ if ((pFontBase->pFontArray[FontID].pKernMap= (METRICS_ENTRY *)malloc( (256*256) *sizeof( METRICS_ENTRY)))==NULL){ sprintf( err_warn_msg_buf, "Error allocating memory for metrics map (FontID=%d)", FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_WARNING); T1_errno=T1ERR_ALLOC_MEM; return(-1); } kern_tbl=pFontBase->pFontArray[FontID].pKernMap; pkd=pFontBase->pFontArray[FontID].pAFMData->pkd; j=0; for ( i=0; i<k; i++) { /* We do not check T1_GetEncodingIndices() against the return value NULL because we just loading the font in question: */ l=0; while ((char1=(T1_GetEncodingIndices( FontID, pkd[i].name1))[l++])!=-1) { /* pair could be relevant in current encoding */ m=0; while ((char2=(T1_GetEncodingIndices( FontID, pkd[i].name2))[m++])!=-1) { /* Since we get here we have a relevant pair --> Put char1 in higher byte and char2 in LSB: */ kern_tbl[j].chars=(char1 << 8) | char2; /* We only make use of horizontal kerning */ kern_tbl[j].hkern=pkd[i].xamt; j++; } /* while (char2) */ } /* while (char1) */ } /* for */ /* We are done, realloc memory: */ kern_tbl=(METRICS_ENTRY*) realloc( kern_tbl, j*sizeof(METRICS_ENTRY)); /* We now sort the kerning array with respect to char indices */ qsort( kern_tbl, (size_t) j, sizeof(METRICS_ENTRY), &cmp_METRICS_ENTRY ); /* Finally write back pointer for the case that realloc changed the pointer */ pFontBase->pFontArray[FontID].pKernMap=kern_tbl; pFontBase->pFontArray[FontID].KernMapSize=j; } else pFontBase->pFontArray[FontID].pKernMap=NULL; } else { /* no AFM data */ pFontBase->pFontArray[FontID].pKernMap=NULL; pFontBase->pFontArray[FontID].pEncMap=NULL; } /* End of "if (AFM-info ..)" */ /* We have just loaded a physical font into memory, thus .... */ pFontBase->pFontArray[FontID].physical=1; /* Set reference-counter to 1: */ pFontBase->pFontArray[FontID].refcount=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -