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

  1. /* $Log:    definefont.c,v $
  2.  * Revision 0.8  92/11/23  19:46:38  19:46:38  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:22  02:41:22  bt (Bo Thide')
  6.  * More bug fixes and improvements. Support for PaintJet XL
  7.  * 
  8.  * Revision 0.6  92/11/10  21:47:38  21:47:38  bt (Bo Thide')
  9.  * Bug fixes. Added -R option. Better font handling.
  10.  * 
  11.  * Revision 0.5  92/11/09  16:25:25  16:25:25  bt (Bo Thide')
  12.  * Rewrite of dospecial.c. Extended \special support
  13.  * 
  14.  * Revision 0.4  92/11/08  02:45:40  02:45:40  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:18  12:43:18  bt (Bo Thide')
  18.  * Fixed 8 bit (dc font) support.
  19.  * 
  20.  * Revision 0.2  92/08/23  17:28:55  17:28:55  bt (Bo Thide')
  21.  * Source cleaned up.  Changed certain function calls.  Removed globals.
  22.  * 
  23.  * Revision 0.1  92/08/22  23:58:47  23:58:47  bt (Bo Thide')
  24.  * First Release.
  25.  *  */
  26.  
  27. /*
  28.  * This subroutine does the necessary things when a 'FNT_DEF' command is
  29.  * being processed.
  30.  */
  31.  
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include "globals.h"
  35. #include "macros.h"
  36.  
  37. static char rcsid[] = "$Header: definefont.c,v 0.8 92/11/23 19:46:38 bt Exp $";
  38.  
  39. void definefont(dvifile, f)
  40. FILE    *dvifile;
  41. int    f;
  42. {
  43.     static  int knownsize[] = {1,90,130,150,180,210,240,270,300,329,360,
  44.                    394,432,473,518,568,622,681,746,818,896,981,
  45.                    1075,1178,1290,1413,1548,1858,2035,2229,2442,
  46.                    2675,10000};
  47.     int    k;
  48.     int    a,l;        /* Font definition parameters */
  49.     fontfmt    *safefont;
  50.     charfmt    *u;
  51.     int    *known;
  52.     int    idealmag;
  53.     double    s;
  54.  
  55.     if(!inpostamble)
  56.     { 
  57.         if(f >= MAXFONTS)
  58.             valerror("Max number of allowed fonts is %3d\n",
  59.               MAXFONTS);
  60.         if(fontptr[f] != 0)
  61.             valerror("Font number %d already defined\n", f);
  62.         safefont = font;
  63.         font = (fontfmt *)malloc(sizeof(*font));
  64.         fontptr[f] = font;
  65.         font->checksum = getsquad(dvifile);
  66.         font->scaled_size = getsquad(dvifile);
  67.         font->design_size = getsquad(dvifile);
  68.         a = (int)getubyte(dvifile);
  69.         l = (int)getubyte(dvifile);
  70.         if((nextnamesfree-names+a+l+2) > NAMESIZE)
  71.             valerror("Capacity exceeded (name size=%d)\n",NAMESIZE);
  72.         font->name = nextnamesfree - names;
  73.         if(verbose)
  74.             fprintf(stderr,"Font %d: ", f);
  75.  
  76.         for(k=0; k<a; k++)
  77.             *nextnamesfree++ = getubyte(dvifile);
  78.         *nextnamesfree++ = '\0';
  79.  
  80.         for(k=0; k<l; k++)
  81.             *nextnamesfree++ = getubyte(dvifile);
  82.         *nextnamesfree++ = '\0';
  83.  
  84.         u = font->chr;
  85.         for(k=0; k<=255; k++) { 
  86.             u->use_count = 0;
  87.             u++;
  88.         }
  89.  
  90.         font->space = font->design_size / 6;
  91.         font->down  = -3;
  92.         if(verbose)
  93.             printfont();
  94.         idealmag = round((double)font->scaled_size/(double)font->design_size*magnification*RESOLUTION*0.001);
  95.         if((idealmag < 10) || (idealmag > 9999))
  96.             valerror("Font dpi size %d unrealistic\n", idealmag);
  97.         known = knownsize;
  98.         while(*known < idealmag) known++;
  99.         if(((double) *known/idealmag) > ((double)idealmag/(*(known-1))))
  100.             known--;
  101.         s = (double) *known/idealmag;
  102.         if((s > 1.02) || (s < 0.98))
  103.             fprintf(stderr,"Warning: Size %d does not exist; substituting %d.\n",
  104.                 idealmag, *known);
  105.         font->dir_size = *known;
  106.         font = safefont;
  107.  
  108.     }
  109. }
  110.