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