home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gs252src.zip / GS252 / GDEVLN03.C < prev    next >
C/C++ Source or Header  |  1992-06-12  |  6KB  |  201 lines

  1. /* Copyright (C) 1991 Free Software Foundation, Inc.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /*
  20. gdevln03.c
  21. Ghostscript driver for DEC LN03 printer
  22.  
  23. Ulrich Mueller, Div. PPE, CERN, CH-1211 Geneva 23 <ulm@vsnhd1.cern.ch>
  24. This code is subject to the GNU General Public License
  25.  
  26. ulm 91-02-13 created as driver for gs 2.1.1
  27. ulm 91-07-23 adapted to gs 2.2
  28. ulm 91-08-21 changed memory allocation to gs_malloc,
  29.          ported to VMS (contributed by Martin Stiftinger, TU Vienna)
  30. lpd 91-11-24 sped up by removing multiplies from inner loop
  31. ijmp 92-04-14 add support for la75/la50 (macphed@dvinci.usask.ca)
  32. */
  33.  
  34. #include "gdevprn.h"
  35.  
  36. /* Forward references */
  37. private int sixel_printpage(P3(gx_device_printer *pdev, FILE *prn_stream, const char *init));
  38.  
  39. /* The device descriptor */
  40. private dev_proc_print_page(ln03_print_page);
  41. gx_device_printer gs_ln03_device =
  42.     prn_device(prn_std_procs, "ln03",
  43.            82,            /* width_10ths,  2460 pixel */
  44.            115,            /* height_10ths, 3450 pixel */
  45.            300, 300,        /* x_dpi, y_dpi */
  46.            0, 0.3, 0, 0,        /* margins */
  47.            1, ln03_print_page);
  48.     /* switch to graphics mode, 300 dpi
  49.        <ESC>[!p        DECSTR    soft terminal reset
  50.        <ESC>[11h    PUM    select unit of measurement
  51.        <ESC>[7 I    SSU    select pixel as size unit
  52.        <ESC>[?52h    DECOPM    origin is upper-left corner
  53.        <ESC>[3475t    DECSLPP    form length (3475 pixels)
  54.        <ESC>[0;2460s    DECSLRM    left and right margins (0, 2460 pixels)
  55.        <ESC>P0;0;1q        select sixel graphics mode
  56.        "1;1        DECGRA    aspect ratio (1:1)
  57.        *** Parameters are for A4 paper format.
  58.        *** Could someone please check them for american paper format? */
  59. #define LN03_INIT \
  60.  "\033[!p\033[11h\033[7 I\033[?52h\033[3475t\033[0;2460s\033P0;0;1q\"1;1"
  61.  
  62. private int
  63. ln03_print_page(gx_device_printer *pdev, FILE *prn_stream)
  64. {
  65. return (sixel_printpage(pdev,prn_stream,LN03_INIT));
  66. }
  67.  
  68. /*
  69.  * LA75 dot matrix printer device.
  70.  * This uses North American 8.5 x 11 inch paper size.
  71.  */
  72. private dev_proc_print_page(la75_print_page);
  73. gx_device_printer gs_la75_device =
  74.     prn_device(prn_std_procs, "la75",
  75.         85,
  76.         110,
  77.         144, 72,
  78.         0, 0, 0.5, 0,
  79.         1, la75_print_page);
  80.  
  81. #define LA75_INIT "\033P0;0;0q"
  82.  
  83. private int
  84. la75_print_page(gx_device_printer *pdev, FILE *prn_stream)
  85. {
  86.     return (sixel_printpage(pdev,prn_stream,LA75_INIT));
  87. }
  88.  
  89. /*
  90.  * LA50 dot matrix printer device.
  91.  * This uses North American 8.5 x 11 inch paper size.
  92.  */
  93. private dev_proc_print_page(la50_print_page);
  94. gx_device_printer gs_la50_device =
  95.     prn_device(prn_std_procs, "la50",
  96.                 85,
  97.                 110,
  98.                 144, 72,
  99.                 0, 0, 0.5, 0,
  100.                 1, la50_print_page);
  101. /* LA50's use a very primitive form of initialization */
  102.  
  103. #define LA50_INIT "\033Pq"
  104.  
  105. private int
  106. la50_print_page(gx_device_printer *pdev, FILE *prn_stream)
  107. {
  108.     return (sixel_printpage(pdev,prn_stream,LA50_INIT));
  109. }
  110.  
  111. /* ------ Internal routines ------ */
  112.  
  113. /* Send the page to the printer. */
  114. private int
  115. sixel_printpage(gx_device_printer *pdev, FILE *prn_stream, const char *init)
  116. {
  117.     byte *in, *inp;
  118.     int lnum, lcount, l, count, empty, mask, c, oldc, line_size, in_size;
  119.  
  120.     line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  121.     in_size = line_size * 6;
  122.     in = (byte *)gs_malloc(in_size, 1, "ln03_print_page");
  123.  
  124.     /* Check allocation */
  125.     if (!in) return(-1);
  126.  
  127.       fputs(init,prn_stream);
  128.  
  129.     /* Print lines of graphics */
  130.     for (lnum = lcount = 0; lnum < pdev->height; lnum+=6, lcount++) {
  131.     gdev_prn_copy_scan_lines(pdev, lnum, inp = in, line_size * 6);
  132.  
  133.     mask = 0200;
  134.     oldc = 077;
  135.     empty = 1;
  136.  
  137.     for (l = pdev->width, count = 0; --l >= 0; count++) {
  138.         /* transpose 6*8 rectangle */
  139.         register byte *iptr = inp;
  140.         c = 077;
  141.         if (*iptr & mask)
  142.         c += 1;
  143.         if (*(iptr += line_size) & mask)
  144.         c += 2;
  145.         if (*(iptr += line_size) & mask)
  146.         c += 4;
  147.         if (*(iptr += line_size) & mask)
  148.         c += 010;
  149.         if (*(iptr += line_size) & mask)
  150.         c += 020;
  151.         if (*(iptr += line_size) & mask)
  152.         c += 040;
  153.         if (!(mask >>= 1)) {
  154.         mask = 0200;
  155.         inp++;
  156.         }
  157.  
  158.         if (c != oldc) {
  159.         if (empty) {
  160.             while (--lcount >= 0) {
  161. #ifdef VMS
  162.             /* terminate record for VMS STREAM-LF file.
  163.                this LF is ignored by the LN03 */
  164.             fputc('\n', prn_stream);
  165. #endif
  166.             /* terminate previous line */
  167.             fputc('-', prn_stream);
  168.             }
  169.             empty = lcount = 0;
  170.         }
  171.         if (count > 3)
  172.             /* use run length encoding */
  173.             fprintf(prn_stream, "!%d%c", count, oldc);
  174.         else
  175.             while (--count >= 0)
  176.             fputc(oldc, prn_stream);
  177.         oldc = c;
  178.         count = 0;
  179.         }
  180.     }
  181.     if (c != 077) {
  182.         if (count > 3)
  183.         /* use run length encoding */
  184.         fprintf(prn_stream, "!%d%c", count, c);
  185.         else
  186.         while (--count >= 0)
  187.             fputc(c, prn_stream);
  188.     }
  189.     }
  190.  
  191.     /* leave sixel graphics mode, eject page
  192.        <ESC>\        ST    string terminator
  193.        <FF>        FF    form feed */
  194.     fputs("\033\\\f", prn_stream);
  195.     fflush(prn_stream);
  196.  
  197.     gs_free((char *)in, in_size, 1, "ln03_print_page");
  198.  
  199.     return(0);
  200. }
  201.