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

  1. /* $Log:    downloadchar.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:43  21:47:43  bt (Bo Thide')
  9.  * Bug fixes. Added -R option. Better font handling.
  10.  * 
  11.  * Revision 0.5  92/11/09  16:25:30  16:25:30  bt (Bo Thide')
  12.  * Rewrite of dospecial.c. Extended \special support
  13.  * 
  14.  * Revision 0.4  92/11/08  02:45:45  02:45:45  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. /*
  28.  * Download character 'c', assuming that the corresponding font file is in 
  29.  * .pk format. Therefore, 'pktopxl(c)' is called which converts the pk-coded
  30.  * character into the corresponding byte aligned pixel pattern, stored in
  31.  * 'pxlbuffer'. 'pktopxl(c)' also determines the global variables
  32.  *      c_width, c_height, c_hoffset, c_voffset.
  33.  *
  34.  * For landscape mode the pixel pattern then will be rotated and stored at
  35.  * the end of the character pixel pattern at 'endofchardata' in pxlbuffer.
  36.  * The appropriate pixel pattern then is downloaded, i.e is put in bitfile,
  37.  * if possible, including the corresponding character descriptor for the
  38.  * printer. For those characters which don't fit into the printer's maximum
  39.  * character cell (use_count < 0) raster information is stored in *gfont
  40.  * and memory space is allocated to store the corresponding pixel pattern.
  41.  * Stored characters are drawn in graphics mode by 'drawchar(c)'.
  42.  */
  43.  
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include "globals.h"
  47. #include "pcl.h"
  48.  
  49. static char rcsid[] = "$Header: downloadchar.c,v 0.8 92/11/23 19:46:43 bt Exp $";
  50.  
  51.  
  52. int downloadchar(bitfile, c, device)
  53. FILE    *bitfile;
  54. int    c;
  55. short    device;
  56. {
  57.     int        i;
  58.     charfmt        *u;
  59.     int        length;
  60.     int         width_bytes;
  61.     int        width, height;
  62.     byte        *p;
  63.  
  64.     pktopxl(c);
  65.  
  66.     /* Determine the char descriptor values */
  67.     cd.format = 4;
  68.     cd.continuation = 0;
  69.     cd.size = 14;
  70.     cd.class = 1;
  71.     cd.reserved = 0;
  72.     if(landscape){
  73.         p = (byte *)rotatechar();
  74.         width  = c_height;
  75.         height = c_width;
  76.         cd.orientation = '\1';
  77.         cd.left_offset = -c_voffset;
  78.         cd.top_offset  = height - c_hoffset - 1;
  79.     }
  80.     else{
  81.         width  = c_width;
  82.         height = c_height;
  83.         cd.orientation = '\0';
  84.         cd.left_offset = -c_hoffset;
  85.         cd.top_offset  = c_voffset;
  86.         p =  pxlbuffer;
  87.     }
  88.     width_bytes = (width + 7) / 8;
  89.     length = height*width_bytes;
  90.  
  91.     /* This is for empty characters */
  92.     if(!length) {
  93.         length = 1;
  94.         if(!width)
  95.             width=1;
  96.         if(!height) {
  97.             height = 1;
  98.             cd.top_offset = 1;
  99.         }
  100.     }
  101.  
  102.     u = cbase + c;
  103.     cd.char_width  = (ushort)width;
  104.     cd.char_height = (ushort)height;
  105.     cd.delta_x = (short)(4*u->pxl_width);        /* In quarterdots! */
  106.     if(device == DEV_LJPLUS) {
  107.         if(c <= 32)
  108.             c += 160;
  109.     }
  110.  
  111. #ifdef DEBUG2
  112. fprintf(stderr,"downloadchar: cd.format = %d\n", cd.format);
  113. fprintf(stderr,"downloadchar: cd.continuation = %d\n", cd.continuation);
  114. fprintf(stderr,"downloadchar: cd.size = %d\n", cd.size);
  115. fprintf(stderr,"downloadchar: cd.class = %d\n", cd.class);
  116. fprintf(stderr,"downloadchar: cd.orientation = %d\n", cd.orientation);
  117. fprintf(stderr,"downloadchar: cd.reserved = %d\n", cd.reserved);
  118. fprintf(stderr,"downloadchar: cd.left_offset = %d\n", cd.left_offset);
  119. fprintf(stderr,"downloadchar: cd.top_offset = %d\n", cd.top_offset);
  120. fprintf(stderr,"downloadchar: cd.char_width = %d\n", cd.char_width);
  121. fprintf(stderr,"downloadchar: cd.char_height = %d\n", cd.char_height);
  122. fprintf(stderr,"downloadchar: cd.delta_x = %d\n", cd.delta_x);
  123. #endif /* DEBUG2 */
  124.  
  125.     /* Send character ID escape sequence to printer */
  126.     fprintf(bitfile, PCL4_CHAR_ID, c, length + (int)cd.size + 2);
  127.  
  128.     /*
  129.     * Download each char descriptor value individually to avoid 
  130.     * possible struct alignment problems.
  131.     */ 
  132.     fwrite((void *)&cd.format, sizeof(cd.format), 1, bitfile);
  133.     fwrite((void *)&cd.continuation, sizeof(cd.continuation), 1, bitfile);
  134.     fwrite((void *)&cd.size, sizeof(cd.size), 1, bitfile);
  135.     fwrite((void *)&cd.class, sizeof(cd.class), 1, bitfile);
  136.     fwrite((void *)&cd.orientation, sizeof(cd.orientation), 1, bitfile);
  137.     fwrite((void *)&cd.reserved, sizeof(cd.reserved), 1, bitfile);
  138.     fwrite((void *)&cd.left_offset, sizeof(cd.left_offset), 1, bitfile);
  139.     fwrite((void *)&cd.top_offset, sizeof(cd.top_offset), 1, bitfile);
  140.     fwrite((void *)&cd.char_width, sizeof(cd.char_width), 1, bitfile);
  141.     fwrite((void *)&cd.char_height, sizeof(cd.char_height), 1, bitfile);
  142.     fwrite((void *)&cd.delta_x, sizeof(cd.delta_x), 1, bitfile);
  143.  
  144.     /* Now download pixel pattern for c */
  145.     for(i = 0 ; i < length ; i++)
  146.         putc(*p++, bitfile);
  147.  
  148.     return(height*((width + 7)/8) + (int)cd.size + 2);
  149. }
  150.