home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fonts 1 / freshfonts1.bin / bbs / programs / amiga / pastex13.lha / DVIPS / dvips5519.lha / dvips / loadfont.c.bak < prev    next >
Text File  |  1993-09-04  |  14KB  |  479 lines

  1. /*
  2.  *   Here's the code to load a PK file into memory.
  3.  *   Individual bitmaps won't be unpacked until they prove to be needed.
  4.  */
  5. #include "dvips.h" /* The copyright notice in that file is included too! */
  6. /*
  7.  *   These are the external routines we use.
  8.  */
  9. extern void makefont() ;
  10. extern void error() ;
  11. extern integer scalewidth() ;
  12. extern int tfmload() ;
  13. extern FILE *pksearch() ;
  14. /*
  15.  *   These are the external variables we use.
  16.  */
  17. #ifdef DEBUG
  18. extern integer debug_flag;
  19. #endif  /* DEBUG */
  20. extern long bytesleft ;
  21. extern quarterword *raster ;
  22. extern real conv ;
  23. extern int actualdpi, vactualdpi ;
  24. extern real alpha ;
  25. extern char *pkpath ;
  26. char errbuf[200] ;
  27. int lastresortsizes[40] ;
  28. extern integer fsizetol ;
  29. extern Boolean nosmallchars ;
  30. extern Boolean compressed ;
  31. extern Boolean dopprescan ;
  32. #ifdef FONTLIB
  33. extern Boolean flib ;
  34. extern FILE *flisearch() ;
  35. #endif
  36. /*
  37.  *   Now we have some routines to get stuff from the PK file.
  38.  *   Subroutine pkbyte returns the next byte.
  39.  */
  40. FILE *pkfile ;
  41. char name[50] ;
  42. void
  43. badpk(s)
  44.    char *s ;
  45. {
  46.    (void)sprintf(errbuf,"! Bad PK file %s: %s",name,s) ;
  47.    error(errbuf);
  48. }
  49.  
  50. shalfword
  51. pkbyte()
  52. {
  53.    register shalfword i ;
  54.  
  55.    if ((i=getc(pkfile))==EOF)
  56.       badpk("unexpected eof") ;
  57.    return(i) ;
  58. }
  59.  
  60. integer
  61. pkquad()
  62. {
  63.    register integer i ;
  64.  
  65.    i = pkbyte() ;
  66.    if (i > 127)
  67.       i -= 256 ;
  68.    i = i * 256 + pkbyte() ;
  69.    i = i * 256 + pkbyte() ;
  70.    i = i * 256 + pkbyte() ;
  71.    return(i) ;
  72. }
  73.  
  74. integer
  75. pktrio()
  76. {
  77.    register integer i ;
  78.  
  79.    i = pkbyte() ;
  80.    i = i * 256 + pkbyte() ;
  81.    i = i * 256 + pkbyte() ;
  82.    return(i) ;
  83. }
  84.  
  85.  
  86. /*
  87.  *   pkopen opens the pk file.  This is system dependent.  We work really
  88.  *   hard to open some sort of PK file.
  89.  */
  90. #ifdef VMCMS /* IBM: VM/CMS - we let DVIPS EXEC handle this after
  91.                              the DVIPS MODULE has finished to avoid
  92.                              complications with system calls. */
  93. int dontmakefont = 0 ;
  94. #else
  95. #ifdef MVSXA /* IBM: MVS/XA - we let system administrator handle this on
  96.                             MVS/XA since some printers can't get to user
  97.                              fonts anyway */
  98. int dontmakefont = 1 ;
  99. #else
  100. int dontmakefont = 0 ; /* if makefont fails once we won't try again */
  101. #endif  /* IBM: VM/CMS */
  102. #endif
  103.  
  104. void
  105. lectureuser() {
  106.    static int userwarned = 0 ;
  107.  
  108.    if (! userwarned) {
  109.       error("Such scaling will generate extremely poor output.") ;
  110.       userwarned = 1 ;
  111.    }
  112. }
  113. Boolean
  114. pkopen(fd)
  115.         register fontdesctype *fd ;
  116. {
  117.    register char *d, *n ;
  118.    int vdpi ;
  119.  
  120.    d = fd->area ;
  121.    n = fd->name ;
  122.    if (*d==0)
  123.       d = pkpath ;
  124. #ifdef FONTLIB
  125.    if (*(fd->area) == 0) {
  126.       int del ;
  127.       for (del=0; del<=RES_TOLERANCE(fd->dpi); del=del>0?-del:-del+1) {
  128.         if ((pkfile=flisearch(n, fd->dpi + del)) != (FILE *)NULL )
  129.           return(1);
  130.       }
  131.    }
  132. #endif
  133.    {
  134.       int del ;
  135.       for (del=0; del<=RES_TOLERANCE(fd->dpi); del=del>0?-del:-del+1) {
  136.          if (actualdpi == vactualdpi) {
  137.             vdpi = 0 ;
  138.          } else {
  139.             vdpi = (2 * ((long)vactualdpi) * (fd->dpi + del) + actualdpi)
  140.                                                        / (2 * actualdpi) ;
  141.          }
  142. #ifdef MVSXA
  143.          (void)sprintf(name, "pk%d(%s)", fd->dpi + del, n) ;
  144. #else
  145. #ifdef AMIGA
  146.          (void)sprintf(name, "%d/%s.%dpk", fd->dpi + del, n, fd->dpi + del) ;
  147. #else
  148.          (void)sprintf(name, "%s.%dpk", n, fd->dpi + del) ;
  149. #endif
  150. #endif
  151.          if (0 != (pkfile=pksearch(d, name, READBIN, n, fd->dpi + del, vdpi)))
  152.             return(1) ;
  153.       }
  154.    }
  155.    if (d == pkpath) {
  156.       if (actualdpi == vactualdpi) {
  157.          vdpi = 0 ;
  158.       } else {
  159.          vdpi = (2 * ((long)vactualdpi) * fd->dpi + actualdpi)
  160.                                                     / (2 * actualdpi) ;
  161.       }
  162. #ifdef MVSXA
  163.       (void)sprintf(name, "pk%d(%s)", fd->dpi, n) ;
  164. #else
  165. #ifdef AMIGA
  166.       (void)sprintf(name, "%d/%s.%dpk", fd->dpi, n, fd->dpi) ;
  167. #else
  168.       (void)sprintf(name, "%s.%dpk", n, fd->dpi) ;
  169. #endif
  170. #endif
  171.       makefont(n, (int)fd->dpi, DPI) ;
  172.       if (dontmakefont == 0 &&
  173.           (pkfile = pksearch(d, name, READBIN, n, fd->dpi, vdpi)))
  174.                return(1) ;
  175. #ifndef MSDOS
  176. #ifndef AMIGA
  177.       dontmakefont = 1 ;
  178. #endif
  179. #endif
  180.    }
  181. /*
  182.  *   If nothing above worked, then we get desparate.  We attempt to
  183.  *   open the stupid font at one of a small set of predefined sizes,
  184.  *   and then use PostScript scaling to generate the correct size.
  185.  *
  186.  *   We much prefer scaling up to scaling down, since scaling down
  187.  *   can omit character features, so we try the larger sizes first,
  188.  *   and then work down.
  189.  */
  190.    {
  191.       int i, j ;
  192.  
  193.       if (lastresortsizes[0] && fd->dpi < 30000) {
  194.          for (i=0; lastresortsizes[i] < fd->dpi; i++) ;
  195.          for (j = i-1; j >= 0; j--) {
  196.             if (actualdpi == vactualdpi) {
  197.                vdpi = 0 ;
  198.             } else {
  199.                vdpi = (2 * ((long)vactualdpi) * lastresortsizes[j] + actualdpi)
  200.                                                        / (2 * actualdpi) ;
  201.             }
  202. #ifdef MVSXA
  203.             (void)sprintf(name, "pk%d(%s)", lastresortsizes[j], n) ;
  204. #else
  205. #ifdef AMIGA
  206.             (void)sprintf(name, "%d/%s.%dpk", lastresortsizes[j], n, lastresortsizes[j]) ;
  207. #else
  208.             (void)sprintf(name, "%s.%dpk", n, lastresortsizes[j]) ;
  209. #endif
  210. #endif
  211. #ifdef FONTLIB
  212.             if (0 != (pkfile=flisearch(n,(halfword)lastresortsizes[j]))
  213.              || 0 != (pkfile=pksearch(d, name, READBIN, n,
  214.                          (halfword)lastresortsizes[j], vdpi))) {
  215. #else
  216.             if (0 != (pkfile=pksearch(d, name, READBIN, n,
  217.                          (halfword)lastresortsizes[j], vdpi))) {
  218. #endif
  219.                fd->loadeddpi = lastresortsizes[j] ;
  220.                fd->alreadyscaled = 0 ;
  221.                (void)sprintf(errbuf,
  222.                        "Font %s at %d not found; scaling %d instead.",
  223.                                          name, fd->dpi, lastresortsizes[j]) ;
  224.                error(errbuf) ;
  225.                lectureuser() ;
  226.                return 1 ;
  227.             }
  228.          }
  229.          for (j = i; lastresortsizes[j] < 30000; j++) {
  230.             if (actualdpi == vactualdpi) {
  231.                vdpi = 0 ;
  232.             } else {
  233.                vdpi = (2 * ((long)vactualdpi) * lastresortsizes[j] + actualdpi)
  234.                                                        / (2 * actualdpi) ;
  235.             }
  236. #ifdef AMIGA
  237.             (void)sprintf(name, "%d/%s.%dpk", lastresortsizes[j], n, lastresortsizes[j]) ;
  238. #else
  239.             (void)sprintf(name, "%s.%dpk", n, lastresortsizes[j]) ;
  240. #endif
  241. #ifdef FONTLIB
  242.             if (0 != (pkfile=flisearch(n, (halfword)lastresortsizes[j]))
  243.                 || 0 != (pkfile=pksearch(d, name, READBIN, n,
  244.                              (halfword)lastresortsizes[j], vdpi))) {
  245. #else
  246.             if (0 != (pkfile=pksearch(d, name, READBIN, n,
  247.                             (halfword)lastresortsizes[j], vdpi))) {
  248. #endif
  249.                fd->loadeddpi = lastresortsizes[j] ;
  250.                fd->alreadyscaled = 0 ;
  251.                (void)sprintf(errbuf,
  252.                        "Font %s at %d not found; scaling %d instead.",
  253.                                          name, fd->dpi, lastresortsizes[j]) ;
  254.                error(errbuf) ;
  255.                lectureuser() ;
  256.                return 1 ;
  257.             }
  258.          }
  259.       }
  260.    }
  261. #ifdef MVSXA
  262.    (void)sprintf(name, "%s.pk%d", n, fd->dpi) ;
  263. #else
  264.    (void)sprintf(name, "%s.%dpk", n, fd->dpi) ;
  265. #endif
  266.    (void)sprintf(errbuf,
  267.       "Font %s%s not found, characters will be left blank.",
  268.       fd->area, name) ;
  269.    error(errbuf) ;
  270.    return(0) ;
  271. }
  272.  
  273. /*
  274.  *   Now our loadfont routine.  We return an integer indicating the
  275.  *   highest character code in the font, so we know how much space
  276.  *   to reserve for the character.  (It's returned in the font
  277.  *   structure, along with everything else.)
  278.  */
  279. void
  280. loadfont(curfnt)
  281.         register fontdesctype *curfnt ;
  282. {
  283.    register shalfword i ;
  284.    register shalfword cmd ;
  285.    register integer k ;
  286.    register integer length = 0 ;
  287.    register shalfword cc = 0 ;
  288.    register integer scaledsize = curfnt->scaledsize ;
  289.    register quarterword *tempr ;
  290.    register chardesctype *cd = 0 ;
  291.    int maxcc = 0 ;
  292.    int mun