home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / tctnt / gprint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-27  |  2.5 KB  |  109 lines

  1. /* GPRINT.C: Prints a graphics screen on an Epson compatible printer
  2. */
  3.  
  4. #include <graphics.h>
  5. #include <stdio.h>
  6. #include <bios.h>                    // for biosprint()
  7. #include <io.h>
  8.  
  9. #define ESC  '\x1B'
  10. #define LPT1 0
  11. #define LPT2 1
  12.  
  13. #define prn_putc(x) biosprint(0,(x),LPT1)
  14.  
  15. /*-------------------------------------------------------------------
  16.     bitImage - Sets Epson printer to bit image mode. 'Nbytes" is
  17.                          the number of bytes to PRINT.
  18. */
  19.  
  20. static void bitImage(int Nbytes) {
  21.     register int n1, n2;
  22.  
  23.     //  Nbytes = (256 * n2) + n1
  24.     n2 = Nbytes >> 8;
  25.     n1 = Nbytes - (n2 << 8);
  26.  
  27.     // 8-pin, Horizontal density = 80 dots/in.
  28.     prn_putc(ESC);
  29.     prn_putc('*');
  30.     prn_putc(4);
  31.     prn_putc(n1);
  32.     prn_putc(n2);
  33. } // end of bitImage()
  34.  
  35. /*-------------------------------------------------------------------
  36.     getScrBits - Get pixels from the screen and convert them to the
  37.                              printer's pin order.
  38. */
  39.  
  40. static unsigned char getScrBits(int x, int y) {
  41.     unsigned char firePins;
  42.  
  43.     firePins  = (getpixel(x, y++)==0)? 0: 0x80;
  44.     firePins |= (getpixel(x, y++)==0)? 0: 0x40;
  45.     firePins |= (getpixel(x, y++)==0)? 0: 0x20;
  46.     firePins |= (getpixel(x, y++)==0)? 0: 0x10;
  47.     firePins |= (getpixel(x, y++)==0)? 0: 0x08;
  48.     firePins |= (getpixel(x, y++)==0)? 0: 0x04;
  49.     firePins |= (getpixel(x, y++)==0)? 0: 0x02;
  50.     firePins |= (getpixel(x, y  )==0)? 0: 0x01;
  51.  
  52.     return     firePins;
  53. } // end of getScrBits()
  54.  
  55. /*-------------------------------------------------------------------
  56.     printImage - Graphics print function.
  57. */
  58.  
  59. int printImage(int left, int top, int right, int bottom) {
  60.     int x, y, width;
  61.  
  62.     width  = right-left;
  63.  
  64.     /* Initialize line spacing to 1/8 in. (normally 1/6) for
  65.          Line Feeds */
  66.     prn_putc(ESC);
  67.     prn_putc('0');
  68.  
  69.     for (y=top; y<bottom; y+=8) {
  70.         bitImage(width+1);
  71.  
  72.         for (x=left; x<=right; x++)
  73.             prn_putc(getScrBits(x,y));
  74.  
  75.         prn_putc('\n');
  76.     }
  77.     return 0;
  78. } // end of printImage()
  79.  
  80. //*******************************************************************
  81. int main()
  82. {
  83.     int driver, mode,x,y;
  84.  
  85.     driver = DETECT;                         // autodetect
  86.     mode = 0;
  87.     initgraph(&driver, &mode, "c:\\tc\\tcp101\\bgi");
  88.     x = getmaxx();
  89.     y = getmaxy();
  90.  
  91.     // draw some things
  92.     rectangle(0,0,x,y);
  93.     circle(300,200,100);
  94.     circle(210,110,50);
  95.     circle(390,110,50);
  96.     circle(272,173,3);
  97.     circle(330,170,10);
  98.     moveto(280,220);
  99.     lineto(290,230);
  100.     lineto(320,220);
  101.  
  102.     // Graphics print function prints entire screen
  103.     printImage(0,0,x,y);
  104.     closegraph();
  105.  
  106.     return 0;
  107. } // end of main()
  108.  
  109.