home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / t / tex / !dvips / Documents / Fonts / Source / c / tfmload < prev    next >
Encoding:
Text File  |  1994-10-23  |  3.4 KB  |  145 lines

  1. /*
  2.  *   Loads a tfm file.  It marks the characters as undefined.
  3.  */
  4. #include "dvips.h" /* The copyright notice in that file is included too! */
  5. /*
  6.  *   These are the external routines it calls:
  7.  */
  8. extern void error() ;
  9. extern integer scalewidth() ;
  10. extern FILE *search() ;
  11. /*
  12.  *   Here are the external variables we use:
  13.  */
  14. extern real conv ;
  15. extern real vconv ;
  16. extern real alpha ;
  17. extern char *tfmpath ;
  18. extern char errbuf[] ;
  19. extern integer fsizetol ;
  20. /*
  21.  *   Our static variables:
  22.  */
  23. FILE *tfmfile ;
  24. static char name[50] ;
  25.  
  26. /*
  27.  *   Tries to open a tfm file.  Uses cmr10.tfm if unsuccessful,
  28.  *   and complains loudly about it.
  29.  */
  30. void
  31. tfmopen(fd)
  32.         register fontdesctype *fd ;
  33. {
  34.    register char *d, *n ;
  35.  
  36.    d = fd->area ;
  37.    n = fd->name ;
  38.    if (*d==0)
  39.       d = tfmpath ;
  40. #ifdef MVSXA   /* IBM: MVS/XA */
  41.    (void)sprintf(name, "tfm(%s)", n) ;
  42. #else
  43.    (void)sprintf(name, "%s.tfm", n) ;
  44. #endif
  45.    if ((tfmfile=search(d, name, READBIN))==NULL) {
  46.       (void)sprintf(errbuf, "Can't open font metric file %s%s",
  47.              fd->area, name) ;
  48.       error(errbuf) ;
  49.       error("I will use cmr10.tfm instead, so expect bad output.") ;
  50. #ifdef MVSXA   /* IBM: MVS/XA */
  51.       if ((tfmfile=search(d, "tfm(cmr10)", READBIN))==NULL)
  52. #else
  53.       if ((tfmfile=search(d, "cmr10.tfm", READBIN))==NULL)
  54. #endif
  55.          error(
  56.           "! I can't find cmr10.tfm; please reinstall me with proper paths") ;
  57.    }
  58. }
  59.  
  60. shalfword
  61. tfmbyte ()
  62. {
  63.   return(getc(tfmfile)) ;
  64. }
  65.  
  66. halfword
  67. tfm16 ()
  68. {
  69.   register halfword a ;
  70.   a = tfmbyte () ;
  71.   return ( a * 256 + tfmbyte () ) ;
  72. }
  73.  
  74. integer
  75. tfm32 ()
  76. {
  77.   register integer a ;
  78.   a = tfm16 () ;
  79.   if (a > 32767) a -= 65536 ;
  80.   return ( a * 65536 + tfm16 () ) ;
  81. }
  82.  
  83. int
  84. tfmload(curfnt)
  85.         register fontdesctype *curfnt ;
  86. {
  87.    register shalfword i ;
  88.    register integer li ;
  89.    integer scaledsize ;
  90.    shalfword nw, hd ;
  91.    shalfword bc, ec ;
  92.    integer scaled[256] ;
  93.    halfword chardat[256] ;
  94.    int charcount = 0 ;
  95.  
  96.    tfmopen(curfnt) ;
  97. /*
  98.  *   Next, we read the font data from the tfm file, and store it in
  99.  *   our own arrays.
  100.  */
  101.    li = tfm16() ; hd = tfm16() ;
  102.    bc = tfm16() ; ec = tfm16() ;
  103.    nw = tfm16() ;
  104.    li = tfm32() ; li = tfm32() ; li = tfm32() ; li = tfm16() ;
  105.    li = tfm32() ;
  106.    if (li && curfnt->checksum)
  107.       if (li!=curfnt->checksum) {
  108.          (void)sprintf(errbuf,"Checksum mismatch in %s", name) ;
  109.          error(errbuf) ;
  110.        }
  111.    li = (integer)(alpha * (real)tfm32()) ;
  112.    if (li > curfnt->designsize + fsizetol ||
  113.        li < curfnt->designsize - fsizetol) {
  114.       (void)sprintf(errbuf,"Design size mismatch in %s", name) ;
  115.       error(errbuf) ;
  116.    }
  117.    for (i=2; i<hd; i++)
  118.       li = tfm32() ;
  119.    for (i=0; i<256; i++)
  120.       chardat[i] = 256 ;
  121.    for (i=bc; i<=ec; i++) {
  122.       chardat[i] = tfmbyte() ;
  123.       li = tfm16() ;
  124.       li |= tfmbyte() ;
  125.       if (li || chardat[i])
  126.          charcount++ ;
  127.    }
  128.    scaledsize = curfnt->scaledsize ;
  129.    for (i=0; i<nw; i++)
  130.       scaled[i] = scalewidth(tfm32(), scaledsize) ;
  131.    (void)fclose(tfmfile) ;
  132.    for (i=0; i<256; i++)
  133.       if (chardat[i]!= 256) {
  134.          li = scaled[chardat[i]] ;
  135.          curfnt->chardesc[i].TFMwidth = li ;
  136.          if (li >= 0)
  137.             curfnt->chardesc[i].pixelwidth = ((integer)(conv*li+0.5)) ;
  138.          else
  139.             curfnt->chardesc[i].pixelwidth = -((integer)(conv*-li+0.5)) ;
  140.          curfnt->chardesc[i].flags = (curfnt->resfont ? EXISTS : 0) ;
  141.       }
  142.    curfnt->loaded = 1 ;
  143.    return charcount ;
  144. }
  145.