📄 t1env.c
字号:
FileName); T1_PrintLog( "intT1_Env_GetCompletePath()", err_warn_msg_buf, T1LOG_DEBUG); } /* Trying to locate absolute path spec. failed. We try to recover by removing the path component and searching in the remaining search path entries. This depends on the OS. */ i=fnamelen-1; StrippedName=&(FileName[i]); while ( FileName[i]!=DIRECTORY_SEP_CHAR#if defined(VMS) /* What exactly to do for VMS? */#elif defined(MSDOS) | defined(_WIN32) | defined (__EMX__) | defined(_MSC_VER) /* We take a drive specification into account. This means we step back until the directory separator or a drive specifier appears! */ && FileName[i]!=':'#endif ) { i--; } i++; StrippedName=&FileName[i]; if (t1lib_log_file!=NULL){ sprintf( err_warn_msg_buf, "path %s stripped to %s", FileName, StrippedName); T1_PrintLog( "intT1_Env_GetCompletePath()", err_warn_msg_buf, T1LOG_DEBUG); } } else{ /* We have a relative path name */ StrippedName=&FileName[0]; } i=0; while (env_ptr[i]!=NULL) { /* Copy current path element: */ strcpy( pathbuf, env_ptr[i]); /* cut a trailing directory separator */ j=strlen(pathbuf); if (pathbuf[j-1]==DIRECTORY_SEP_CHAR) pathbuf[j--]='\0'; /* Add the directory separator: */#ifdef VMS { char *p= strrchr(FullPathName, DIRECTORY_SEP_CHAR); if (p && *(p+1) == '\0') *p = '\0'; } #endif strcat( pathbuf, DIRECTORY_SEP); /* And finally the filename: */ strcat( pathbuf, StrippedName); /* Check for existence of the path: */ if (!stat( pathbuf, &filestats)) { if ((FullPathName=(char*)malloc( (j+fnamelen+2)*sizeof(char)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(NULL); } strcpy( FullPathName, pathbuf); if (t1lib_log_file!=NULL){ sprintf( err_warn_msg_buf, "stat()'ing %s successful", FullPathName); T1_PrintLog( "intT1_Env_GetCompletePath()", err_warn_msg_buf, T1LOG_DEBUG); } return(FullPathName); } if (t1lib_log_file!=NULL){ sprintf( err_warn_msg_buf, "stat()'ing %s failed", pathbuf); T1_PrintLog( "intT1_Env_GetCompletePath()", err_warn_msg_buf, T1LOG_DEBUG); } /* We didn't find the file --> try next path entry */ i++; } /* If we get here, no file was found at all, so return a NULL-pointer */ return(NULL);}/* T1_SetFileSearchPath(): Set the search path to find files of the specified type and return 0 if successful and -1 otherwise. An existing path is overwritten rigorously, unless the database already contains fonts. In the latter case the function returns with an error status. Multiple path types may be specified as a bitmask!*/int T1_SetFileSearchPath( int type, char *pathname){ int i; int pathlen; if (pathname==NULL){ T1_errno=T1ERR_INVALID_PARAMETER; return(-1); } /* We do not allow to change the searchpath if the database already contains one or more entries. */ if (T1_Get_no_fonts()>0){ sprintf( err_warn_msg_buf, "Path %s not set, database is not empty", pathname); T1_PrintLog( "T1_SetFileSearchPath()", err_warn_msg_buf, T1LOG_STATISTIC); T1_errno=T1ERR_OP_NOT_PERMITTED; return(-1); } pathlen=strlen(pathname)+1; /* Throw away a possibly existing path */ if (type & T1_PFAB_PATH){ if (pfab_no==-1) { T1_PFAB_ptr=NULL; /* realloc() will do a malloc() */ } else { /* throw away current paths */ i=0; while (T1_PFAB_ptr[i]!=NULL) { free (T1_PFAB_ptr[i++]); } } if ((T1_PFAB_ptr=(char**)realloc( T1_PFAB_ptr, 2*sizeof(char*)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } if ((T1_PFAB_ptr[0]=(char*)malloc(pathlen*sizeof(char)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } strcpy( T1_PFAB_ptr[0], pathname); T1_PFAB_ptr[1]=NULL; pfab_no=1; } if (type & T1_AFM_PATH){ if (afm_no==-1) { T1_AFM_ptr=NULL; /* realloc() will do a malloc() */ } else { /* throw away current paths */ i=0; while (T1_AFM_ptr[i]!=NULL) { free (T1_AFM_ptr[i++]); } } if ((T1_AFM_ptr=(char**)realloc( T1_AFM_ptr, 2*sizeof(char*)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } if ((T1_AFM_ptr[0]=(char*)malloc(pathlen*sizeof(char)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } strcpy( T1_AFM_ptr[0], pathname); T1_AFM_ptr[1]=NULL; afm_no=1; } if (type & T1_ENC_PATH){ if (enc_no==-1) { T1_ENC_ptr=NULL; /* realloc() will do a malloc() */ } else { /* throw away current paths */ i=0; while (T1_ENC_ptr[i]!=NULL) { free (T1_ENC_ptr[i++]); } } if ((T1_ENC_ptr=(char**)realloc( T1_ENC_ptr, 2*sizeof(char*)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } if ((T1_ENC_ptr[0]=(char*)malloc(pathlen*sizeof(char)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } strcpy( T1_ENC_ptr[0], pathname); T1_ENC_ptr[1]=NULL; enc_no=1; } return(0); }/* T1_GetFileSearchPath(): Return the specified file search path or NULL if an error occurred. Note: We do only one path at a time, so that if a bitmask is specified, the first match wins. The returned path is formatted using the actual PATH_SEP_CHAR. */char *T1_GetFileSearchPath( int type){ static char *out_ptr; int i; int pathlen; char **src_ptr=NULL; if (out_ptr!=NULL) free( out_ptr); out_ptr=NULL; if (type & T1_PFAB_PATH) { src_ptr=T1_PFAB_ptr; } else if (type & T1_AFM_PATH) { src_ptr=T1_AFM_ptr; } else if (type & T1_ENC_PATH) { src_ptr=T1_ENC_ptr; } else if (type & T1_FDB_PATH) { src_ptr=T1_FDB_ptr; } i=0; pathlen=0; while (src_ptr[i]!=NULL) { pathlen +=strlen( src_ptr[i++]); pathlen+=1; /* path separator */ } if ((out_ptr=(char *)malloc(pathlen+1))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return( NULL); } strcpy( out_ptr, src_ptr[0]); i=1; while (src_ptr[i]!=NULL) { strcat( out_ptr, path_sep_string); strcat( out_ptr, src_ptr[i++]); } return( out_ptr);}/* T1_AddToFileSearchPath(): Add the specified path element to the specified search path. If the existing path is the default path, it will not be replaced by the new path element. Since this function might be called before initialization, we have to be aware that even the default path could be missing. Multiple path types may be specified as a bitmask! Return value is 0 if successful and -1 otherwise */int T1_AddToFileSearchPath( int pathtype, int mode, char *pathname){ int i; int pathlen; char* newpath; int nofonts; if (pathname==NULL) return(-1); nofonts=T1_Get_no_fonts(); pathlen=strlen(pathname); if (pathtype & T1_PFAB_PATH){ /* Allocate meory for string */ if ((newpath=(char*)malloc( (pathlen+1)*sizeof(char)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } /* Check for and handle the existing path configuration */ if (pfab_no==0) { /* do not free the default path but establish it as a regularly setup path, if database not empty! */ if (nofonts>0) { pfab_no++; } else { free( T1_AFM_ptr[0]); } } if (pfab_no==-1) { /* not initialized! */ pfab_no=0; T1_PFAB_ptr=NULL; /* realloc() will do the malloc()! */ } if ((T1_PFAB_ptr=(char**)realloc( T1_PFAB_ptr, (++pfab_no+1)*sizeof(char*)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } /* Insert the new path element: */ if (mode & T1_PREPEND_PATH){ /* prepend */ i=pfab_no-2; while (i>=0) { T1_PFAB_ptr[i+1]=T1_PFAB_ptr[i--]; } T1_PFAB_ptr[0]=newpath; } else{ /* append */ T1_PFAB_ptr[pfab_no-1]=newpath; } T1_PFAB_ptr[pfab_no]=NULL; } if (pathtype & T1_AFM_PATH){ /* Allocate meory for string */ if ((newpath=(char*)malloc( (pathlen+1)*sizeof(char)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } /* Check for and handle the existing path configuration */ if (afm_no==0) { /* do not free the default path but establish it as a regularly setup path, if database not empty! */ if (nofonts>0) { afm_no++; } else { free( T1_AFM_ptr[0]); } } if (afm_no==-1) { /* not initialized! */ afm_no=0; T1_AFM_ptr=NULL; /* realloc() will do the malloc()! */ } if ((T1_AFM_ptr=(char**)realloc( T1_AFM_ptr, (++afm_no+1)*sizeof(char*)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } /* Insert the new path element */ if (mode & T1_PREPEND_PATH){ /* prepend */ i=afm_no-2; while (i>=0) { T1_AFM_ptr[i+1]=T1_AFM_ptr[i--]; } T1_AFM_ptr[0]=newpath; } else{ /* append */ T1_AFM_ptr[afm_no-1]=newpath; } T1_AFM_ptr[afm_no]=NULL; } if (pathtype & T1_ENC_PATH){ /* Allocate meory for string */ if ((newpath=(char*)malloc( (pathlen+1)*sizeof(char)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } /* Check for and handle the existing path configuration */ if (enc_no==0) { /* do not free the default path but establish it as a regularly setup path, if database not empty! */ if (nofonts>0) { enc_no++; } else { free( T1_ENC_ptr[0]); } } if (enc_no==-1) { /* not initialized! */ enc_no=0; T1_ENC_ptr=NULL; /* realloc() will do the malloc()! */ } if ((T1_ENC_ptr=(char**)realloc( T1_ENC_ptr, (++enc_no+1)*sizeof(char*)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } /* Insert the new path element: */ if (mode & T1_PREPEND_PATH){ /* prepend */ i=enc_no-2; while (i>=0) { T1_ENC_ptr[i+1]=T1_ENC_ptr[i--]; } T1_ENC_ptr[0]=newpath; } else{ /* append */ T1_ENC_ptr[enc_no-1]=newpath; } T1_ENC_ptr[enc_no]=NULL; } return(0); }/* T1_SetFontDataBase(): Set a new name for the font database. It replaces the default name and any names specified previously with this function. Return value: 0 if OK, and -1 if filename not valid or an allocation error occurred */int T1_SetFontDataBase( char *filename){ int pathlen; int i; int result=0; /* chekc filename */ if (filename==NULL) { T1_errno=T1ERR_INVALID_PARAMETER; return -1; } /* this function must be called before any font is in the database, that is, usually, before initialization! */ if (pFontBase->no_fonts>0) { T1_errno=T1ERR_OP_NOT_PERMITTED; return -1; } pathlen=strlen(filename)+1; /* Throw away a possibly existing font database-statement */ if (fdb_no==-1) { T1_FDB_ptr=NULL; /* realloc() will do a malloc() */ } else { /* throw away current paths */ i=0; while (T1_FDB_ptr[i]!=NULL) { free (T1_FDB_ptr[i++]); } } if ((T1_FDB_ptr=(char**)realloc( T1_FDB_ptr, 2*sizeof(char*)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return -1; } if ((T1_FDB_ptr[0]=(char*)malloc(pathlen*sizeof(char)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return -1; } strcpy( T1_FDB_ptr[0], filename); T1_FDB_ptr[1]=NULL; fdb_no=1; /* Load database immediately if t1lib already is initailzed */ if (CheckForInit()==0) { if ((result=intT1_scanFontDBase(T1_FDB_ptr[0]))==-1) { T1_PrintLog( "T1_AddFontDataBase()", "Fatal error scanning Font Database File %s (T1_errno=%d)", T1LOG_WARNING, T1_FDB_ptr[0], T1_errno); } if (result>-1) pFontBase->no_fonts+=result; result=pFontBase->no_fonts; } return result; }/* T1_AddFontDataBase(): Add a new font database file to the list. If the lib is already initialzed, then the new database is immediately loaded. Otherwise it is simply appended to the list and loaded at the time of initialization. Returns: -1 an error occured 0 successfully inserted but not loaded because lib not initilized n>0 the highest defined FontID*/int T1_AddFontDataBase( int mode, char *filename) { int i; int pathlen; int result=0; char* newpath; if (filename==NULL) { T1_errno=T1ERR_INVALID_PARAMETER; return(-1); } pathlen=strlen(filename); /* Allocate memory for string */ if ((newpath=(char*)malloc( (pathlen+1)*sizeof(char)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } strcpy( newpath, filename); /* Check for and handle the existing path configuration */ if (fdb_no==0) { /* defauls setup, free the path */ free( T1_FDB_ptr[0]); } if (fdb_no==-1) { /* not initialized! */ fdb_no=0; T1_FDB_ptr=NULL; /* realloc() will do the malloc()! */ } if ((T1_FDB_ptr=(char**)realloc( T1_FDB_ptr, (++fdb_no+1)*sizeof(char*)))==NULL) { T1_errno=T1ERR_ALLOC_MEM; return(-1); } /* Insert the new database. If t1lib is already initialzed, the database can only be appended. Otherwise. prepending is also possible.*/ if ((mode & T1_PREPEND_PATH) && (CheckForInit()!=0) ) { /* prepend */ i=fdb_no-2; while (i>=0) { T1_FDB_ptr[i+1]=T1_FDB_ptr[i--]; } T1_FDB_ptr[0]=newpath; result=0; } else { /* append */ T1_FDB_ptr[fdb_no-1]=newpath; if (CheckForInit()==0) { if ((result=intT1_scanFontDBase(T1_FDB_ptr[fdb_no-1]))==-1) { T1_PrintLog( "T1_AddFontDataBase()", "Fatal error scanning Font Database File %s (T1_errno=%d)", T1LOG_WARNING, T1_FDB_ptr[fdb_no-1], T1_errno); } if (result>-1) pFontBase->no_fonts+=result; result=pFontBase->no_fonts; } } T1_FDB_ptr[fdb_no]=NULL; return result; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -