home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / printing / ghostscrip / source / specific / c / gdevbj10 < prev    next >
Encoding:
Text File  |  1991-10-25  |  3.4 KB  |  116 lines

  1. /* Copyright (C) 1990, 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gdevbj10.c */
  21. /* Canon Bubble Jet BJ-10e printer driver for Ghostscript */
  22. #include "gdevprn.h"
  23.  
  24. /* The device descriptor */
  25. private dev_proc_print_page(bj10_print_page);
  26. gx_device_printer gs_bj10_device =
  27.   prn_device(prn_std_procs, "bj10",
  28.     80,                /* width_10ths, 8" */
  29.     105,                /* height_10ths, 10.5" */
  30.     360,                /* x_dpi */
  31.     360,                /* y_dpi */
  32.     0,0,0,0,            /* margins */
  33.     1, bj10_print_page);
  34.  
  35. /* ------ internal routines ------ */
  36.  
  37. /* Send the page to the printer. */
  38. private int
  39. bj10_print_page(gx_device_printer *pdev, FILE *prn_stream)
  40. {    int line_size = gdev_mem_bytes_per_scan_line(&pdev->mem);
  41.     byte *in = (byte *)gs_malloc(1, 48*line_size, "bj10_print_page(in)");
  42.     byte *out = (byte *)gs_malloc(1, 48*line_size, "bj10_print_page(out)");
  43.     static char cmp[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  44.     int lnum;
  45.  
  46.     if ( in == 0 || out == 0 )
  47.         return -1;
  48.  
  49.     /* I don't know how to initialize the printer -- */
  50.     /* \033@ doesn't work. */
  51.  
  52.     /* Linewidth for 48 pixel lines */
  53.     fprintf(prn_stream, "\033A%c\033\002", 8);
  54.  
  55.     /* Print lines with 48 pixel height of graphics */
  56.     for ( lnum = 0; lnum < pdev->height; lnum += 48 )
  57.        {    byte *inp = in;
  58.         byte *outp = out;
  59.         byte *in_end = in + line_size;
  60.         byte *out_beg = out;
  61.         byte *out_end = out + 6 * pdev->width;
  62.         int count;
  63.  
  64.         gdev_prn_copy_scan_lines(pdev, lnum, inp, line_size*48);
  65.  
  66.         while ( inp < in_end )
  67.            {    int i;
  68.             for ( i = 0; i < 6; i++, outp++ )
  69.                 gdev_prn_transpose_8x8(inp + 8*i*line_size,
  70.                             line_size, outp, 6);
  71.             inp++;
  72.             outp += 42;
  73.            }
  74.  
  75.         /* Remove trailing 0s. */
  76.         while ( out_end - 6 >= out )
  77.            {    if ( memcmp(cmp, (char *)out_end-6, 6) != 0 )
  78.                 break;
  79.             out_end -= 6;
  80.            }
  81.  
  82.         /* Remove leading 0s. */
  83.         while ( out_beg + 18 <= out_end )
  84.            {    if( memcmp(cmp, (char *)out_beg, 18) != 0 )
  85.                 break;
  86.             out_beg += 18;
  87.            }
  88.  
  89.         /* Transfer the bits */
  90.         count = (out_end - out_beg) / 6;
  91.         if ( count > 0 )
  92.            {    if ( out_beg > out )
  93.                {    putc(033, prn_stream);
  94.                 putc('d', prn_stream);    /* displace to right */
  95.                 putc( ((out_beg - out) / 18) & 0x0ff, prn_stream);
  96.                 putc( ((out_beg - out) / 18) >> 8, prn_stream);
  97.                }
  98.             putc(033, prn_stream);
  99.             putc('*', prn_stream);
  100.             putc(48, prn_stream);
  101.             putc(count & 0xff, prn_stream);
  102.             putc(count >> 8, prn_stream);
  103.             fwrite((char *)out_beg, 1, 6*count, prn_stream);
  104.            }
  105.         putc(015, prn_stream);
  106.         putc(012, prn_stream);
  107.        }
  108.  
  109.     /* Reinitialize the printer ?? */
  110.     putc(014, prn_stream);    /* form feed */
  111.  
  112.     gs_free(in, 1, 48*line_size, "bj10_print_page(in)");
  113.     gs_free(out, 1, 48*line_size, "bj10_print_page(out)");
  114.     return 0;
  115. }
  116.