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