home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gnu / gs-2.6.1.4-src.lha / src / amiga / gs-2.6.1.4 / gdevdjet.c < prev    next >
C/C++ Source or Header  |  1994-01-27  |  16KB  |  471 lines

  1. /* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises.  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. /* gdevdjet.c */
  20. /* HP LaserJet/DeskJet driver for Ghostscript */
  21. #include "gdevprn.h"
  22. #include "gdevpcl.h"
  23.  
  24. /*
  25.  * Thanks to Jim Mayer (mayer@wrc.xerox.com),
  26.  * Jan-Mark Wams (jms@cs.vu.nl), Frans van Hoesel (hoesel@rugr86.rug.nl),
  27.  * and George Cameron (g.cameron@biomed.abdn.ac.uk) for improvements.
  28.  */
  29.  
  30. /*
  31.  * You may select a default resolution of 75, 100, 150, 300, or
  32.  * (LJ4 only) 600 DPI in the makefile, or an actual resolution on
  33.  * the gs command line.
  34.  *
  35.  * If the preprocessor symbol A4 is defined, the default paper size is
  36.  * the European A4 size; otherwise it is the U.S. letter size (8.5"x11").
  37.  *
  38.  * You may find the following test page useful in determining the exact
  39.  * margin settings on your printer.  It prints four big arrows which
  40.  * point exactly to the for corners of an A4 sized paper. Of course the
  41.  * arrows cannot appear in full on the paper, and they are truncated by
  42.  * the margins. The margins measured on the testpage must match those
  43.  * in gdevdjet.c.  So the testpage indicates two facts: 1) the page is
  44.  * not printed in the right position 2) the page is truncated too much
  45.  * because the margins are wrong. Setting wrong margins in gdevdjet.c
  46.  * will also move the page, so both facts should be matched with the
  47.  * real world.
  48.  
  49. %!
  50.     newpath 
  51.     0 0 moveto 144 72 lineto 72 144 lineto
  52.     closepath fill stroke 0 0 moveto 144 144 lineto stroke
  53.  
  54.     595.27 841.88 moveto 451.27 769.88 lineto 523.27 697.88 lineto
  55.     closepath fill stroke 595.27 841.88 moveto 451.27 697.88 lineto stroke
  56.  
  57.     0 841.88 moveto 144 769.88 lineto 72 697.88 lineto
  58.     closepath fill stroke 0 841.88 moveto 144 697.88 lineto stroke
  59.  
  60.     595.27 0 moveto 451.27 72 lineto 523.27 144 lineto
  61.     closepath fill stroke 595.27 0 moveto 451.27 144 lineto stroke
  62.  
  63.     /Helvetica findfont
  64.     14 scalefont setfont
  65.     100 600 moveto
  66.     (This is an A4 testpage. The arrows should point exactly to the) show
  67.     100 580 moveto
  68.     (corners and the margins should match those given in gdev*.c) show
  69.     showpage
  70.  
  71.  */
  72.  
  73. /* Define the default, maximum resolutions. */
  74. #ifdef X_DPI
  75. #  define X_DPI2 X_DPI
  76. #else
  77. #  define X_DPI 300
  78. #  define X_DPI2 600
  79. #endif
  80. #ifdef Y_DPI
  81. #  define Y_DPI2 Y_DPI
  82. #else
  83. #  define Y_DPI 300
  84. #  define Y_DPI2 600
  85. #endif
  86.  
  87. /*
  88.  * For all DeskJet Printers:
  89.  *
  90.  *  Maximum printing width               = 2400 dots = 8"
  91.  *  Maximum recommended printing height  = 3100 dots = 10 1/3"
  92.  *
  93.  * All Deskjets have 1/2" unprintable bottom margin.
  94.  * The recommendation comes from the HP Software Developer's Guide for
  95.  * the DeskJet 500, DeskJet PLUS, and DeskJet printers, version C.01.00
  96.  * of 12/1/90.
  97.  *
  98.  * Note that the margins defined just below here apply only to the DeskJet;
  99.  * the paper size, width and height apply to the LaserJet as well.
  100.  */
  101.  
  102. /* Margins are left, bottom, right, top. */
  103. /* from Frans van Hoesel hoesel@rugr86.rug.nl. */
  104. /* A4 has a left margin of 1/8 inch and at a printing width of
  105.  * 8 inch this give a right margin of 0.143. The 0.09 top margin is
  106.  * not the actual margin - which is 0.07 - but compensates for the
  107.  * inexact paperlength which is set to 117 10ths 
  108.  * Somebody should check for letter sized paper. I left it at 0.07
  109.  */
  110. #define DESKJET_MARGINS_LETTER  0.25, 0.50, 0.25, 0.07
  111. #define DESKJET_MARGINS_A4      0.125, 0.5, 0.143, 0.09
  112. /* Similar margins for the LaserJet, */
  113. /* from Eddy Andrews eeandrew@pyr.swan.ac.uk. */
  114. #define LASERJET_MARGINS_A4    0.25, 0.20, 0.25, 0.00
  115. #define LASERJET_MARGINS_LETTER    0.35, 0.20, 0.35, 0.00
  116.  
  117. /* The number of blank lines that make it worthwhile to reposition */
  118. /* the cursor. */
  119. #define MIN_SKIP_LINES 7
  120.  
  121. /* We round up the LINE_SIZE to a multiple of a ulong for faster scanning. */
  122. #define W sizeof(word)
  123.  
  124. /* Printer types */
  125. #define LJ    0
  126. #define LJplus    1
  127. #define LJ2p    2
  128. #define LJ3    3
  129. #define DJ    4
  130. #define DJ500    5
  131. #define LJ4    6
  132.  
  133. /*
  134.  * The notion that there is such a thing as a "PCL printer" is a fiction:
  135.  * no two "PCL" printers, even at the same PCL level, have compatible
  136.  * command sets.  The command strings below were established by hearsay
  137.  * and by trial and error.  (The H-P documentation isn't fully accurate
  138.  * either; for example, it doesn't reveal that the DeskJet printers
  139.  * implement anything beyond PCL 3.)
  140.  */
  141.  
  142. /* Printer capabilities */
  143. typedef enum {
  144.     mode_0,        /* PCL 3, use <ESC>*p+<n>Y for vertical spacing */
  145.     mode_2,        /* PCL 4, use <ESC>*b<n>Y for vertical spacing */
  146.     mode_2p,    /* PCL 4 but no vertical spacing */
  147.     mode_3        /* PCL 5, use <ESC>*b<n>Y and clear seed row */
  148.             /* (includes mode 2) */
  149. } compression_modes;
  150.  
  151. /* The device descriptors */
  152. private dev_proc_open_device(hpjet_open);
  153. private dev_proc_print_page(djet_print_page);
  154. private dev_proc_print_page(djet500_print_page);
  155. private dev_proc_print_page(ljet_print_page);
  156. private dev_proc_print_page(ljetplus_print_page);
  157. private dev_proc_print_page(ljet2p_print_page);
  158. private dev_proc_print_page(ljet3_print_page);
  159. private dev_proc_print_page(ljet4_print_page);
  160.  
  161. gx_device_procs prn_hp_procs =
  162.   prn_matrix_procs(hpjet_open, gdev_pcl_get_initial_matrix,
  163.     gdev_prn_output_page, gdev_prn_close);
  164.  
  165. gx_device_printer far_data gs_deskjet_device =
  166.   prn_device(prn_hp_procs, "deskjet",
  167.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  168.     X_DPI, Y_DPI,
  169.     0, 0, 0, 0,        /* margins filled in by hpjet_open */
  170.     1, djet_print_page);
  171.  
  172. gx_device_printer far_data gs_djet500_device =
  173.   prn_device(prn_hp_procs, "djet500",
  174.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  175.     X_DPI, Y_DPI,
  176.     0, 0, 0, 0,        /* margins filled in by hpjet_open */
  177.     1, djet500_print_page);
  178.  
  179. gx_device_printer far_data gs_laserjet_device =
  180.   prn_device(prn_hp_procs, "laserjet",
  181.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  182.     X_DPI, Y_DPI,
  183.     0.05, 0.25, 0.55, 0.25,        /* margins */
  184.     1, ljet_print_page);
  185.  
  186. gx_device_printer far_data gs_ljetplus_device =
  187.   prn_device(prn_hp_procs, "ljetplus",
  188.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  189.     X_DPI, Y_DPI,
  190.     0.05, 0.25, 0.55, 0.25,        /* margins */
  191.     1, ljetplus_print_page);
  192.  
  193. gx_device_printer far_data gs_ljet2p_device =
  194.   prn_device(prn_hp_procs, "ljet2p",
  195.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  196.     X_DPI, Y_DPI,
  197.     0.20, 0.25, 0.25, 0.25,        /* margins */
  198.     1, ljet2p_print_page);
  199.  
  200. gx_device_printer far_data gs_ljet3_device =
  201.   prn_device(prn_hp_procs, "ljet3",
  202.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  203.     X_DPI, Y_DPI,
  204.     0.20, 0.25, 0.25, 0.25,        /* margins */
  205.     1, ljet3_print_page);
  206.  
  207. gx_device_printer far_data gs_ljet4_device =
  208.   prn_device(prn_hp_procs, "ljet4",
  209.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  210.     X_DPI2, Y_DPI2,
  211.     0.25, 0.0, 0.25, 0.25,        /* margins */
  212.     1, ljet4_print_page);
  213.  
  214. /* Forward references */
  215. private int hpjet_print_page(P6(gx_device_printer *, FILE *, int, int, compression_modes, const char *));
  216.  
  217. /* Open the printer, adjusting the margins if necessary. */
  218. private int
  219. hpjet_open(gx_device *pdev)
  220. {    /* Change the margins if necessary. */
  221.     const float _ds *m;
  222. #define ppdev ((gx_device_printer *)pdev)
  223.     if ( ppdev->print_page == djet_print_page ||
  224.          ppdev->print_page == djet500_print_page
  225.        )
  226. #undef ppdev
  227.     {    static const float m_a4[4] = { DESKJET_MARGINS_A4 };
  228.         static const float m_letter[4] = { DESKJET_MARGINS_LETTER };
  229.         m = (gdev_pcl_paper_size(pdev) == PAPER_SIZE_A4 ? m_a4 :
  230.             m_letter);
  231.     }
  232.     else    /* LaserJet */
  233.     {    static const float m_a4[4] = { LASERJET_MARGINS_A4 };
  234.         static const float m_letter[4] = { LASERJET_MARGINS_LETTER };
  235.