home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fonts 1 / freshfonts1.bin / bbs / programs / amiga / pastex13.lha / DVIPS / dvips5519.lha / dvips / tfmload.c < prev    next >
C/C++ Source or Header  |  1993-01-19  |  3KB  |  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. integer
  74. tfm32 ()
  75. {
  76.   register integer a ; 
  77.   a = tfm16 () ; 
  78.   if (a > 32767) a -= 65536 ;
  79.   return ( a * 65536 + tfm16 () ) ; 
  80.  
  81. int
  82. tfmload(curfnt)
  83.         register fontdesctype *curfnt ;
  84. {
  85.    register shalfword i ;
  86.    register integer li ;
  87.    integer scaledsize ;
  88.    shalfword nw, hd ;
  89.    shalfword bc, ec ;
  90.    integer scaled[256] ;
  91.    halfword chardat[256] ;
  92.    int charcount = 0 ;
  93.  
  94.    tfmopen(curfnt) ;
  95. /*
  96.  *   Next, we read the font data from the tfm file, and store it in
  97.  *   our own arrays.
  98.  */
  99.    li = tfm16() ; hd = tfm16() ;
  100.    bc = tfm16() ; ec = tfm16() ;
  101.    nw = tfm16() ;
  102.    li = tfm32() ; li = tfm32() ; li = tfm32() ; li = tfm16() ;
  103.    li = tfm32() ;
  104.    if (li && curfnt->checksum)
  105.       if (li!=curfnt->checksum) {
  106.          (void)sprintf(errbuf,"Checksum mismatch in %s", name) ;
  107.          error(errbuf) ;
  108.        }
  109.    li = (integer)(alpha * (real)tfm32()) ;
  110.    if (li > curfnt->designsize + fsizetol ||
  111.        li < curfnt->designsize - fsizetol) {
  112.       (void)sprintf(errbuf,"Design size mismatch in %s", name) ;
  113.       error(errbuf) ;
  114.    }
  115.    for (i=2; i<hd; i++)
  116.       li = tfm32() ;
  117.    for (i=0; i<256; i++)
  118.       chardat[i] = 256 ;
  119.    for (i=bc; i<=ec; i++) {
  120.       chardat[i] = tfmbyte() ;
  121.       li = tfm16() ;
  122.       li |= tfmbyte() ;
  123.       if (li || chardat[i])
  124.          charcount++ ;
  125.    }
  126.    scaledsize = curfnt->scaledsize ;
  127.    for (i=0; i<nw; i++)
  128.       scaled[i] = scalewidth(tfm32(), scaledsize) ;
  129.    (void)fclose(tfmfile) ;
  130.    for (i=0; i<256; i++)
  131.       if (chardat[i]!= 256) {
  132.          li = scaled[chardat[i]] ;
  133.          curfnt->chardesc[i].TFMwidth = li ;
  134.          if (li >= 0)
  135.             curfnt->chardesc[i].pixelwidth = ((integer)(conv*li+0.5)) ;
  136.          else
  137.             curfnt->chardesc[i].pixelwidth = -((integer)(conv*-li+0.5)) ;
  138.          curfnt->chardesc[i].flags = (curfnt->resfont ? EXISTS : 0) ;
  139.       }
  140.    curfnt->loaded = 1 ;
  141.    return charcount ;
  142. }
  143.