home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume24 / psroff3.0 / part14 / pkc.c < prev    next >
C/C++ Source or Header  |  1991-10-09  |  6KB  |  243 lines

  1. /*
  2.     Copyright 1985, 1986, 1987, 1988, 1989, 1990, 1991 Chris Lewis
  3.         All Rights Reserved
  4.  
  5.     See the LICENSE file for a full description of restrictions under which
  6.     this software is provided.
  7.  
  8.     Function:        PK Cache - handles incremental downloading for
  9.             laserjets
  10.  
  11. */
  12.  
  13. #include "defs.h"
  14.  
  15. #if    defined(PARTIAL) || defined(INCR)
  16.  
  17. #ifndef    lint
  18. static char SCCSid[] =
  19.     "@(#)pkc.c: 2.2 Copyright 91/02/20 09:06:57 Chris Lewis";
  20. #endif
  21.  
  22. #include "pk.h"
  23.  
  24. #include "pkc.h"
  25.  
  26. extern int fontCount;
  27.  
  28. /*    Does the font *need* this character? */
  29. extern struct needmaps *needmaps;
  30.  
  31. needchar(font, ch)
  32. register int font;
  33. register long ch; {
  34.     register struct needmaps *nbp;
  35.  
  36.     ch &= 0xff;
  37.  
  38.     if (ch <= ' ' || (ch > 0x7f && ch <= (0x80 + ' ')))
  39.     return(0);
  40.     ch -= ' ';
  41.     if (ch >= 0x80 - ' ')
  42.     ch -= ' ';
  43.  
  44.     if (font >= 0 && font <= 2)    /* redirections to NORM fonts */
  45.     font = N;
  46.     else if (font == 3)        /* redirections to SYMBOL font */
  47.     font = S;
  48.  
  49.     for (nbp = needmaps; nbp; nbp = nbp->next)
  50.     if (nbp->fontnum == font) {
  51.         return(nbp->NMAP(ch / ELEN) & (1 << (ch % ELEN)));
  52.     }
  53.     return(0);
  54. }
  55.  
  56.  
  57. addneedchar(font, ch)
  58. register int font, ch; {
  59.     register struct needmaps *nbp, *onbp = (struct needmaps *) NULL;
  60.     ch &= 0xff;
  61.  
  62.     if (ch <= ' ' || (ch > 0x7f && ch <= (0x80 + ' ')))
  63.     return;
  64.     ch -= ' ';
  65.     if (ch >= 0x80 - ' ')
  66.     ch -= ' ';
  67.  
  68.     if (font >= 0 && font <= 2)    /* redirections to NORM fonts */
  69.     font = N;
  70.     else if (font == 3)        /* redirections to SYMBOL font */
  71.     font = S;
  72.  
  73.     for (onbp = (struct needmaps *) NULL, nbp = needmaps;
  74.     nbp; onbp = nbp, nbp = nbp->next)
  75.  
  76.     if (nbp->fontnum == font)
  77.         break;
  78.  
  79.     if (!nbp) {
  80.     nbp = (struct needmaps *) mustmalloc(sizeof(struct needmaps),
  81.         "needmaps");
  82.     nbp->fontnum = font;
  83.     if (!onbp)
  84.         needmaps = nbp;
  85.     else
  86.         onbp->next = nbp;
  87.     }
  88.     if (ch == -1)
  89.     return;
  90.     nbp->NMAP(ch / ELEN) |= (1 << (ch % ELEN));
  91. }
  92.  
  93. #endif
  94.  
  95. #ifdef    INCR
  96. downchar(font, ch, pointidx)
  97. int font, ch, pointidx; {
  98.     ch &= 0xff;
  99.     if (ch <= ' ' || (ch > 0x7f && ch <= (0x80 + ' ')))
  100.     return(0);
  101.     ch -= ' ';
  102.     if (ch >= 0x80 - ' ')
  103.     ch -= ' ';
  104.     return(fonttable[font].map->DMAP(ch / ELEN, pointidx) &
  105.     (1 << (ch % ELEN)));
  106. }
  107.  
  108. setdown(font, ch, pointidx)
  109. int font, ch, pointidx; {
  110.     ch &= 0xff;
  111.     if (ch <= ' ' || (ch > 0x7f && ch <= (0x80 + ' ')))
  112.     return;
  113.     ch -= ' ';
  114.     if (ch >= 0x80 - ' ')
  115.     ch -= ' ';
  116.     fonttable[font].map->DMAP(ch / ELEN, pointidx) |= (1 << (ch % ELEN));
  117.     fonttable[font].map->lastpage[pointidx] = currentPage;
  118. }
  119. #endif
  120.  
  121. #if    defined(DEBUG) && defined(PARTIAL)
  122. dumppartmaps() {
  123.     register struct needmaps *nbp;
  124.     register int c;
  125.     fprintf(diagFile,"MASKLEN: %d, ELEN: %d\n", MASKLEN, ELEN);
  126.     for (nbp = needmaps; nbp; nbp = nbp->next) {
  127.     fprintf(diagFile,"Font: %02x, needmap:", nbp->fontnum);
  128.     for (c = 0; c < MASKLEN; c++)
  129.         fprintf(diagFile," %08x", nbp->NMAP(c));
  130.     fprintf(diagFile,"\n");
  131.     }
  132. }
  133.  
  134. #ifdef    INCR
  135. dumpincrmaps() {
  136.     static char ptsizes[] =
  137.      {6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 28, 36};
  138.     register struct downmaps *dbp;
  139.     register int c, p, fn;
  140.     fprintf(diagFile,"MASKLEN: %d, ELEN: %d\n", MASKLEN, ELEN);
  141.     for (fn = 0; fonttable[fn].troffName; fn++) {
  142.     dbp = fonttable[fn].map;
  143.     if (!dbp)
  144.         continue;
  145.     fprintf(diagFile,"Font: %02x, troffname: %s, downloadedmaps:\n",
  146.         fn, fonttable[fn].troffName);
  147.     for (p = 0; p < NPTSIZE; p++) {
  148.         if (!dbp->nm[p])
  149.         continue;
  150.         fprintf(diagFile,"f%02d p%02d:%02d lp%d %s:", fn, p,
  151.         ptsizes[p], dbp->lastpage[p], dbp->pkfont[p] ? "load": "unlo");
  152.         for (c = 0; c < MASKLEN; c++)
  153.         fprintf(diagFile," %08x", dbp->DMAP(c,p));
  154.         fprintf(diagFile,"\n");
  155.     }
  156.     }
  157. }
  158. #endif
  159.  
  160. dumpmaps(which)
  161. int which; {
  162.     DBP((D_FONT,"dumpmaps: %d\n", which));
  163.     if (diagFile && (debug&D_FONT)) {
  164.     switch(which) {
  165.         case 0: dumppartmaps(); break;
  166. #ifdef    INCR
  167.         case 1: dumpincrmaps(); break;
  168. #endif
  169.     }
  170.     }
  171. }
  172.  
  173. #endif
  174.  
  175. #ifdef    INCR
  176. /*    Go find "oldest" font and delete it, both internally *and*
  177.     on the printer.  It cannot already be in use on this page.
  178.  */
  179. pkflush(needfont, needpoint)
  180. int needfont, needpoint; {
  181.     register int oldestpage = 32767, p;
  182.     int bestpoints, bestfont;
  183.     register struct downmaps *dbp;
  184.     int font;
  185.  
  186.     DBP((D_FONT, "Flushing font - avoid font %d, ps: %d\n",
  187.     needfont, needpoint));
  188.  
  189.     for (font = 0; fonttable[font].troffName; font++) {
  190.  
  191.     if (!(dbp = fonttable[font].map))
  192.         continue;
  193.  
  194.     for (p = 0; p < NPTSIZE; p++) {
  195.         if (!dbp->pkfont[p] || (font == needfont && needpoint == p))
  196.         continue;
  197.  
  198.         /* if font in use, and less than oldest page */
  199.         DBP((D_FONT, "Checking font %d, point: %d, lastpage: %d\n",
  200.         font, p, dbp->lastpage[p]));
  201.  
  202.         if (dbp->lastpage[p] && dbp->lastpage[p] < oldestpage) {
  203.         oldestpage = dbp->lastpage[p];
  204.         bestpoints = p;
  205.         bestfont = font;
  206.         }
  207.     }
  208.     }
  209.  
  210.     /* oh-oh! */
  211.     if (oldestpage >= currentPage) {
  212.  
  213.     fprintf(stderr, "Too many fonts on page %d, SIMPLIFY!\n", currentPage);
  214.  
  215.     } else {
  216.     dbp = fonttable[bestfont].map;
  217.  
  218.     DBP((D_FONT, "Dismembering font %d, pointidx: %d, p: %x\n", bestfont,
  219.         bestpoints, dbp->pkfont[bestpoints]));
  220.  
  221.     /* Clobber PK */
  222.     pk_destroy(dbp->pkfont[bestpoints]);
  223.  
  224.     /* Clobber PK pointer */
  225.     dbp->pkfont[bestpoints] = (struct pkp *) NULL;
  226.  
  227.     /* clear downloaded arrays */
  228.     clrarray((char*) &dbp->DMAP(0,bestpoints), MASKLEN * sizeof(ETYP));
  229.  
  230.     /* reset lastpage */
  231.     dbp->lastpage[bestpoints] = 0;
  232.  
  233.     /* tell backend that this font isn't downloaded anymore */
  234.     fonttable[bestfont].fontFlags[bestpoints] =
  235.         tolower(fonttable[bestfont].fontFlags[bestpoints]);
  236.  
  237.     fontCount--;
  238.     /* Select and nuke downloaded font */
  239.     printf("\033*c%dd2F", (bestfont << 4) + bestpoints);
  240.     }
  241. }
  242. #endif
  243.