1 /* Copyright (C) 1991, 1996 artofcode LLC. All rights reserved.
2
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2 of the License, or (at your
6 option) any later version.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16
17 */
18
19 /*$Id: gdev4081.c,v 1.3.2.1.2.1 2003/01/17 00:49:00 giles Exp $*/
20 /* Ricoh 4081 laser printer driver */
21 #include "gdevprn.h"
22
23 #define X_DPI 300 /* pixels per inch */
24 #define Y_DPI 300 /* pixels per inch */
25
26 /* The device descriptor */
27 private dev_proc_print_page(r4081_print_page);
28 const gx_device_printer far_data gs_r4081_device =
29 prn_device(prn_std_procs, "r4081",
30 85, /* width_10ths, 8.5" */
31 110, /* height_10ths, 11" */
32 X_DPI, Y_DPI,
33 0.25, 0.16, 0.25, 0.16, /* margins */
34 1, r4081_print_page);
35
36 /* ------ Internal routines ------ */
37
38
39 /* Send the page to the printer. */
40 private int
r4081_print_page(gx_device_printer * pdev,FILE * prn_stream)41 r4081_print_page(gx_device_printer *pdev, FILE *prn_stream)
42 {
43 int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
44 int out_size = ((pdev->width + 7) & -8) ;
45 byte *out = (byte *)gs_malloc(out_size, 1, "r4081_print_page(out)");
46 int lnum = 0;
47 int last = pdev->height;
48
49 /* Check allocations */
50 if ( out == 0 )
51 { if ( out )
52 gs_free((char *)out, out_size, 1,
53 "r4081_print_page(out)");
54 return -1;
55 }
56
57 /* find the first line which has something to print */
58 while ( lnum < last )
59 {
60 gdev_prn_copy_scan_lines(pdev, lnum, (byte *)out, line_size);
61 if ( out[0] != 0 ||
62 memcmp((char *)out, (char *)out+1, line_size-1)
63 )
64 break;
65 lnum ++;
66 }
67
68 /* find the last line which has something to print */
69 while (last > lnum) {
70 gdev_prn_copy_scan_lines(pdev, last-1, (byte *)out, line_size);
71 if ( out[0] != 0 ||
72 memcmp((char *)out, (char *)out+1, line_size-1)
73 )
74 break;
75 last --;
76 }
77
78 /* Initialize the printer and set the starting position. */
79 fprintf(prn_stream,"\033\rP\033\022YB2 \033\022G3,%d,%d,1,1,1,%d@",
80 out_size, last-lnum, (lnum+1)*720/Y_DPI);
81
82 /* Print lines of graphics */
83 while ( lnum < last )
84 {
85 gdev_prn_copy_scan_lines(pdev, lnum, (byte *)out, line_size);
86 fwrite(out, sizeof(char), line_size, prn_stream);
87 lnum ++;
88 }
89
90 /* Eject the page and reinitialize the printer */
91 fputs("\f\033\rP", prn_stream);
92
93 gs_free((char *)out, out_size, 1, "r4081_print_page(out)");
94 return 0;
95 }
96