home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GDEVLBP8.C < prev    next >
C/C++ Source or Header  |  1994-07-27  |  5KB  |  158 lines

  1. /* Copyright (C) 1991, 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gdevlbp8.c */
  20. /* Canon LBP-8II and LIPS III driver for Ghostscript */
  21. #include "gdevprn.h"
  22.  
  23. #define X_DPI 300
  24. #define Y_DPI 300
  25. #define LINE_SIZE ((X_DPI * 85 / 10 + 7) / 8)    /* bytes per line */
  26.  
  27. /* The device descriptors */
  28. private dev_proc_print_page(lbp8_print_page);
  29. private dev_proc_print_page(lips3_print_page);
  30.  
  31. gx_device_printer far_data gs_lbp8_device =
  32.   prn_device(prn_std_procs, "lbp8",
  33.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  34.     X_DPI, Y_DPI,
  35.     0.16, 0.20, 0.32, 0.20,        /* margins */
  36.     1, lbp8_print_page);
  37.  
  38. gx_device_printer far_data gs_lips3_device =
  39.   prn_device(prn_std_procs, "lips3",
  40.     82,                /* width_10ths, 8.3" */
  41.     117,                /* height_10ths, 11.7" */
  42.     X_DPI, Y_DPI,
  43.     0.16, 0.27, 0.23, 0.27,        /* margins */
  44.     1, lips3_print_page);
  45.  
  46. /* ------ Internal routines ------ */
  47.  
  48. #define ESC 0x1b
  49. #define CSI 0233
  50. #define DCS 0220
  51. #define ST 0234
  52.  
  53. static const char lbp8_init[] = {
  54.   ESC, ';', ESC, 'c', ESC, ';', /* reset, ISO */
  55.   CSI, '2', '&', 'z',    /* fullpaint mode */
  56.   CSI, '1', '4', 'p',    /* select page type (A4) */
  57.   CSI, '1', '1', 'h',    /* set mode */
  58.   CSI, '7', ' ', 'I',    /* select unit size (300dpi)*/
  59. };
  60.  
  61. static const char lbp8_end[] = {
  62. };
  63.  
  64. static const char lips3_init[] = {
  65.   ESC, '<', /* soft reset */
  66.   DCS, '0', 'J', ST, /* JOB END */
  67.   DCS, '3', '1', ';', '3', '0', '0', ';', '2', 'J', ST, /* 300dpi, LIPS3 JOB START */
  68.   ESC, '<',  /* soft reset */
  69.   DCS, '2', 'y', 'P', 'r', 'i', 'n', 't', 'i', 'n', 'g', '(', 'g', 's', ')', ST,  /* Printing (gs) display */
  70.   CSI, '?', '1', 'l',  /* auto cr-lf disable */
  71.   CSI, '?', '2', 'h', /* auto ff disable */
  72.   CSI, '1', '1', 'h', /* set mode */
  73.   CSI, '7', ' ', 'I', /* select unit size (300dpi)*/
  74.   CSI, 'f' /* move to home position */
  75. };
  76.  
  77. static const char lips3_end[] = {
  78.   DCS, '0', 'J', ST  /* JOB END */
  79. };
  80.  
  81. /* Send the page to the printer.  */
  82. private int
  83. can_print_page(gx_device_printer *pdev, FILE *prn_stream,
  84.   const char *init, int init_size, const char *end, int end_size)
  85. {    char data[LINE_SIZE*2];
  86.     char *out_data;
  87.     int out_count;
  88.  
  89. #define CSI_print(str) fprintf(prn_stream, str, CSI)
  90. #define CSI_print_1(str,arg) fprintf(prn_stream, str, CSI, arg)
  91.  
  92.     fwrite(init, init_size, 1, prn_stream);        /* initialize */
  93.  
  94.     /* Send each scan line in turn */
  95.        {    int lnum;
  96.         int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  97.         byte rmask = (byte)(0xff << (-pdev->width & 7));
  98.  
  99.         for ( lnum = 0; lnum < pdev->height; lnum++ )
  100.            {    char *end_data = data + LINE_SIZE;
  101.             gdev_prn_copy_scan_lines(pdev, lnum,
  102.                          (byte *)data, line_size);
  103.                /* Mask off 1-bits beyond the line width. */
  104.             end_data[-1] &= rmask;
  105.             /* Remove trailing 0s. */
  106.             while ( end_data > data && end_data[-1] == 0 )
  107.                 end_data--;
  108.             if ( end_data != data )
  109.                {    
  110.                 int num_cols = 0;
  111.  
  112.                 out_data = data;
  113.                 while(out_data < end_data && *out_data == 0)
  114.                                   {
  115.                                     num_cols += 8;
  116.                                     out_data++;
  117.                                   }
  118.                 out_count = end_data - out_data;
  119.  
  120.                 /* move down */
  121.                 CSI_print_1("%c%dd", lnum);
  122.                 /* move across */
  123.                 CSI_print_1("%c%d`", num_cols);
  124.  
  125.                 /* transfer raster graphics */
  126.                 fprintf(prn_stream, "%c%d;%d;300;.r",
  127.                     CSI, out_count, out_count);
  128.  
  129.                 /* send the row */
  130.                 fwrite(out_data, sizeof(char),
  131.                                        out_count, prn_stream);
  132.                }
  133.            }
  134.     }
  135.  
  136.     /* eject page */
  137.     fprintf(prn_stream, "%c=", ESC);
  138.  
  139.     /* terminate */
  140.     fwrite(end, end_size, 1, prn_stream);
  141.  
  142.     return 0;
  143. }
  144.  
  145. /* Print an LBP-8 page. */
  146. private int
  147. lbp8_print_page(gx_device_printer *pdev, FILE *prn_stream)
  148. {    return can_print_page(pdev, prn_stream, lbp8_init, sizeof(lbp8_init),
  149.                   lbp8_end, sizeof(lbp8_end));
  150. }
  151.  
  152. /* Print a LIPS III page. */
  153. private int
  154. lips3_print_page(gx_device_printer *pdev, FILE *prn_stream)
  155. {    return can_print_page(pdev, prn_stream, lips3_init, sizeof(lips3_init),
  156.                   lips3_end, sizeof(lips3_end));
  157. }
  158.