home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PRINTING / DVIPS386.ZIP / TFMLOAD.C < prev    next >
C/C++ Source or Header  |  1990-11-25  |  3KB  |  125 lines

  1. /*
  2.  *   Loads a tfm file.  It marks the characters as undefined.
  3.  */
  4. #include "structures.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. static FILE *tfmfile ; 
  24. static char name[50] ;
  25.  
  26. /*
  27.  *   Tries to open a tfm file.  Aborts job if unsuccessful.
  28.  */
  29. void
  30. tfmopen(fd)
  31.         register fontdesctype *fd ;
  32. {
  33.    register char *d, *n ;
  34.  
  35.    d = fd->area ;
  36.    n = fd->name ;
  37.    if (*d==0)
  38.       d = tfmpath ;
  39.    (void)sprintf(name, "%s.tfm", n) ;
  40.    if ((tfmfile=search(d, name, READBIN))==NULL) {
  41.       (void)sprintf(errbuf, "! Can't open font metric file %s%s",
  42.              fd->area, name) ;
  43.       error(errbuf) ;
  44.    }
  45. }
  46.  
  47. shalfword
  48. tfmbyte ()
  49. {
  50.   return(getc(tfmfile)) ;
  51. }
  52.  
  53. halfword
  54. tfm16 ()
  55. {
  56.   register halfword a ; 
  57.   a = tfmbyte () ; 
  58.   return ( a * 256 + tfmbyte () ) ; 
  59.  
  60. integer
  61. tfm32 ()
  62. {
  63.   register integer a ; 
  64.   a = tfm16 () ; 
  65.   if (a > 32767) a -= 65536 ;
  66.   return ( a * 65536 + tfm16 () ) ; 
  67.  
  68. void
  69. tfmload(curfnt)
  70.         register fontdesctype *curfnt ;
  71. {
  72.    register shalfword i ;
  73.    register integer li ;
  74.    integer scaledsize ;
  75.    shalfword nw, hd ;
  76.    shalfword bc, ec ;
  77.    integer scaled[256] ;
  78.    halfword chardat[256] ;
  79.  
  80.    tfmopen(curfnt) ;
  81. /*
  82.  *   Next, we read the font data from the tfm file, and store it in
  83.  *   our own arrays.
  84.  */
  85.    li = tfm16() ; hd = tfm16() ;
  86.    bc = tfm16() ; ec = tfm16() ;
  87.    nw = tfm16() ;
  88.    li = tfm32() ; li = tfm32() ; li = tfm32() ; li = tfm16() ;
  89.    li = tfm32() ;
  90.    if (li && curfnt->checksum)
  91.       if (li!=curfnt->checksum) {
  92.          (void)sprintf(errbuf,"Checksum mismatch in %s", name) ;
  93.          error(errbuf) ;
  94.        }
  95.    li = (integer)(alpha * (real)tfm32()) ;
  96.    if (li > curfnt->designsize + fsizetol ||
  97.        li < curfnt->designsize - fsizetol) {
  98.       (void)sprintf(errbuf,"Design size mismatch in %s", name) ;
  99.       error(errbuf) ;
  100.    }
  101.    for (i=2; i<hd; i++)
  102.       li = tfm32() ;
  103.    for (i=0; i<256; i++)
  104.       chardat[i] = 256 ;
  105.    for (i=bc; i<=ec; i++) {
  106.       chardat[i] = tfmbyte() ;
  107.       li = tfm16() ;
  108.       li = tfmbyte() ;
  109.    }
  110.    scaledsize = curfnt->scaledsize ;
  111.    for (i=0; i<nw; i++)
  112.       scaled[i] = scalewidth(tfm32(), scaledsize) ;
  113.    (void)fclose(tfmfile) ;
  114.    for (i=0; i<256; i++)
  115.       if (chardat[i]!= 256) {
  116.          li = scaled[chardat[i]] ;
  117.          curfnt->chardesc[i].TFMwidth = li ;
  118.          curfnt->chardesc[i].pixelwidth = ((integer)(conv*li+0.5)) ;
  119.          curfnt->chardesc[i].flags = (curfnt->resfont ? EXISTS : 0) ;
  120.       }
  121.    curfnt->loaded = 1 ;
  122. }
  123.