home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / printer / dvi2pcl.lha / prescanpage.c < prev    next >
C/C++ Source or Header  |  1992-11-25  |  4KB  |  154 lines

  1. /* $Log:    prescanpage.c,v $
  2.  * Revision 0.8  92/11/23  19:46:55  19:46:55  bt (Bo Thide')
  3.  * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support
  4.  * 
  5.  * Revision 0.7  92/11/13  02:41:40  02:41:40  bt (Bo Thide')
  6.  * More bug fixes and improvements. Support for PaintJet XL
  7.  * 
  8.  * Revision 0.6  92/11/10  21:48:37  21:48:37  bt (Bo Thide')
  9.  * Bug fixes. Added -R option. Better font handling.
  10.  * 
  11.  * Revision 0.5  92/11/09  16:25:43  16:25:43  bt (Bo Thide')
  12.  * Rewrite of dospecial.c. Extended \special support
  13.  * 
  14.  * Revision 0.4  92/11/08  02:46:00  02:46:00  bt (Bo Thide')
  15.  * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's.
  16.  * 
  17.  * Revision 0.3  92/08/24  12:43:21  12:43:21  bt (Bo Thide')
  18.  * Fixed 8 bit (dc font) support.
  19.  * 
  20.  * Revision 0.2  92/08/23  17:29:00  17:29:00  bt (Bo Thide')
  21.  * Source cleaned up.  Changed certain function calls.  Removed globals.
  22.  * 
  23.  * Revision 0.1  92/08/22  23:58:48  23:58:48  bt (Bo Thide')
  24.  * First Release.
  25.  *  */
  26.  
  27. /*
  28.  * This routine will scan a page from 'bop' to 'eop', maintaining information
  29.  * about font usage. It also catches errors like illegal font numbers or
  30.  * characters. Finally, it also counts the number of pages actually processed,
  31.  * so if the file is scanned backwards, it will end correctly.
  32.  */
  33.  
  34. #include <stdio.h>
  35. #include "dvi.h"
  36. #include "globals.h"
  37. #include "macros.h"
  38.  
  39. static char rcsid[] = "$Header: prescanpage.c,v 0.8 92/11/23 19:46:55 bt Exp $";
  40.  
  41. prescanpage(bitfile, dvifile, pcllevel, resolution)
  42. FILE    *bitfile;
  43. FILE    *dvifile;
  44. short    pcllevel, resolution;
  45. {
  46.   bool    badchar;
  47.   int    k;
  48.   int    q;
  49.   int    font_num;
  50.   int    font_used[MAXFONTS];
  51.   long    p;
  52.   long    hh=0L;                /* Pixel analog of DVI unit h */
  53.   long    vv=0L;                 /* Pixel analog of DVI unit v */
  54.  
  55.   actualpagecount++;
  56.  
  57.   for(k = 0 ; k < MAXFONTS ; k++)
  58.     font_used[k] = FALSE;
  59.   font_num = 0;
  60.  
  61.   while (TRUE){
  62.     if((k = (int)getubyte(dvifile)) < DVI_SET1)
  63.       (cbase + k)->use_count++;
  64.     else {
  65.       p = firstpar(dvifile, k);
  66.  
  67. #ifdef DEBUG2
  68.   fprintf(stderr,"\nprescanpage: p = %d,k = %d", p, k);
  69. #endif /* DEBUG2 */
  70.  
  71.       switch (k) {
  72.       case DVI_BOP:
  73.         scanbop(dvifile);
  74.         break;
  75.       case DVI_EOP:
  76.         goto end;
  77.         break;
  78.       case DVI_SET1:
  79.       case DVI_SET2:
  80.       case DVI_SET3:
  81.       case DVI_SET4:
  82.       case DVI_PUT1:
  83.       case DVI_PUT2:
  84.       case DVI_PUT3:
  85.       case DVI_PUT4:
  86.         if(p > 255)
  87.           prerror("Char > 255 encountered\n");
  88.         else
  89.           (cbase +  p)->use_count++;
  90.         break;
  91.       case DVI_SET_RULE:
  92.       case DVI_PUT_RULE:
  93.         getsquad(dvifile);
  94.         break;
  95.       case DVI_FNT_DEF1:
  96.       case DVI_FNT_DEF2:
  97.       case DVI_FNT_DEF3:
  98.       case DVI_FNT_DEF4:
  99.         definefont(dvifile, p);
  100.         break;
  101.       case DVI_XXX1:
  102.       case DVI_XXX2:
  103.       case DVI_XXX3:
  104.       case DVI_XXX4:
  105.         badchar = FALSE;
  106.         if(p + nextnamesfree  - names > NAMESIZE)
  107.           prerror("Out of string space during special\n");
  108.         for (k=0; k<(int)p; k++)
  109.         {
  110.           q = (int)getubyte(dvifile);
  111.           if((q < ' ') || (q > '~'))
  112.             badchar = TRUE;
  113.           *(nextnamesfree + k) = q;
  114.         }
  115.         *(nextnamesfree + p) = '\0';
  116.         if(badchar)
  117.           fprintf(stderr,"non-ASCII character in DVI_XXX command\n");
  118.         dospecial(bitfile, PRESCAN_ON, pcllevel, hh, vv, resolution);
  119.         break;
  120.       case DVI_POST:
  121.         inpostamble = TRUE;
  122.         goto end;
  123.         break;
  124.       default:
  125.         if((k >= DVI_FNT_NUM_0) && (k <= DVI_FNT4))
  126.         {
  127.           if(p > MAXFONTS)
  128.         valerror("Max number of allowed fonts is %3d\n", MAXFONTS);
  129.           else {
  130.             font = fontptr[p];
  131.             if(font == NULL)
  132.               prerror("Undefined font\n");
  133.             else {
  134.               cbase = font->chr;
  135.               if(!font_used[p]) {
  136.                 font_used[p] = TRUE;
  137.                 font_num++;
  138.               }
  139.             }
  140.           }
  141.         }
  142.         break;
  143.       }
  144.     }
  145.   }
  146. end:
  147.   if(font_num > 16)
  148.   {
  149.     fprintf(stderr,"Warning: ");
  150.     printbop(startvals, count);
  151.     fprintf(stderr,"prescanpage: %d [>16] fonts on page\n",font_num);
  152.   }
  153. }
  154.