home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2096 / pkc.c < prev   
Encoding:
C/C++ Source or Header  |  1990-12-28  |  5.6 KB  |  245 lines

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