⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t1base.c

📁 source code: Covert TXT to PDF
💻 C
📖 第 1 页 / 共 3 页
字号:
	if (pFontBase->pFontArray[i-1].pAfmFileName!=NULL){	  free( pFontBase->pFontArray[i-1].pAfmFileName);	  pFontBase->pFontArray[i-1].pAfmFileName=NULL;	}      }            /* Now, remove font: */      if ((j=T1_DeleteFont( i-1))){	error=1;	sprintf( err_warn_msg_buf, "T1_DeleteFont() returned %d for Font %d",		 j, i-1);	T1_PrintLog( "T1_CloseLib()", err_warn_msg_buf, T1LOG_ERROR);      }    }    /* Free the FONTPRIVATE area */    if (pFontBase->pFontArray)      free( pFontBase->pFontArray);    else      error=1;    /* Free search paths */    intT1_FreeSearchPaths();    /* Reset the flags */    pFontBase->t1lib_flags=0;        /* Indicate Library is no longer initialized */    pFontBase=NULL;    T1_Up=0;    T1_PrintLog( "T1_CloseLib()", "Library closed", T1LOG_STATISTIC);    if ((t1lib_log_file!=NULL) && (t1lib_log_file!=stderr))      fclose(t1lib_log_file);    t1lib_log_file=NULL;  }    return( error);}/* T1_AddFont(): Add a new fontfile to the fontdatabase.   Return values: >0: Assigned FontID                  -1: Fontfile not found		  -2: Error allocating memory for FONTPRIVATE-area		  -3: No memory for saving font filename		  */int T1_AddFont( char *fontfilename){    char *FullName;  FONTPRIVATE *save_ptr;  int i;  int new_ID;      if (fontfilename==NULL){    T1_errno=T1ERR_INVALID_PARAMETER;    return(-1);  }    /* Check for existence of fontfile */  if ((FullName=intT1_Env_GetCompletePath(fontfilename,T1_PFAB_ptr))==NULL) {    T1_errno=T1ERR_FILE_OPEN_ERR;    return(-1);  }  free(FullName);  /* 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){    if (pFontBase->pFontArray == NULL) {      /* In case this is the first font */      pFontBase->pFontArray=(FONTPRIVATE *)calloc(pFontBase->no_fonts_limit 						  + ADVANCE_FONTPRIVATE,						  sizeof(FONTPRIVATE));    }    else {      /* We already have some fonts */      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(-2); /* No memory available */      }    }    pFontBase->no_fonts_limit += ADVANCE_FONTPRIVATE;    /* First, initialize newly allocated to be not used */    for ( i=pFontBase->no_fonts;	  i<pFontBase->no_fonts+ADVANCE_FONTPRIVATE; i++){      pFontBase->pFontArray[i].pFontFileName=NULL;      pFontBase->pFontArray[i].pAfmFileName=NULL;      pFontBase->pFontArray[i].pAFMData=NULL;      pFontBase->pFontArray[i].pType1Data=NULL;      pFontBase->pFontArray[i].pEncMap=NULL;      pFontBase->pFontArray[i].pKernMap=NULL;      pFontBase->pFontArray[i].pFontEnc=NULL;      pFontBase->pFontArray[i].pFontSizeDeps=NULL;      pFontBase->pFontArray[i].vm_base=NULL;      pFontBase->pFontArray[i].FontMatrix[0]=0.0;      pFontBase->pFontArray[i].FontMatrix[1]=0.0;      pFontBase->pFontArray[i].FontMatrix[2]=0.0;      pFontBase->pFontArray[i].FontMatrix[3]=0.0;      pFontBase->pFontArray[i].FontTransform[0]=0.0;      pFontBase->pFontArray[i].FontTransform[1]=0.0;      pFontBase->pFontArray[i].FontTransform[2]=0.0;      pFontBase->pFontArray[i].FontTransform[3]=0.0;      pFontBase->pFontArray[i].slant=0.0;      pFontBase->pFontArray[i].extend=0.0;      pFontBase->pFontArray[i].physical=0;      pFontBase->pFontArray[i].refcount=0;       pFontBase->pFontArray[i].space_position=0;       pFontBase->pFontArray[i].info_flags=0;     }  }  /* no_fonts-1 was the largest allowed font ID */  new_ID=pFontBase->no_fonts;  pFontBase->no_fonts++;  if ((FontBase.pFontArray[new_ID].pFontFileName=(char *)       calloc( strlen( fontfilename)+1, sizeof(char))) == NULL){    T1_PrintLog( "T1_AddFont()",		 "Failed to allocate memory for Filename %s (FontID=%d)",		 T1LOG_ERROR, fontfilename, new_ID);    T1_errno=T1ERR_ALLOC_MEM;    return(-3);  }  strcpy( FontBase.pFontArray[new_ID].pFontFileName, fontfilename);  /* Generate logfile entry */  sprintf( err_warn_msg_buf, "Assigned FontID %d to fontfile %s",	   new_ID, FontBase.pFontArray[new_ID].pFontFileName);  T1_PrintLog( "T1_AddFont()", err_warn_msg_buf,	       T1LOG_STATISTIC);  /* Return FontID of newly declared font */  return( new_ID);  }/* T1_PrintLog() generates entries in the log file. msg_txt is subject to scan   conversion and ... signifies a accordingly lrge variable list. */void T1_PrintLog( char *func_ident, char *msg_txt, int level, ...){  va_list vararg;  static char levelid[4]={ 'E', 'W', 'S', 'D'};  time_t s_clock, *tp;    if (t1lib_log_file==NULL)    return;  if ((level>t1lib_log_level) || (level<1)){    return;  }  else{    /* initialize argument list */    va_start( vararg, level);        tp=&s_clock;    s_clock=time( tp);    /*    fprintf( t1lib_log_file, "(%c) (%.24s) %s: ",	     levelid[level-1], ctime(&s_clock), func_ident);	     */    /* Don't print the time stamp */    fprintf( t1lib_log_file, "(%c) %s: ", levelid[level-1], func_ident );    vfprintf( t1lib_log_file, msg_txt, vararg );    fprintf( t1lib_log_file, "\n");    fflush( t1lib_log_file);    /* cleanup variable list */    va_end( vararg);        return;  }}/* T1_SetLogLevel(): Set the level which a message must have so   that it is printed into the logfile. This function may be called   before T1_InitLib(). */void T1_SetLogLevel( int level){  if ((level>0) && (level<5))    t1lib_log_level=level;  return;}/* CheckForInit(): If no initialization of font mechanism has been   done, return -1, indicating an error. */int CheckForInit(void){  if(T1_Up)    return(0);  else    return(-1);  }/* CheckForFontID(): Checks the font mechanism concerning the specified   ID. It returns:                   0  if font belonging to FontID has not yet been loaded		   1  if font belonging to FontID has already been loaded		   -1 if FontID is an invalid specification or t1lib not		      initialized		   */int CheckForFontID( int FontID){  /* FontID is invalid */  if ((FontID<0)||(FontID>(pFontBase->no_fonts - 1))||(T1_Up==0))    return(-1);    if (pFontBase->pFontArray[FontID].pType1Data==NULL)    return(0);     /* has not yet been loaded */  else    return(1);     /* has already been loaded */} /* test_for_t1_file returns 0 if a file "name.pfa" or "name.pfb"   was found. Else, -1 is returned. If successful, buffer contains the   found filename string */int test_for_t1_file( char *buffer ){  int i=0;  char *FullName;    /* First case: A PostScript Font ASCII File without extension     (according to some UNIX-conventions) */  if ((FullName=intT1_Env_GetCompletePath(buffer,T1_PFAB_ptr))!=NULL) {    free(FullName);    return(0);  }  while (buffer[i]!=0){    i++;  }  buffer[i]='.';  buffer[i+1]='p';  buffer[i+2]='f';  buffer[i+4]=0;    /* Second case: A PostScript Font ASCII File */  buffer[i+3]='a';  if ((FullName=intT1_Env_GetCompletePath(buffer,T1_PFAB_ptr))!=NULL) {    free(FullName);    return(0);  }  /* Third case: A PostScript Font Binary File */  buffer[i+3]='b';  if ((FullName=intT1_Env_GetCompletePath(buffer,T1_PFAB_ptr))!=NULL) {    free(FullName);    return(0);  }    /* If we get here no file was found => Set buffer     to an empty string and return -1 */    buffer[0]=0;  return(-1);}/* T1_GetFontFileName() returns a pointer to the filename of the font,   associated with FontID. This filename does not contain a full path.   */char *T1_GetFontFileName( int FontID){  static char filename[MAXPATHLEN+1];    if (CheckForInit())return(NULL);  /* Check first for valid FontID */  if ((FontID<0) || (FontID>FontBase.no_fonts)){    T1_errno=T1ERR_INVALID_FONTID;    return(NULL);  }    strcpy( filename, pFontBase->pFontArray[FontID].pFontFileName);    return( filename);  }/* As suggested by Nicolai Langfeldt, we make it possible to specify   a completely independent path for the afm filename. This should   make t1lib usable in context with using the kpathsearch-library.   We allow setting those path磗 after initialization, but before a   font is loaded.   returns  0:   OK           -1:   Operation could not be performed*/int T1_SetAfmFileName( int FontID, char *afm_name){  if (CheckForFontID(FontID)!=0){    /* Operation may not be applied because FontID is invalid       or font is loaded */    T1_errno=T1ERR_INVALID_FONTID;    return(-1);  }  if (afm_name==NULL) {    T1_errno=T1ERR_INVALID_PARAMETER;    return(-1);  }  if (pFontBase->pFontArray[FontID].pAfmFileName!=NULL){    /* we first free the current name */    free( pFontBase->pFontArray[FontID].pAfmFileName);    pFontBase->pFontArray[FontID].pAfmFileName=NULL;  }    if ((pFontBase->pFontArray[FontID].pAfmFileName=       (char *)malloc( (strlen(afm_name)+1)*sizeof( char)))==NULL) {    T1_errno=T1ERR_ALLOC_MEM;    return( -1);  }  strcpy( pFontBase->pFontArray[FontID].pAfmFileName, afm_name);	    return(0);  }		   /* We have a function for querying the name. Returns a pointer   to the string or NULL if name was not explicitly set .*/char *T1_GetAfmFileName( int FontID){  static char filename[MAXPATHLEN+1];    if (CheckForInit())return(NULL);  /* Check first for valid FontID */  if ((FontID<0) || (FontID>FontBase.no_fonts)){    T1_errno=T1ERR_INVALID_FONTID;    return(NULL);  }  if (pFontBase->pFontArray[FontID].pAfmFileName==NULL) {    return( NULL);  }    strcpy( filename, pFontBase->pFontArray[FontID].pAfmFileName);  return( filename);  }  /* T1_Get_no_fonts(): Return the number of declared fonts */int  T1_Get_no_fonts(void){  if (CheckForInit())return(-1);  return(FontBase.no_fonts);}	/* T1_SetDeviceResolutions( x_res, y_res): Set the device's physical   resolution in horizontal and vertical direction, mesured in DPI   (Dots Per Inch). This should be done before the first font is   loaded! */int T1_SetDeviceResolutions( float x_res, float y_res){  int i;    if (CheckForInit())    ;   /* Not initialized -> no size dependent data -> OK */  else    /* Check if size-dependent data is existent */    for ( i=T1_Get_no_fonts(); i; i--)      if (pFontBase->pFontArray[i-1].pFontSizeDeps!=NULL){	T1_errno=T1ERR_OP_NOT_PERMITTED;	return(-1); /* There's is size dependent data for a font */      }    /* Save resolutions and calculate horizontal and vertical     scale factors to map desired bp to device pixel */  DeviceSpecifics.x_resolution=(float) x_res;  DeviceSpecifics.y_resolution=(float) y_res;  DeviceSpecifics.scale_x=(float)(((float)x_res)/BIGPOINTSPERINCH);  DeviceSpecifics.scale_y=(float)(((float)y_res)/BIGPOINTSPERINCH);  return(0);}/* T1_QueryX11Support(): Check at runtime to see if t1lib was compiled   with X11 interface: */int T1_QueryX11Support( void){#ifndef T1LIB_NO_X11_SUPPORT  return(1);#else  return(0);#endif}/* int T1_CopyFont(): Copies the font associated with FontID to another   location. The pointers to type1- , afm- and encoding data as well as   the matrices remain completely untouched. However, size dependent data   is not copied. The produced font is marked as a "logical" font.   If no memory is available in the FONTPRIVATE-array, there's realloc'ed   some more memory. The FontID which is assigned to the newly generated   font is given as the return value, or < 0 if an error occurs. Also,   the refcount entry of the source font is incremented by one.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -