home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 3.3J / os33j.iso / NextLibrary / TeX / tex / src / dvips / fontdef.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-22  |  5.4 KB  |  193 lines

  1. /*
  2.  *  Stores the data from a font definition into the global data structures.
  3.  *  A routine skipnop is also included to handle nops and font definitions
  4.  *  between pages.
  5.  */
  6. #include "dvips.h" /* The copyright notice in that file is included too! */
  7. /*
  8.  *   These are the external routines we call.
  9.  */
  10. extern shalfword dvibyte() ;
  11. extern halfword twobytes() ;
  12. extern integer threebytes(), signedquad() ;
  13. extern void skipover(), error() ;
  14. /*
  15.  *   The external variables we use:
  16.  */
  17. extern char *nextstring, *maxstring ;
  18. extern integer mag ;
  19. extern fontdesctype *baseFonts[] ;
  20. #ifdef DEBUG
  21. extern integer debug_flag;
  22. #endif  /* DEBUG */
  23. extern int actualdpi ;
  24. extern real alpha ;
  25. extern fontmaptype *ffont ;
  26. extern fontdesctype *fonthead ;
  27. extern halfword dpicheck() ;
  28. extern integer fsizetol ;
  29. /*
  30.  * newfontdesc creates a new font descriptor with the given parameters and
  31.  * returns a pointer to the new object.
  32. */
  33. fontdesctype*
  34. newfontdesc(cksum, scsize, dssize, name, area)
  35. integer cksum, scsize, dssize ;
  36. char *name, *area ;
  37. {
  38.    register fontdesctype *fp ;
  39.  
  40.    fp = (fontdesctype *)mymalloc((integer)sizeof(fontdesctype)) ;
  41.    fp->psname = 0 ;
  42.    fp->loaded = 0 ;
  43.    fp->checksum = cksum ;
  44.    fp->scaledsize = scsize ;
  45.    fp->designsize = dssize ;
  46.    fp->thinspace = scsize / 6 ;
  47.    fp->scalename = NULL ;
  48.    fp->psflag = 0 ;
  49.    fp->name = name;
  50. #ifdef VMCMS   /* IBM: VM/CMS */
  51.    {
  52.      int i ;
  53.      for ( i=0 ; fp->name[i] ; i++ )
  54.        fp->name[i] = ascii2ebcdic[ fp->name[i] ] ;
  55.    }
  56. #ifdef MVSXA   /* IBM: MVS/XA */
  57.    {
  58.      int i ;
  59.      for ( i=0 ; fp->name[i] ; i++ )
  60.        fp->name[i] = ascii2ebcdic[ fp->name[i] ] ;
  61.    }
  62. #endif   /* IBM: MVS/XA */
  63. #endif   /* IBM: VM/CMS */
  64.    fp->area = area;
  65.    fp->resfont = NULL ;
  66.    fp->localfonts = NULL ;
  67.    fp->dpi = dpicheck((halfword)((float)mag*(float)fp->scaledsize*DPI/
  68.          ((float)fp->designsize*1000.0)+0.5)) ;
  69.    fp->loadeddpi = fp->dpi ;
  70. #ifdef DEBUG
  71.    if (dd(D_FONTS))
  72.       (void)fprintf(stderr,"Defining font (%s) %s at %.1fpt\n",
  73.          area, name, (real)scsize/(alpha*0x100000)) ;
  74. #endif /* DEBUG */
  75.    return fp ;
  76. }
  77. /*
  78.  * Try to find a font with a given name and approximate scaled size, returning
  79.  * NULL if unsuccessful.  If scname and the font's scalename are both
  80.  * non-NULL they must match exactly.  If both are NULL, scsize and the
  81.  * font's scaledsize come from the dvi file and should match exactly.
  82.  * Otherwise there can be some slop due to the inaccuracies of sizes
  83.  * read from an included psfile.
  84.  */
  85. fontdesctype *
  86. matchfont(name, area, scsize, scname)
  87. char *area, *name, *scname ;
  88. integer scsize ;
  89. {
  90.    register fontdesctype *fp;
  91.    register integer smin, smax;
  92.  
  93.    smin = scsize - fsizetol ;
  94.    smax = scsize + fsizetol ;
  95.    for (fp=fonthead; fp; fp=fp->next)
  96.       if (smin < fp->scaledsize && fp->scaledsize < smax &&
  97.             strcmp(name,fp->name)==0 && strcmp(area,fp->area)==0)
  98.          if (scname == NULL) {
  99.             if (fp->scalename!=NULL || scsize==fp->scaledsize)
  100.                break ;
  101.          } else {
  102.             if (fp->scalename==NULL || strcmp(scname,fp->scalename)==0)
  103.                break ;
  104.          }
  105. #ifdef DEBUG
  106.    if (dd(D_FONTS) && fp)
  107.       (void)fprintf(stderr,"(Already known.)\n") ;
  108. #endif /* DEBUG */
  109.    return fp;
  110. }
  111. /*
  112.  *   fontdef takes a font definition in the dvi file and loads the data
  113.  *   into its data structures.
  114.  */
  115. void
  116. fontdef(siz)
  117. int siz ;
  118. {
  119.    register integer i, j, fn ;
  120.    register fontdesctype *fp ;
  121.    register fontmaptype *cfnt ;
  122.    char *name, *area ;
  123.    integer cksum, scsize, dssize ;
  124.    extern void skipover() ;
  125.  
  126.    fn = dvibyte() ;
  127.    while (siz-- > 1)
  128.       fn = (fn << 8) + dvibyte() ;
  129.    for (cfnt=ffont; cfnt; cfnt = cfnt->next)
  130.       if (cfnt->fontnum == fn) goto alreadydefined ;
  131.    cfnt = (fontmaptype *)mymalloc((integer)sizeof(fontmaptype)) ;
  132.    cfnt->next = ffont ;
  133.    ffont = cfnt ;
  134.    cfnt->fontnum = fn ;
  135.    cksum = signedquad() ;
  136.    scsize = signedquad() ;
  137.    dssize = signedquad() ;
  138.    i = dvibyte() ; j = dvibyte() ;
  139.    if (nextstring + i + j > maxstring)
  140.       error("! out of string space") ;
  141.    area = nextstring ;
  142.    for (; i>0; i--)
  143.       *nextstring++ = dvibyte() ;
  144.    *nextstring++ = 0 ;
  145.    name = nextstring ;
  146.    for (; j>0; j--)
  147.       *nextstring++ = dvibyte() ;
  148.    *nextstring++ = 0 ;
  149.    fp = matchfont(name, area, scsize, (integer)0) ;
  150.    if (fp) {
  151.       nextstring = name ;
  152.       fp->checksum = cksum ;
  153.    } else {
  154.       fp = newfontdesc(cksum, scsize, dssize, name, area) ;
  155.       fp->next = fonthead ;
  156.       fonthead = fp ;
  157.    }
  158.    cfnt->desc = fp ;
  159.    if (fn < 256)
  160.       baseFonts[fn] = fp ;
  161.    return ;
  162. alreadydefined:
  163. /* A DVI file will not define a font twice; but we may be scanning
  164.  * a font definition twice because a new section has started,
  165.  * or because of collated copies. */
  166.       skipover(12) ;
  167.       skipover(dvibyte()+dvibyte()) ;
  168. }
  169.  
  170. /*
  171.  *   The next routine handles nops or font definitions between pages in a
  172.  *   dvi file.  Returns the first command that is not a nop or font definition.
  173.  *
  174.  *   Now handles specials (but ignores them)
  175.  */
  176. int
  177. skipnop()
  178. {
  179.   register int cmd ;
  180.  
  181.    while (1) {
  182.       switch(cmd=dvibyte()) {
  183. case 138: break ;
  184. case 239: skipover((int)dvibyte()) ; break ; /* xxx1 */
  185. case 240: skipover((int)twobytes()) ; break ; /* xxx2 */
  186. case 241: skipover((int)threebytes()) ; break ; /* xxx3 */
  187. case 242: skipover((int)signedquad()) ; break ; /* xxx4 */
  188. case 243: case 244: case 245: case 246: fontdef(cmd-242) ; break ;
  189. default: return cmd ;
  190.       }
  191.    }
  192. }
  193.