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

📄 t1load.c

📁 source code: Covert TXT to PDF
💻 C
📖 第 1 页 / 共 3 页
字号:
/*--------------------------------------------------------------------------  ----- File:        t1load.c   ----- Author:      Rainer Menzner (Rainer.Menzner@web.de)  ----- Date:        2001-10-03  ----- Description: This file is part of the t1-library. It contains                     functions for loading fonts  and for managing size		     dependent data.  ----- Copyright:   t1lib is copyrighted (c) Rainer Menzner, 1996-2001.                      As of version 0.5, t1lib is distributed under the		     GNU General Public Library Lincense. The		     conditions can be found in the files LICENSE and		     LGPL, which should reside in the toplevel		     directory of the distribution.  Please note that 		     there are parts of t1lib that are subject to		     other licenses:		     The parseAFM-package is copyrighted by Adobe Systems		     Inc.		     The type1 rasterizer is copyrighted by IBM and the		     X11-consortium.  ----- Warranties:  Of course, there's NO WARRANTY OF ANY KIND :-)  ----- Credits:     I want to thank IBM and the X11-consortium for making                     their rasterizer freely available.		     Also thanks to Piet Tutelaers for his ps2pk, from		     which I took the rasterizer sources in a format		     independent from X11.                     Thanks to all people who make free software living!--------------------------------------------------------------------------*/  #define T1LOAD_C#define ANSI_REALLOC_VM  #include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#if defined(_MSC_VER)# include <io.h># include <sys/types.h># include <sys/stat.h>#else# include <unistd.h>#endif#include <stdlib.h>#include <math.h>#include <string.h>#include "../type1/ffilest.h"#include "../type1/types.h"#include "parseAFM.h" #include "../type1/objects.h"#include "../type1/spaces.h"#include "../type1/util.h"#include "../type1/fontfcn.h"#include "../type1/blues.h"#include "../type1/regions.h"#include "t1types.h"#include "t1extern.h"#include "t1load.h"#include "t1env.h"#include "t1set.h"#include "t1base.h"#include "t1finfo.h"#include "t1afmtool.h"extern psobj *StdEncArrayP;       /* For checking of a fonts encoding */extern char not_def[];            /* for checking the ".notdef"-string *//* T1_LoadFont(FontID): Loads a Type1 font into memory and allocates all   memory, necessary for this. */int T1_LoadFont( int FontID){  int i, j, k, l, m;  char *FileName, *FileNamePath;  int mode;  /* This is used by the type1-library for error reporting */     char *charname;    /* The following vars are used for reallocation of VM */  long tmp_size;  float ascender;#ifdef ANSI_REALLOC_VM  unsigned long shift;  unsigned long ldummy;  char *tmp_ptr;#endif  struct region *area;  struct XYspace *S;      /* These are for constructing the kerning lookup table: */  PairKernData *pkd;  METRICS_ENTRY *kern_tbl;  int char1, char2;      if (CheckForInit()){    T1_errno=T1ERR_OP_NOT_PERMITTED;    return(-1);  }    i=CheckForFontID(FontID);  if (i==1)    return(0);      /* Font already loaded */  if (i==-1){    T1_errno=T1ERR_INVALID_FONTID;    return(-1);     /* illegal FontID */  }    /* Allocate memory for ps_font structure: */  if ((pFontBase->pFontArray[FontID].pType1Data=(psfont *)malloc(sizeof(psfont)))==NULL){    T1_PrintLog( "T1_LoadFont()", "Failed to allocate memory for psfont-struct (FontID=%d)",		 T1LOG_ERROR, FontID);    T1_errno=T1ERR_ALLOC_MEM;    return(-1);  }  /* Check for valid filename */  if ((FileName=T1_GetFontFileName(FontID))==NULL){    T1_PrintLog( "T1_LoadFont()", "No font file name for font %d", T1LOG_ERROR, FontID);    return(-1);  }    /* Fetch the full path of type1 font file */  if ((FileNamePath=intT1_Env_GetCompletePath( FileName,					 T1_PFAB_ptr))==NULL){    T1_PrintLog( "T1_LoadFont()", "Couldn't locate font file for font %d in %s",		 T1LOG_ERROR, FontID, T1_GetFileSearchPath(T1_PFAB_PATH));    T1_errno=T1ERR_FILE_OPEN_ERR;    return(-1);  }    /* And load all PostScript information into memory */  if (fontfcnA( FileNamePath, &mode,		pFontBase->pFontArray[FontID].pType1Data) == FALSE){    T1_PrintLog( "T1_LoadFont()", "Loading font with ID = %d failed! (mode = %d)",		 T1LOG_ERROR, FontID, mode);    free(FileNamePath);    pFontBase->pFontArray[FontID].pType1Data=NULL;    T1_errno=mode;    return(-1);  }  free(FileNamePath);    /* Store the base address of virtual memory and realloc in order not     to waste too much memory: */  pFontBase->pFontArray[FontID].vm_base=vm_base; #ifdef ANSI_REALLOC_VM  /* We first get the size of pointers on the current system */  /* Get size of VM, ... */  tmp_size=((unsigned long)vm_used - (unsigned long)vm_base);   /* ... realloc to that size ... */  tmp_ptr=(char *)realloc(vm_base,  tmp_size);   /* ... and shift all pointers refering to that area */  if (tmp_ptr > vm_base){    shift= (unsigned long)tmp_ptr - (unsigned long)vm_base;    sprintf( err_warn_msg_buf,	     "Old VM at 0x%lX, new VM at 0x%lX, shifting up by %lu",	     (unsigned long)vm_base, (unsigned long)tmp_ptr, tmp_size);    T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG);        /* We start by shifting the topmost pointers: */    pFontBase->pFontArray[FontID].vm_base=tmp_ptr;        ldummy=(long)(pFontBase->pFontArray[FontID].pType1Data->vm_start);    ldummy +=shift;    pFontBase->pFontArray[FontID].pType1Data->vm_start=(char *)ldummy;        ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->CharStringsP;    ldummy +=shift;    pFontBase->pFontArray[FontID].pType1Data->CharStringsP=(psdict *)ldummy;        ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Private;    ldummy +=shift;    pFontBase->pFontArray[FontID].pType1Data->Private=(psdict *)ldummy;        ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP;    ldummy +=shift;    pFontBase->pFontArray[FontID].pType1Data->fontInfoP=(psdict *)ldummy;        ldummy=(long)(pFontBase->pFontArray[FontID].pType1Data->BluesP);    ldummy +=shift;    pFontBase->pFontArray[FontID].pType1Data->BluesP=(struct blues_struct *)ldummy;        /* We now have to care for correcting all pointers which are in the VM       and refer to some place in the VM! Note: Instead of selecting the       appropriate pointer-elements of the union we simply shift the       unspecified pointer "valueP".       Note: The filename entry does not need to be modified since it does not       need to be shifted since it points to memory managed by t1lib.       */    /* FontInfo-dictionary: All name-pointers and the pointers to all array       types have to be shifted: */    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 standard 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( tmp_ptr > vm_base ) */  else if ( vm_base > tmp_ptr){    shift= (unsigned long)vm_base - (unsigned long)tmp_ptr;    sprintf( err_warn_msg_buf,	     "Old VM at 0x%lX, new VM at 0x%lX, shifting down by %lu",	     (unsigned long)vm_base, (unsigned long)tmp_ptr, tmp_size);    T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG);        /* We start by shifting the topmost pointers: */    pFontBase->pFontArray[FontID].vm_base=tmp_ptr;        ldummy=(long)(pFontBase->pFontArray[FontID].pType1Data->vm_start);    ldummy -=shift;    pFontBase->pFontArray[FontID].pType1Data->vm_start=(char *)ldummy;        ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->CharStringsP;    ldummy -=shift;    pFontBase->pFontArray[FontID].pType1Data->CharStringsP=(psdict *)ldummy;        ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Private;    ldummy -=shift;    pFontBase->pFontArray[FontID].pType1Data->Private=(psdict *)ldummy;        ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP;    ldummy -=shift;    pFontBase->pFontArray[FontID].pType1Data->fontInfoP=(psdict *)ldummy;        ldummy=(long)(pFontBase->pFontArray[FontID].pType1Data->BluesP);    ldummy -=shift;    pFontBase->pFontArray[FontID].pType1Data->BluesP=(struct blues_struct *)ldummy;        /* We now have to care for correcting all pointers which are in the VM       and refer to some place in the VM! Note: Instead of selecting the       appropriate pointer-elements of the union we simply shift the       unspecified pointer "valueP".       Note: The filename entry does not need to be modified since it does not       need to be shifted since it points to memory managed by t1lib.       */    /* FontInfo-dictionary: All name-pointers and the pointers to all array       types have to be shifted: */

⌨️ 快捷键说明

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