📄 t1base.c
字号:
Return value -1: invalid FontID specified -2: source font is not a "physical" font -3: no memory for reallocation of FONTPRIVATEs -4: no memory for one of the mapping tables */int T1_CopyFont( int FontID){ FONTPRIVATE *save_ptr; int k; int new_ID; /* Check for a valid source font */ if (CheckForFontID(FontID)!=1){ T1_errno=T1ERR_INVALID_FONTID; return(-1); } /* Check if the font in question is a "physical" font, otherwise it may not be copied */ if (pFontBase->pFontArray[FontID].physical==0){ T1_errno=T1ERR_OP_NOT_PERMITTED; return(-2); } /* Check if free space for a new FONTPRIVATE is available; if not, realloc memory some amount larger */ save_ptr=pFontBase->pFontArray; if (pFontBase->no_fonts==pFontBase->no_fonts_limit){ pFontBase->pFontArray=(FONTPRIVATE *)realloc(pFontBase->pFontArray, (pFontBase->no_fonts_limit + ADVANCE_FONTPRIVATE) * sizeof(FONTPRIVATE)); if (pFontBase->pFontArray==NULL){ /* Restore pointer */ pFontBase->pFontArray=save_ptr; T1_errno=T1ERR_ALLOC_MEM; return(-3); } /* We zero the newly allocated memory */ if (pFontBase->pFontArray != NULL) { memset( pFontBase->pFontArray + pFontBase->no_fonts_limit, 0, ADVANCE_FONTPRIVATE * sizeof(FONTPRIVATE)); } pFontBase->no_fonts_limit += ADVANCE_FONTPRIVATE; } /* no_fonts-1 was the largest allowed font ID */ new_ID=pFontBase->no_fonts; /* Copy FONTPRIVATE-structure: */ pFontBase->pFontArray[new_ID]=pFontBase->pFontArray[FontID]; /* (Re)Set some values explicitly, others remain untouched: */ pFontBase->pFontArray[new_ID].pFontSizeDeps=NULL; pFontBase->pFontArray[new_ID].physical=0; /* AFM-mapping tables are to be setup for logical fonts separately (if AFM data is there) */ /* first, kerning map */ if (pFontBase->pFontArray[new_ID].pAFMData) { k=pFontBase->pFontArray[new_ID].pAFMData->numOfPairs; if (k>0){ /* kern map exists only if kerning pairs exist! */ if ((pFontBase->pFontArray[new_ID].pKernMap= (METRICS_ENTRY *)malloc( k*sizeof( METRICS_ENTRY)))==NULL){ sprintf( err_warn_msg_buf, "Error allocating memory for kerning map (new_ID=%d)", new_ID); T1_PrintLog( "T1_CopyFont()", err_warn_msg_buf, T1LOG_WARNING); T1_errno=T1ERR_ALLOC_MEM; return(-4); } memcpy( pFontBase->pFontArray[new_ID].pKernMap, pFontBase->pFontArray[FontID].pKernMap, k*sizeof( METRICS_ENTRY)); } else { /* no kerning pairs, bu AFM data present */ pFontBase->pFontArray[new_ID].pKernMap=NULL; } } else { /* AFM data not present at all */ pFontBase->pFontArray[new_ID].pKernMap=NULL; } /* second, encoding map */ if (pFontBase->pFontArray[FontID].pEncMap!=NULL) { if ((pFontBase->pFontArray[new_ID].pEncMap= (int *)calloc(256,sizeof(int)))==NULL){ sprintf( err_warn_msg_buf, "Error allocating memory for encoding map (new_ID=%d)", new_ID); T1_PrintLog( "T1_CopyFont()", err_warn_msg_buf, T1LOG_WARNING); T1_errno=T1ERR_ALLOC_MEM; return(-4); } memcpy( pFontBase->pFontArray[new_ID].pEncMap, pFontBase->pFontArray[FontID].pEncMap, 256*sizeof( int)); } /* New font is logical --> indicate to which physical font it refers by setting refcount: */ pFontBase->pFontArray[new_ID].refcount=FontID; /* Now the struct is setup; increment no_fonts by 1 because new_ID is a valid font specification from now on. */ pFontBase->no_fonts++; /* Increment refcount in source font */ pFontBase->pFontArray[FontID].refcount++; /* Generate logfile entry */ sprintf( err_warn_msg_buf, "Assigned FontID %d to fontfile %s", new_ID, FontBase.pFontArray[new_ID].pFontFileName); T1_PrintLog( "T1_CopyFont()", err_warn_msg_buf, T1LOG_STATISTIC); return(new_ID);}/* T1_SetBitmapPad(): Set the value to which bitmap-scanlines are padded. This has to be done before initialization because it is a very rudimentary operation. */int T1_SetBitmapPad( int pad){ if (T1_Up){ /* Library is initialized --> return error */ T1_errno=T1ERR_OP_NOT_PERMITTED; return(-1); } else{ switch (pad){ case 8: T1_pad=8; return(0); case 16: T1_pad=16; return(0);#ifdef T1_AA_TYPE64 case 32: T1_pad=32; return(0);#endif default: T1_errno=T1ERR_INVALID_PARAMETER; return(-1); } }}/* T1_GetBitmapPad(): Read the value to which scanlines of bitmap are padded. This can be done before or after initialization. */int T1_GetBitmapPad( void){ if (pFontBase) /* T1lib initialized --> return value from struct */ return( pFontBase->bitmap_pad); else{ if (T1_pad) return(T1_pad); /* pad is explicitly set --> return that value */ else return( T1GLYPH_PAD); /* not expl. set --> return compilation default */ }}/* bin_dump(): Print a binary dump of a byte, short and long variable (used for debug purposes only): */void bin_dump_c(unsigned char value, char space_flag){ int i,j; for (i=0;i<=7;i++){ if ((j=((value)>>i)&0x01)) printf("X"); else printf("."); } if (space_flag) printf(" ");}void bin_dump_s(unsigned short value, char space_flag){ int i,j; if (T1_CheckEndian()){ for (i=8;i<=15;i++){ if ((j=((value)>>i)&0x01)) printf("X"); else printf("."); } for (i=0;i<=7;i++){ if ((j=((value)>>i)&0x01)) printf("X"); else printf("."); } } else{ for (i=0;i<=15;i++){ if ((j=((value)>>i)&0x01)) printf("X"); else printf("."); } } if (space_flag) printf(" "); }void bin_dump_l(unsigned long value, char space_flag){ int i,j; if (T1_CheckEndian()){ for (i=24;i<=31;i++){ if ((j=((value)>>i)&0x01)) printf("X"); else printf("."); } for (i=16;i<=23;i++){ if ((j=((value)>>i)&0x01)) printf("X"); else printf("."); } for (i=8;i<=15;i++){ if ((j=((value)>>i)&0x01)) printf("X"); else printf("."); } for (i=0;i<=7;i++){ if ((j=((value)>>i)&0x01)) printf("X"); else printf("."); } } else{ for (i=0;i<=31;i++){ if ((j=((value)>>i)&0x01)) printf("X"); else printf("."); } } if (space_flag) printf(" ");}/* CheckEndian(): Checks whether the current machine is of little or big endian architecture. This is important for concatenating bitmaps. Function returns 0 if LittleEndian and 1 if BigEndian representation is used on the current hardware. */int T1_CheckEndian(){ unsigned char *charptr; /* Generate test value */ unsigned short test=0x0001; /* Read out memory as unsigned char */ charptr=(unsigned char *)(&test)+1; /* Return value will be 1 if Big- and 0 if Little Endian */ return((int) *charptr); }/* T1_GetLibIdent(): Return the identifier string for the current version of t1lib */char *T1_GetLibIdent( void){ static char buf[15]; sprintf( buf, "%s", T1LIB_IDENT); return( (char *)buf);}/* T1_SetRasterFlags(): Enable/Disable certain features in the rasterizer */extern void T1_SetRasterFlags( int flags){ T1_Type1OperatorFlags=flags; return; }/* T1_GetFontFileName(): returns a pointer to the complete path filename of the font, associated with FontID as it is in use by t1lib. */char *T1_GetFontFilePath( int FontID){ static char filepath[MAXPATHLEN+1]; char *FileNamePath=NULL; /* is initialzed? */ if (CheckForInit()) { T1_errno=T1ERR_INVALID_FONTID; return(NULL); } /* Check first for valid FontID */ if ((FontID<0) || (FontID>FontBase.no_fonts)){ T1_errno=T1ERR_INVALID_FONTID; return(NULL); } /* lib is initialized and FontID is valid -> we can really expect a name */ if ((FileNamePath=intT1_Env_GetCompletePath( pFontBase->pFontArray[FontID].pFontFileName, T1_PFAB_ptr))==NULL) { T1_PrintLog( "T1_GetFontFilePath()", "Couldn't locate font file for font %d in %s", T1LOG_WARNING, FontID, T1_GetFileSearchPath(T1_PFAB_PATH)); T1_errno=T1ERR_FILE_OPEN_ERR; return(NULL); } strcpy( filepath, FileNamePath); free( FileNamePath); return( filepath); }/* We have a function for querying the name. Returns a pointer to the string or NULL if name was not explicitly set .*/char *T1_GetAfmFilePath( int FontID){ static char filepath[MAXPATHLEN+1]; char *FontFileName; char *AFMFilePath; int i, j; /* is initialized? */ if ((CheckForInit())) { T1_errno=T1ERR_INVALID_FONTID; return(NULL); } /* Check first for valid FontID */ if ((FontID<0) || (FontID>FontBase.no_fonts)){ T1_errno=T1ERR_INVALID_FONTID; return(NULL); } /* Check wether AFM-file loading was suppressed on user's request */ if ((pFontBase->t1lib_flags & T1_NO_AFM)!=0) { /* this is no error condition, we simply return (NULL) */ return( NULL); } /* Check for explicitly associated metrics filename (via "T1_SetAfmFileName()"). If it exists, we return it! */ if (pFontBase->pFontArray[FontID].pAfmFileName!=NULL) { strcpy( filepath, pFontBase->pFontArray[FontID].pAfmFileName); sprintf( err_warn_msg_buf, "Returning explicitly specified path %s for Font %d", filepath, FontID); T1_PrintLog( "T1_GetAfmFilePath()", err_warn_msg_buf, T1LOG_DEBUG); return( filepath); } /* we have the usual case that the name of the metrics file has to be deduced from the font file name */ FontFileName=T1_GetFontFileName( FontID); i=strlen(FontFileName); j=i; strcpy( filepath, FontFileName); while ( filepath[i] != '.'){ if (i==0) break; else i--; } if (i==0){ /* We have a filename without extension -> append extension */ filepath[j]='.'; filepath[j+1]='a'; filepath[j+2]='f'; filepath[j+3]='m'; filepath[j+4]='\0'; } else{ /* we found a '.' -> replace extension */ filepath[i+1]='a'; filepath[i+2]='f'; filepath[i+3]='m'; filepath[i+4]='\0'; } /* Get full path of the afm file (The case of a full path name name specification is valid */ AFMFilePath=intT1_Env_GetCompletePath( filepath, T1_AFM_ptr); strcpy( filepath, AFMFilePath); free( AFMFilePath); return( filepath); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -