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

  1. /* $Log:    downloadfont.c,v $
  2.  * Revision 0.8  92/11/23  19:46:43  19:46:43  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:27  02:41:27  bt (Bo Thide')
  6.  * More bug fixes and improvements. Support for PaintJet XL
  7.  * 
  8.  * Revision 0.6  92/11/10  21:47:44  21:47:44  bt (Bo Thide')
  9.  * Bug fixes. Added -R option. Better font handling.
  10.  * 
  11.  * Revision 0.5  92/11/09  16:25:31  16:25:31  bt (Bo Thide')
  12.  * Rewrite of dospecial.c. Extended \special support
  13.  * 
  14.  * Revision 0.4  92/11/08  02:45:46  02:45:46  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:45:38  12:45:38  bt (Bo Thide')
  18.  * Fixed 8 bit (dc font) support.
  19.  * 
  20.  * Revision 0.2  92/08/23  17:28:56  17:28:56  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. #include <math.h>
  28. #include <stdio.h>
  29. #include "globals.h"
  30. #include "macros.h"
  31. #include "pcl.h"
  32.  
  33. static char rcsid[] = "$Header: downloadfont.c,v 0.8 92/11/23 19:46:43 bt Exp $";
  34.  
  35. /*  Download a font to the printer */
  36. long downloadfont(bitfile, permfontsdown, device)
  37. FILE    *bitfile;
  38. int    permfontsdown;
  39. short    device;
  40. {
  41.     int    i;
  42.     int    depth;
  43.     int    max_depth;
  44.     int    max_width;
  45.     int    max_offset;
  46.     long    memreq;
  47.     double    fh4;
  48.     
  49.     max_depth = max_width = max_offset = 0;
  50.     memreq = 4;
  51.  
  52.     /* Specify font ID = nextfontdown and download each character */
  53.     fprintf(bitfile, PCL4_FONT_ID, font->down=nextfontdown--, fd.size);
  54.  
  55.     if(verbose)
  56.         fprintf(stderr,"Downloading %d...\n",font->down);
  57.  
  58.     for(i = font->bc ; i <= font->ec ; i++)
  59.         if((cbase + i)->use_count) { 
  60.             pkcharinfo(i);
  61.             if(c_voffset > max_offset) max_offset = c_voffset;
  62.             if((depth = c_height-c_voffset) > max_depth)
  63.               max_depth = depth;
  64.             if(c_width > max_width) max_width = c_width;
  65.         }
  66.  
  67.  
  68.     /* Determine the font descriptor values */
  69.     fd.size = 64;
  70.     fd.descriptor = 0;
  71.     if(device == DEV_LJPLUS)
  72.         fd.font_type = 1;
  73.     else
  74.         fd.font_type = 2;
  75.     fd.style_MSB = 0;
  76.     fd.reserved = 0;
  77.     fd.baseline = (ushort)max_offset;
  78.     fd.cell_width = (ushort)(max_width?max_width:1);
  79.     fd.cell_height = (ushort)(max_depth?max_offset+max_depth:max_offset+1);
  80.     fd.orientation = (ubyte)(landscape ? 1 : 0);
  81.     fd.spacing = 1;
  82.     fd.symbol_set = (ushort)(DYNAMICFONTBASE-nextfontdown-permfontsdown)<<5;
  83.     fd.pitch = fd.cell_width << 2;
  84.     fh4 = 4.0*font->height;            /* Temp variable */
  85.     fd.height = (ushort)fh4;
  86.     pkcharinfo('x');               /* Get global values for 'x' */
  87.     fd.x_height = (ushort)c_height;        /* c_height is for 'x' here! */
  88.     fd.width_type = 0;
  89.     fd.style_LSB = 0;
  90.     fd.stroke_weight = 0;
  91.     fd.typeface_LSB = 0;
  92.     fd.typeface_MSB = 0;
  93.         fd.serif_style = 128;    /* Serif */
  94.         fd.quality = 0;
  95.         fd.placement = 0;
  96.     fd.underl_dist = (byte)-max_depth;
  97.         fd.underl_height = 0;
  98.     fd.text_height = fd.cell_height << 2;
  99.     fd.text_width = fd.cell_width << 2;
  100.         fd.first_code = 1;
  101.         fd.last_code = 255;
  102.         fd.pitch_ext = 0;
  103.     fd.height_ext = (ushort)(1024*(fh4 - fd.height));
  104.         fd.cap_height = 0;
  105.         fd.font_number = 0;
  106.         strcpy(fd.font_name,"-TeX dvi font-");
  107.  
  108. #ifdef DEBUG2
  109. fprintf(stderr,"downloadfont: fd.size = %d\n", fd.size);
  110. fprintf(stderr,"downloadfont: fd.descriptor = %d\n", fd.descriptor);
  111. fprintf(stderr,"downloadfont: fd.font_type = %d\n", fd.font_type);
  112. fprintf(stderr,"downloadfont: fd.style_MSB = %d\n", fd.style_MSB);
  113. fprintf(stderr,"downloadfont: fd.reserved = %d\n", fd.reserved);
  114. fprintf(stderr,"downloadfont: fd.baseline = %d\n", fd.baseline);
  115. fprintf(stderr,"downloadfont: fd.cell_width = %d\n", fd.cell_width);
  116. fprintf(stderr,"downloadfont: fd.cell_height = %d\n", fd.cell_height);
  117. fprintf(stderr,"downloadfont: fd.orientation = %d\n", fd.orientation);
  118. fprintf(stderr,"downloadfont: fd.spacing = %d\n", fd.spacing);
  119. fprintf(stderr,"downloadfont: fd.symbol_set = %d\n", fd.symbol_set);
  120. fprintf(stderr,"downloadfont: fd.pitch = %d\n", fd.pitch);
  121. fprintf(stderr,"downloadfont: fd.height = %d\n", fd.height);
  122. fprintf(stderr,"downloadfont: fd.x_height = %d\n", fd.x_height);
  123. fprintf(stderr,"downloadfont: fd.width_type = %d\n", fd.width_type);
  124. fprintf(stderr,"downloadfont: fd.style_LSB = %d\n", fd.style_LSB);
  125. fprintf(stderr,"downloadfont: fd.stroke_weight = %d\n", fd.stroke_weight);
  126. fprintf(stderr,"downloadfont: fd.typeface_LSB = %d\n", fd.typeface_LSB);
  127. fprintf(stderr,"downloadfont: fd.typeface_MSB = %d\n", fd.typeface_MSB);
  128. fprintf(stderr,"downloadfont: fd.serif_style = %d\n", fd.serif_style);
  129. fprintf(stderr,"downloadfont: fd.quality = %d\n", fd.quality);
  130. fprintf(stderr,"downloadfont: fd.placement = %d\n", fd.placement);
  131. fprintf(stderr,"downloadfont: fd.underl_dist = %d\n", fd.underl_dist);
  132. fprintf(stderr,"downloadfont: fd.underl_height = %d\n", fd.underl_height);
  133. fprintf(stderr,"downloadfont: fd.text_height = %d\n", fd.text_height);
  134. fprintf(stderr,"downloadfont: fd.text_width = %d\n", fd.text_width);
  135. fprintf(stderr,"downloadfont: fd.first_code = %d\n", fd.first_code);
  136. fprintf(stderr,"downloadfont: fd.last_code = %d\n", fd.last_code);
  137. fprintf(stderr,"downloadfont: fd.pitch_ext = %d\n", fd.pitch_ext);
  138. fprintf(stderr,"downloadfont: fd.height_ext = %d\n", fd.height_ext);
  139. fprintf(stderr,"downloadfont: fd.cap_height = %d\n", fd.cap_height);
  140. fprintf(stderr,"downloadfont: fd.font_number = %d\n", fd.font_number);
  141. fprintf(stderr,"downloadfont: fd.font_name = %s\n", fd.font_name);
  142. #endif /* DEBUG2 */
  143.  
  144.     /* Send font descriptor escape sequence to printer */
  145.     fprintf(bitfile, PCL4_FONT_DESCR, fd.size);
  146.  
  147.     /*
  148.     * Download each font descriptor value individually to avoid 
  149.     * possible struct alignment problems.
  150.     */
  151.     fwrite((void *)&fd.size, sizeof(fd.size), 1, bitfile);
  152.     fwrite((void *)&fd.descriptor, sizeof(fd.descriptor), 1, bitfile);
  153.     fwrite((void *)&fd.font_type, sizeof(fd.font_type), 1, bitfile);
  154.     fwrite((void *)&fd.style_MSB, sizeof(fd.style_MSB), 1, bitfile);
  155.     fwrite((void *)&fd.reserved, sizeof(fd.reserved), 1, bitfile);
  156.     fwrite((void *)&fd.baseline, sizeof(fd.baseline), 1, bitfile);
  157.     fwrite((void *)&fd.cell_width, sizeof(fd.cell_width), 1, bitfile);
  158.     fwrite((void *)&fd.cell_height, sizeof(fd.cell_height), 1, bitfile); 
  159.     fwrite((void *)&fd.orientation, sizeof(fd.orientation), 1, bitfile);
  160.     fwrite((void *)&fd.spacing, sizeof(fd.spacing), 1, bitfile);
  161.     fwrite((void *)&fd.symbol_set, sizeof(fd.symbol_set), 1, bitfile);
  162.     fwrite((void *)&fd.pitch, sizeof(fd.pitch), 1, bitfile);
  163.     fwrite((void *)&fd.height, sizeof(fd.height), 1, bitfile);
  164.     fwrite((void *)&fd.x_height, sizeof(fd.x_height), 1, bitfile);
  165.     fwrite((void *)&fd.width_type, sizeof(fd.width_type), 1, bitfile);
  166.     fwrite((void *)&fd.style_LSB, sizeof(fd.style_LSB), 1, bitfile);
  167.     fwrite((void *)&fd.stroke_weight, sizeof(fd.stroke_weight), 1, bitfile);
  168.     fwrite((void *)&fd.typeface_LSB, sizeof(fd.typeface_LSB), 1, bitfile);
  169.     fwrite((void *)&fd.typeface_MSB, sizeof(fd.typeface_MSB), 1, bitfile);
  170.     fwrite((void *)&fd.serif_style, sizeof(fd.serif_style), 1, bitfile);
  171.     fwrite((void *)&fd.quality, sizeof(fd.quality), 1, bitfile);
  172.     fwrite((void *)&fd.placement, sizeof(fd.placement), 1, bitfile);
  173.     fwrite((void *)&fd.underl_dist, sizeof(fd.underl_dist), 1, bitfile);
  174.     fwrite((void *)&fd.underl_height, sizeof(fd.underl_height), 1, bitfile);
  175.     fwrite((void *)&fd.text_height, sizeof(fd.text_height), 1, bitfile);
  176.     fwrite((void *)&fd.text_width, sizeof(fd.text_width), 1, bitfile);
  177.     fwrite((void *)&fd.first_code, sizeof(fd.first_code), 1, bitfile);
  178.     fwrite((void *)&fd.last_code, sizeof(fd.last_code), 1, bitfile);
  179.     fwrite((void *)&fd.pitch_ext, sizeof(fd.pitch_ext), 1, bitfile);
  180.     fwrite((void *)&fd.height_ext, sizeof(fd.height_ext), 1, bitfile);
  181.     fwrite((void *)&fd.cap_height, sizeof(fd.cap_height), 1, bitfile);
  182.     fwrite((void *)&fd.font_number, sizeof(fd.font_number), 1, bitfile);
  183.     fwrite((void *)fd.font_name, sizeof(fd.font_name), 1, bitfile);
  184.  
  185.     /* Download each character of curfont which occurs in the .dvi file */
  186.     for(i = font->bc ; i <= font->ec ; i++)
  187.         if((cbase + i)->use_count)
  188.             memreq += downloadchar(bitfile, i, device);
  189.     fprintf(bitfile, PCL4_MAKE_FONT_TEMP);    /* Make the font temporary */
  190.     return(memreq);
  191. }
  192.