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

  1. /* $Log:    drawchar.c,v $
  2.  * Revision 0.8  92/11/23  19:46:44  19:46:44  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:28  02:41:28  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:47  02:45:47  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:19  12:43:19  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 <stdio.h>
  28. #include "globals.h"
  29. #include "pcl.h"
  30.  
  31. static char rcsid[] = "$Header: drawchar.c,v 0.8 92/11/23 19:46:44 bt Exp $";
  32.  
  33. /*
  34.  * On entrance to this routine, the character to be drawn will be in 'c', the
  35.  * font in use is pointed by the pointer '*font'. The external name by which
  36.  * the font is known in 'font->down'. The routine is also responsible for
  37.  * setting the printer to the correct location on the page  ('hh' and 'vv')
  38.  */
  39. charfmt *drawchar(bitfile, c, hh, vv, resolution, device)
  40. FILE    *bitfile;
  41. int    c;
  42. long    hh, vv;
  43. short    resolution;
  44. short    device;
  45. {
  46.     int        i,j;
  47.     int        pxl_bytes;
  48.     charfmt        *u;
  49.     gcharfmt    *g;
  50.     byte        *p;
  51.     char        drawrow[8];
  52.  
  53. #ifdef DEBUG
  54.     fprintf(stderr,"\ndrawchar: hh = %ld, vv = %ld,\n",hh, vv);
  55. #endif
  56.     if(!h_posed && !v_posed) {
  57.         fprintf(bitfile, PCL4_MOVE_POSITION, hh + h_offset, vv + v_offset);
  58.         h_posed = v_posed = TRUE;
  59.     }
  60.     else if(!h_posed) {
  61.         fprintf(bitfile, PCL4_MOVE_H_POSITION, hh + h_offset);
  62.         h_posed = TRUE;
  63.     }
  64.     else if(!v_posed) {
  65.         fprintf(bitfile, PCL4_MOVE_V_POSITION, vv + v_offset);
  66.         v_posed = TRUE;
  67.     }
  68.     u = font->chr + c;
  69.     if(u->use_count > 0) {
  70.         /* Print downloaded character */
  71.         if(device == DEV_LJPLUS) {
  72.             putc(c > 32 ? c : c + 160, bitfile);
  73.         } else  
  74.             if(c > 27)
  75.                 putc(c, bitfile);
  76.                 else
  77.                 if(c==0 || c > 6 && c < 16 || c==27)
  78.                      fprintf(bitfile, PCL4_TRANSP_MODE, c);
  79.             else
  80.                 putc(c , bitfile);
  81.     } else {
  82.         /* Draw graphic raster pattern of character */
  83.         g = &(*gfont)[c];
  84.         p = g->pxl_pattern;
  85.         fputs(PCL4_PUSH, bitfile);
  86.         fprintf(bitfile, PCL4_MOVE_REL, g->x_offset, g->y_offset);
  87.         fprintf(bitfile, PCL4_RESOLUTION, resolution);
  88.         fputs(PCL4_START_RASTER, bitfile);
  89.         pxl_bytes = g->pxl_bytes;
  90.         sprintf(drawrow, PCL4_DRAWROW, pxl_bytes);
  91.         for(i = 0 ; i < g->pxl_rows ; i++) {
  92.             fputs(drawrow, bitfile);
  93.             for(j = 0 ; j < pxl_bytes ; j++)
  94.                 putc(*p++, bitfile);
  95.         }
  96.         fputs(PCL4_END_RASTER, bitfile);
  97.         fputs(PCL4_POP, bitfile);
  98.         fprintf(bitfile, PCL4_MOVE_HREL, u->pxl_width);
  99.     }
  100.     return (u);
  101. }
  102.