Back to index

tetex-bin  3.0
fontdef.c
Go to the documentation of this file.
00001 /*
00002  *  Stores the data from a font definition into the global data structures.
00003  *  A routine skipnop is also included to handle nops and font definitions
00004  *  between pages.
00005  */
00006 #include "dvips.h" /* The copyright notice in that file is included too! */
00007 #ifdef KPATHSEA
00008 #include <kpathsea/magstep.h>
00009 #endif
00010 
00011 /*
00012  *   These are the external routines we call.
00013  */
00014 #include "protos.h"
00015 
00016 /*
00017  *   The external variables we use:
00018  */
00019 extern char *nextstring, *maxstring ;
00020 extern double mag ;
00021 #ifdef DEBUG
00022 extern integer debug_flag;
00023 #endif  /* DEBUG */
00024 extern int actualdpi ;
00025 extern real alpha ;
00026 extern fontmaptype *ffont ;
00027 extern quarterword *curpos ;
00028 extern fontdesctype *fonthead ;
00029 extern integer fsizetol ;
00030 /*
00031  * newfontdesc creates a new font descriptor with the given parameters and
00032  * returns a pointer to the new object.
00033 */
00034 fontdesctype*
00035 newfontdesc P5C(integer, cksum, integer, scsize, integer, dssize,
00036               char *, name, char *, area)
00037 {
00038    register fontdesctype *fp ;
00039 
00040    fp = (fontdesctype *)mymalloc((integer)sizeof(fontdesctype)) ;
00041    fp->chardesc = (chardesctype *)mymalloc(256*(integer)sizeof(chardesctype)) ;
00042    fp->maxchars = 256 ;
00043    fp->psname = 0 ;
00044    fp->loaded = 0 ;
00045    fp->checksum = cksum ;
00046    fp->scaledsize = scsize ;
00047    fp->designsize = dssize ;
00048    fp->thinspace = scsize / 6 ;
00049    fp->scalename = NULL ;
00050    fp->psflag = 0 ;
00051    fp->codewidth = 1 ;
00052    fp->name = name;
00053 #ifdef VMCMS   /* IBM: VM/CMS */
00054    {
00055      int i ;
00056      for ( i=0 ; fp->name[i] ; i++ )
00057        fp->name[i] = ascii2ebcdic[ fp->name[i] ] ;
00058    }
00059 #else
00060 #ifdef MVSXA   /* IBM: MVS/XA */
00061    {
00062      int i ;
00063      for ( i=0 ; fp->name[i] ; i++ )
00064        fp->name[i] = ascii2ebcdic[ fp->name[i] ] ;
00065    }
00066 #endif   /* IBM: MVS/XA */
00067 #endif   /* IBM: VM/CMS */
00068    fp->area = area;
00069    fp->resfont = NULL ;
00070    fp->localfonts = NULL ;
00071 #ifdef KPATHSEA
00072    fp->dpi = kpse_magstep_fix ((halfword)(mag*(float)fp->scaledsize*DPI/
00073          ((float)fp->designsize*1000.0)+0.5), DPI, NULL) ;
00074 #else
00075    fp->dpi = dpicheck((halfword)(mag*fp->scaledsize*DPI/
00076          ((float)fp->designsize*1000.0)+0.5)) ;
00077 #endif
00078    fp->loadeddpi = fp->dpi ;
00079 #ifdef DEBUG
00080    if (dd(D_FONTS))
00081       (void)fprintf(stderr,"Defining font (%s) %s at %.1fpt\n",
00082          area, name, (real)scsize/(alpha*0x100000)) ;
00083 #endif /* DEBUG */
00084    return fp ;
00085 }
00086 /*
00087  * Try to find a font with a given name and approximate scaled size, returning
00088  * NULL if unsuccessful.  If scname and the font's scalename are both
00089  * non-NULL they must match exactly.  If both are NULL, scsize and the
00090  * font's scaledsize come from the dvi file and should match exactly.
00091  * Otherwise there can be some slop due to the inaccuracies of sizes
00092  * read from an included psfile.
00093  */
00094 fontdesctype *
00095 matchfont P4C(char *, name, char *, area, integer, scsize, char *, scname)
00096 {
00097    register fontdesctype *fp;
00098    register integer smin, smax;
00099 
00100    smin = scsize - fsizetol ;
00101    smax = scsize + fsizetol ;
00102    for (fp=fonthead; fp; fp=fp->next)
00103       if (smin < fp->scaledsize && fp->scaledsize < smax &&
00104             strcmp(name,fp->name)==0 && strcmp(area,fp->area)==0) {
00105          if (scname == NULL) {
00106             if (fp->scalename!=NULL || scsize==fp->scaledsize)
00107                break ;
00108          } else {
00109             if (fp->scalename==NULL || strcmp(scname,fp->scalename)==0)
00110                break ;
00111          }
00112       }
00113 #ifdef DEBUG
00114    if (dd(D_FONTS) && fp)
00115       (void)fprintf(stderr,"(Already known.)\n") ;
00116 #endif /* DEBUG */
00117    return fp;
00118 }
00119 /*
00120  *   fontdef takes a font definition in the dvi file and loads the data
00121  *   into its data structures.
00122  */
00123 void
00124 fontdef P1C(int, siz)
00125 {
00126    register integer i, j, fn ;
00127    register fontdesctype *fp ;
00128    register fontmaptype *cfnt ;
00129    char *name, *area ;
00130    integer cksum, scsize, dssize ;
00131    extern void skipover(int) ;
00132 
00133    fn = dvibyte() ;
00134    while (siz-- > 1)
00135       fn = (fn << 8) + dvibyte() ;
00136    for (cfnt=ffont; cfnt; cfnt = cfnt->next)
00137       if (cfnt->fontnum == fn) goto alreadydefined ;
00138    cfnt = (fontmaptype *)mymalloc((integer)sizeof(fontmaptype)) ;
00139    cfnt->next = ffont ;
00140    ffont = cfnt ;
00141    cfnt->fontnum = fn ;
00142    cksum = signedquad() ;
00143    scsize = signedquad() ;
00144    dssize = signedquad() ;
00145    i = dvibyte() ; j = dvibyte() ;
00146    if (nextstring + i + j > maxstring)
00147       error("! out of string space") ;
00148    area = nextstring ;
00149    for (; i>0; i--)
00150       *nextstring++ = dvibyte() ;
00151    *nextstring++ = 0 ;
00152    name = nextstring ;
00153    for (; j>0; j--)
00154       *nextstring++ = dvibyte() ;
00155    *nextstring++ = 0 ;
00156    fp = matchfont(name, area, scsize, (char *)0) ;
00157    if (fp) {
00158       nextstring = name ;
00159       fp->checksum = cksum ;
00160    } else {
00161       fp = newfontdesc(cksum, scsize, dssize, name, area) ;
00162       fp->next = fonthead ;
00163       fonthead = fp ;
00164    }
00165    cfnt->desc = fp ;
00166    return ;
00167 alreadydefined:
00168 /* A DVI file will not define a font twice; but we may be scanning
00169  * a font definition twice because a new section has started,
00170  * or because of collated copies. */
00171       skipover(12) ;
00172       skipover(dvibyte()+dvibyte()) ;
00173 }
00174 
00175 /*
00176  *   The next routine handles nops or font definitions between pages in a
00177  *   dvi file.  Returns the first command that is not a nop or font definition.
00178  *
00179  *   Now handles specials (but ignores them)
00180  */
00181 int
00182 skipnop P1H(void)
00183 {
00184   register int cmd ;
00185 
00186    while (1) {
00187       switch(cmd=dvibyte()) {
00188 case 138: break ;
00189 case 239: skipover((int)dvibyte()) ; break ; /* xxx1 */
00190 case 240: skipover((int)twobytes()) ; break ; /* xxx2 */
00191 case 241: skipover((int)threebytes()) ; break ; /* xxx3 */
00192 case 242: skipover((int)signedquad()) ; break ; /* xxx4 */
00193 case 243: case 244: case 245: case 246: fontdef(cmd-242) ; break ;
00194 default: return cmd ;
00195       }
00196    }
00197 }