home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3.4.17 [SPARC, PA-RISC] / nextstep33_risc.iso / NextLibrary / TeX / tex / src / texview / tfmload.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-01  |  3.6 KB  |  151 lines

  1. /*
  2.  *   tfmload.c of dvisw software package.
  3.  *
  4.  *   Loads a tfm file.  It marks the characters as undefined.
  5.  */
  6. #include "structures.h"
  7. #include <string.h>
  8. /*
  9.  *   These are the external routines it calls:
  10.  */
  11. extern void error() ;
  12. extern FILE *search() ;
  13. extern integer scalewidth() ;
  14. extern void newraster() ;
  15. extern void TPSdf(), TPSdfe(), TPSdc(), TPSbop(), TPSeop(), texflush() ;
  16. /*
  17.  *   Here are the external variables we use:
  18.  */
  19. extern halfword *left, *right, *top ;
  20. extern TeXfontdesctype *TeXfonts[] ;
  21. extern real conv ;
  22. extern int curid ;
  23. extern char *tfmpath ;
  24. extern char lastfile[] ;
  25. /*
  26.  *   Our static variables:
  27.  */
  28. static FILE *tfmfile ; 
  29. /*
  30.  *   Tries to open a tfm file.  Returns true if found.
  31.  */
  32. Boolean tfmopen(tft)
  33. TeXfontdesctype *tft ;
  34. {
  35.    register char *d, *n ;
  36.  
  37.    n = tft->name ;
  38.    if (*n==0) {
  39.       n++ ;
  40.       d = tfmpath ;
  41.    } else {
  42.       d = n ;
  43.       while (*n) n++ ;
  44.    }
  45.    sprintf(lastfile, "%s.tfm", n) ;
  46.    tfmfile = search(d, lastfile) ;
  47.    if (tfmfile == 0) {
  48.       error(" couldn't find tfm file; substituting cmr10") ;
  49.       tfmfile = search(tfmpath, "cmr10.tfm") ;
  50.    }
  51.    return (tfmfile != NULL) ;
  52. }
  53. shalfword tfmbyte () {
  54.   return(getc(tfmfile)) ;
  55. }
  56. halfword tfm16 () {
  57. register halfword a ; 
  58.   a = tfmbyte () ; 
  59.   return ( a * 256 + tfmbyte () ) ; 
  60. integer tfm32 () {
  61. register integer a ; 
  62.   a = tfm16 () ; 
  63.   return ( (a << 16) + tfm16 () ) ; 
  64. void tfmload(tft, define)
  65. register TeXfontdesctype *tft ;
  66. int define ;
  67. {
  68.    register chardesctype *cdp ;
  69.    register shalfword i ;
  70.    register integer li ;
  71.    register fontdesctype *curfnt ;
  72.    integer scaledsize ;
  73.    shalfword nw, nh, nd, hd ;
  74.    shalfword bc, ec ;
  75.    integer scaled[300] ;
  76.    halfword chardat[256] ;
  77.    shalfword pixel[300] ;
  78.    int height, width, yoff ;
  79.    int *black ;
  80.    int bk ;
  81.  
  82.    bk = ~0 ;
  83.    black = &bk ;
  84.    curfnt = tft->loaded ;
  85.    if (!tfmopen(tft))
  86.       error("! could not open tfm file") ;
  87. /*
  88.  *   Next, we read the font data from the tfm file, and store it in
  89.  *   our own arrays.
  90.  */
  91.    li = tfm16() ; hd = tfm16() ;
  92.    bc = tfm16() ; ec = tfm16() ;
  93.    nw = tfm16() ; nh = tfm16() ; nd = tfm16() ;
  94.    li = tfm32() ; li = tfm32() ; li = tfm16() ;
  95.    scaledsize = tfm32() ;
  96. /* if (scaledsize-tft->checksum > 6 || -6 > scaledsize-tft->checksum) {
  97.        error("bad checksum in tfm file") ;
  98.    } */
  99.    li = tfm32() >> 4 ;
  100.    if (li > tft->designsize + 2 || li < tft->designsize - 2)
  101.       error("bad design size in tfm file") ;
  102.    for (i=2; i<hd; i++)
  103.       li = tfm32() ;
  104.    for (i=bc; i<=ec; i++) {
  105.       chardat[i] = tfm16() ;
  106.       li = tfm16() ;
  107.    }
  108.    scaledsize = tft->scaledsize ;
  109.    for (i=0; i<nw+nh+nd; i++) {
  110.      scaled[i] = tfm32() ;
  111.      if (scaled[i] >= 0)
  112.         pixel[i] = (conv * scalewidth(scaled[i], scaledsize) + 0.5) ;
  113.      else
  114.         pixel[i] = -(conv * scalewidth(-scaled[i], scaledsize) + 0.5) ;
  115.    }
  116.    fclose(tfmfile) ;
  117.    if (define) {
  118.       curfnt->id = curid++ ;
  119. #ifdef POPRESTORE
  120.       TPSeop() ;
  121. #endif
  122.       TPSdf(curfnt->id) ;
  123.     }
  124.    for (i=0, cdp = curfnt->chardesc; i<256; i++, cdp++) {
  125.       if (i>=bc && i<=ec) {
  126.          cdp = curfnt->chardesc + i ;
  127.          cdp->TFMwidth = scaled[chardat[i]>>8] ;
  128.          cdp->pixelwidth = pixel[chardat[i]>>8] ;
  129.          width = cdp->pixelwidth ;
  130.          yoff = pixel[((chardat[i]&240)>>4)+nw] ;
  131.          height = pixel[(chardat[i]&15)+nw+nh] + yoff ;
  132.          if (width <= 0)
  133.             width = 1 ;
  134.          if (height <= 0)
  135.             height = 1 ;
  136.          if (define)
  137.             TPSdc(black, 2, width, height, 0, height - yoff - 1, cdp->pixelwidth, i) ;
  138.       }
  139.    }
  140.    if (define) {
  141.       TPSdfe() ;
  142. #ifdef POPRESTORE
  143.       TPSbop() ;
  144. #else
  145.       texflush() ;
  146. #endif
  147.    }
  148. }
  149.