home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / dvips549.zip / DVIPS / TFMLOAD.C < prev    next >
C/C++ Source or Header  |  1992-10-14  |  3KB  |  137 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. 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.    (void)sprintf(name, "%s.tfm", n) ;
  41.    if ((tfmfile=search(d, name, READBIN))==NULL) {
  42.       (void)sprintf(errbuf, "Can't open font metric file %s%s",
  43.              fd->area, name) ;
  44.       error(errbuf) ;
  45.       error("I will use cmr10.tfm instead, so expect bad output.") ;
  46.       if ((tfmfile=search(d, "cmr10.tfm", READBIN))==NULL)
  47.          error(
  48.           "! I can't find cmr10.tfm; please reinstall me with proper paths") ;
  49.    }
  50. }
  51.  
  52. shalfword
  53. tfmbyte ()
  54. {
  55.   return(getc(tfmfile)) ;
  56. }
  57.  
  58. halfword
  59. tfm16 ()
  60. {
  61.   register halfword a ; 
  62.   a = tfmbyte () ; 
  63.   return ( a * 256 + tfmbyte () ) ; 
  64.  
  65. integer
  66. tfm32 ()
  67. {
  68.   register integer a ; 
  69.   a = tfm16 () ; 
  70.   if (a > 32767) a -= 65536 ;
  71.   return ( a * 65536 + tfm16 () ) ; 
  72.  
  73. int
  74. tfmload(curfnt)
  75.         register fontdesctype *curfnt ;
  76. {
  77.    register shalfword i ;
  78.    register integer li ;
  79.    integer scaledsize ;
  80.    shalfword nw, hd ;
  81.    shalfword bc, ec ;
  82.    integer scaled[256] ;
  83.    halfword chardat[256] ;
  84.    int charcount = 0 ;
  85.  
  86.    tfmopen(curfnt) ;
  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() ;
  94.    li = tfm32() ; li = tfm32() ; li = tfm32() ; li = tfm16() ;
  95.    li = tfm32() ;
  96.    if (li && curfnt->checksum)
  97.       if (li!=curfnt->checksum) {
  98.          (void)sprintf(errbuf,"Checksum mismatch in %s", name) ;
  99.          error(errbuf) ;
  100.        }
  101.    li = (integer)(alpha * (real)tfm32()) ;
  102.    if (li > curfnt->designsize + fsizetol ||
  103.        li < curfnt->designsize - fsizetol) {
  104.       (void)sprintf(errbuf,"Design size mismatch in %s", name) ;
  105.       error(errbuf) ;
  106.    }
  107.    for (i=2; i<hd; i++)
  108.       li = tfm32() ;
  109.    for (i=0; i<256; i++)
  110.       chardat[i] = 256 ;
  111.    for (i=bc; i<=ec; i++) {
  112.       chardat[i] = tfmbyte() ;
  113.       li = tfm16() ;
  114.       li |= tfmbyte() ;
  115.       if (li || chardat[i])
  116.          charcount++ ;
  117.    }
  118.    scaledsize = curfnt->scaledsize ;
  119.    for (i=0; i<nw; i++)
  120.       scaled[i] = scalewidth(tfm32(), scaledsize) ;
  121.    (void)fclose(tfmfile) ;
  122.    for (i=0; i<256; i++)
  123.       if (chardat[i]!= 256) {
  124.          li = scaled[chardat[i]] ;
  125.          curfnt->chardesc[i].TFMwidth = li ;
  126.          if (li >= 0)
  127.             curfnt->chardesc[i].pixelwidth = ((integer)(conv*li+0.5)) ;
  128.          else
  129.             curfnt->chardesc[i].pixelwidth = -((integer)(conv*-li+0.5)) ;
  130.          curfnt->chardesc[i].flags = (curfnt->resfont ? EXISTS : 0) ;
  131.       }
  132.    curfnt->loaded = 1 ;
  133.    return charcount ;
  134. }
  135.