📄 t1load.c
字号:
/* Get the index into encoding vector where the space character is found. If not encoded, set space_position to -1. */ pFontBase->pFontArray[FontID].space_position=-1; i=0; if (pFontBase->pFontArray[FontID].pFontEnc) { /* external default encoding */ while (i<256) { if (strcmp( (char *)pFontBase->pFontArray[FontID].pFontEnc[i], "space")==0){ /* space found at position i: */ pFontBase->pFontArray[FontID].space_position=i; break; } i++; } } else { /* internal encoding */ while (i<256) { if (strcmp( (char *)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[ENCODING].value.data.arrayP[i].data.arrayP, "space")==0){ /* space found at position i: */ pFontBase->pFontArray[FontID].space_position=i; break; } i++; } } /* Set the lining rule parameters to default values */ pFontBase->pFontArray[FontID].UndrLnPos= pFontBase->pFontArray[FontID].pType1Data->fontInfoP[UNDERLINEPOSITION].value.data.real; pFontBase->pFontArray[FontID].UndrLnThick= pFontBase->pFontArray[FontID].pType1Data->fontInfoP[UNDERLINETHICKNESS].value.data.real; /* We have to set the value for the typographic ascender. If possible, we get it from the afm-File. But be aware this value might be undefined! This value should in any acse explicitly be set later by the user! */ if (pFontBase->pFontArray[FontID].pAFMData!=NULL && pFontBase->pFontArray[FontID].pAFMData->gfi!=NULL) { ascender=(float) pFontBase->pFontArray[FontID].pAFMData->gfi->ascender; } else { ascender=(float) T1_GetCharBBox( FontID, T1_GetEncodingIndex( FontID, "d")).ury; } pFontBase->pFontArray[FontID].OvrLnPos=ascender + (float) abs( (double)pFontBase->pFontArray[FontID].UndrLnPos); pFontBase->pFontArray[FontID].OvrStrkPos=ascender / 2.0; pFontBase->pFontArray[FontID].OvrLnThick=pFontBase->pFontArray[FontID].UndrLnThick; pFontBase->pFontArray[FontID].OvrStrkThick=pFontBase->pFontArray[FontID].UndrLnThick; /* Finally, set the font size dependencies pointer to NULL since we can assume, that at load time of a font, no size specific data of this font is available. */ pFontBase->pFontArray[FontID].pFontSizeDeps=NULL; /* If wanted, some debugging information is put into logfile */ sprintf( err_warn_msg_buf, "Pointer vm_base: 0x%lX", (long)pFontBase->pFontArray[FontID].vm_base); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); sprintf( err_warn_msg_buf, "Pointer vm_start: 0x%lX", (long)pFontBase->pFontArray[FontID].pType1Data->vm_start); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); sprintf( err_warn_msg_buf, "Pointer CharStringsP: 0x%lX", (long)pFontBase->pFontArray[FontID].pType1Data->CharStringsP); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); sprintf( err_warn_msg_buf, "Pointer Private: 0x%lX", (long)pFontBase->pFontArray[FontID].pType1Data->Private); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); sprintf( err_warn_msg_buf, "Pointer fontInfoP: 0x%lX", (long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); return(0);} /* openFontMetricsFile( FontID, open_sloppy): Gets the fontfilename corresponding to FontID, opens the corresponding afm-file and fills the data structures. return-value is the value returned by the T1lib_parseFile() function. If open_sloppy is set, the minimum information needed is read from AFM file. This can be considered a fallback for problematic AFM files. */static int openFontMetricsFile( int FontID, int open_sloppy){ char *FontFileName; char *AFMFileName; char *afm_name; char *AFMFileNamePath; int i, j; FILE *metricsfile; afm_name=T1_GetAfmFileName(FontID); if (afm_name!=NULL) { /* We have name explicitly specified */ /* It needs to be freeable */ if ((AFMFileName= (char *)malloc( (strlen(afm_name)+1)*sizeof( char)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return( -6); } strcpy( AFMFileName, afm_name); } else { FontFileName=T1_GetFontFileName( FontID); i=strlen(FontFileName); j=i; AFMFileName=(char *)malloc( i+5); strcpy( AFMFileName, FontFileName); while ( AFMFileName[i] != '.'){ if (i==0) break; else i--; } if (i==0){ /* We have a filename without extension -> append extension */ AFMFileName[j]='.'; AFMFileName[j+1]='a'; AFMFileName[j+2]='f'; AFMFileName[j+3]='m'; AFMFileName[j+4]='\0'; } else{ /* we found a '.' -> replace extension */ AFMFileName[i+1]='a'; AFMFileName[i+2]='f'; AFMFileName[i+3]='m'; AFMFileName[i+4]='\0'; } } /* Get full path of the afm file (The case of a full path name name specification is valid */ AFMFileNamePath=intT1_Env_GetCompletePath( AFMFileName, T1_AFM_ptr); free( AFMFileName); /* open afm-file: */ if (AFMFileNamePath!=NULL){ if ((metricsfile=fopen(AFMFileNamePath,"r"))==NULL){ free(AFMFileNamePath); return(-4); } else { free(AFMFileNamePath); } } else{ return( -5); } /* Call procedure to read afm-file and store the data formatted. Flags used here: P_M All Metrics Information P_P Pair Kerning Information P_C Composite Character Data (since t1lib V.1.2) The P_G flag to get global font information should not be used if not absolutely needed. When parsing an unknown keyword, which may be harmless, the T1lib_parseFile function returns the error code -1 (parseError). On the other hand, all other really relevant data may habe been parsed and stored correctly. In such a case, There's no way to make a serious decision whether an error has occured or not. */ if (open_sloppy!=0) i=T1lib_parseFile( (FILE *) metricsfile, (FontInfo **) &(FontBase.pFontArray[FontID].pAFMData), P_M ); else i=T1lib_parseFile( (FILE *) metricsfile, (FontInfo **) &(FontBase.pFontArray[FontID].pAFMData), P_G | P_M | P_P | P_C ); fclose(metricsfile); return(i);}/* CreateNewFontSize( FontID, size): Create a new size "size" of font "FontID" and allocate all data necessary for this. The data structure is connected to the linked list of FontSizeDeps for this font. Returns a pointer to the newly created FontSizeDeps-struct if all went correct and NULL otherwise. Since of version 0.3 a member antialias has been added to the FONTSIZEDEPS structure! This can be: 0: bitmaps are stored in this struct 1: non-antialiased bytemaps are stored in this struct 2: low-antialiased bytemaps are stored in this struct 4: high-antialiased bytemaps are stored in this struct */FONTSIZEDEPS *CreateNewFontSize( int FontID, float size, int aa){ FONTSIZEDEPS *pFontSizeDeps, *pPrev; /* First, get to the last font size in the linked list for this font. The following routine returns the address of the last struct in the linked list of FONTSIZEDEPS or NULL if none exists. */ pFontSizeDeps=GetLastFontSize( FontID); pPrev=pFontSizeDeps; if (pFontSizeDeps==NULL){ /* Allocate memory for first FontSizeDeps-structure: */ if ((pFontBase->pFontArray[FontID].pFontSizeDeps=(FONTSIZEDEPS *)malloc(sizeof(FONTSIZEDEPS)))==NULL){ T1_errno=T1ERR_ALLOC_MEM; return(NULL); } pFontSizeDeps=pFontBase->pFontArray[FontID].pFontSizeDeps; } else{ /* A valid address of an existing structure was found */ if ((pFontSizeDeps->pNextFontSizeDeps=(FONTSIZEDEPS *)malloc(sizeof(FONTSIZEDEPS)))==NULL){ T1_errno=T1ERR_ALLOC_MEM; return(NULL); } pFontSizeDeps=pFontSizeDeps->pNextFontSizeDeps; } /* The pointer to the previous struct */ pFontSizeDeps->pPrevFontSizeDeps=pPrev; /* Put the size into this structure */ pFontSizeDeps->size=size; /* Set the antialias mark: */ pFontSizeDeps->antialias=aa; /* Just the current becomes now the last item in the linked list: */ pFontSizeDeps->pNextFontSizeDeps=NULL; /* Setup CharSpaceMatrix for this font: */ pFontSizeDeps->pCharSpaceLocal=(struct XYspace *) IDENTITY; /* Apply transformation with font matrix: */ pFontSizeDeps->pCharSpaceLocal=(struct XYspace *) Transform(pFontSizeDeps->pCharSpaceLocal, pFontBase->pFontArray[FontID].FontMatrix[0], pFontBase->pFontArray[FontID].FontMatrix[1], pFontBase->pFontArray[FontID].FontMatrix[2], pFontBase->pFontArray[FontID].FontMatrix[3]); /* Apply a further transformation (optionally): */ pFontSizeDeps->pCharSpaceLocal=(struct XYspace *) Transform(pFontSizeDeps->pCharSpaceLocal, pFontBase->pFontArray[FontID].FontTransform[0], pFontBase->pFontArray[FontID].FontTransform[1], pFontBase->pFontArray[FontID].FontTransform[2], pFontBase->pFontArray[FontID].FontTransform[3]); /* Apply desired scaling factor, and make it Permanent */ pFontSizeDeps->pCharSpaceLocal=(struct XYspace *) Permanent (Scale(pFontSizeDeps->pCharSpaceLocal, size, size)); /* We should now allocate memory for the glyph area of the font cache: */ if ((pFontSizeDeps->pFontCache=(GLYPH *)calloc(256,sizeof(GLYPH))) ==NULL) return(NULL); sprintf( err_warn_msg_buf, "New Size %f created for FontID %d (antialias=%d)", pFontSizeDeps->size, FontID, pFontSizeDeps->antialias); T1_PrintLog( "CreateNewFontSize()", err_warn_msg_buf, T1LOG_STATISTIC); /* We are done */ return(pFontSizeDeps); } /* QueryFontSize( FontID, size, aa): Search if a requested size of font FontID is already existing. If so, it returns a pointer to the respective FontSizeDeps-structure, otherwise NULL is returned: */FONTSIZEDEPS *QueryFontSize( int FontID, float size, int aa){ FONTSIZEDEPS *link_ptr; /* There's not yet one size: */ if (pFontBase->pFontArray[FontID].pFontSizeDeps == NULL) return(pFontBase->pFontArray[FontID].pFontSizeDeps); /* There's already existing one or more size */ link_ptr=pFontBase->pFontArray[FontID].pFontSizeDeps; while (((link_ptr->size != size)||(link_ptr->antialias != aa)) &&(link_ptr->pNextFontSizeDeps != NULL)) link_ptr=link_ptr->pNextFontSizeDeps; if ((link_ptr->size != size)||(link_ptr->antialias != aa)) return( NULL); /* requested size/aa-combination was not found */ else return(link_ptr); /* return pointer to requested struct */ }/* FONTSIZEDEPS *GetLastFontSize( FontID): Get the address of the last struct in the linked list of FontSizeDeps or NULL if there is no existing size dependent data. */FONTSIZEDEPS *GetLastFontSize( int FontID){ FONTSIZEDEPS *link_ptr, *result_ptr; /* There's not yet one size: */ if (pFontBase->pFontArray[FontID].pFontSizeDeps == NULL) return((FONTSIZEDEPS *) (pFontBase->pFontArray[FontID].pFontSizeDeps)); /* There's already existing one or more size */ link_ptr=pFontBase->pFontArray[FontID].pFontSizeDeps; while (link_ptr != NULL){ result_ptr=link_ptr; link_ptr=link_ptr->pNextFontSizeDeps; } return((FONTSIZEDEPS *)(result_ptr));}/* A function for comparing METRICS_ENTRY structs */static int cmp_METRICS_ENTRY( const void *entry1, const void *entry2){ if (((METRICS_ENTRY *)entry1)->chars < ((METRICS_ENTRY *)entry2)->chars) return(-1); if (((METRICS_ENTRY *)entry1)->chars > ((METRICS_ENTRY *)entry2)->chars) return(1); return(0); /* This should not happen */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -