xref: /plan9/sys/src/cmd/gs/src/gdev4081.c (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1991, 1996 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gdev4081.c,v 1.6 2004/08/04 23:33:29 stefan Exp $*/
18 /* Ricoh 4081 laser printer driver */
19 #include "gdevprn.h"
20 
21 #define X_DPI 300			/* pixels per inch */
22 #define Y_DPI 300			/* pixels per inch */
23 
24 /* The device descriptor */
25 private dev_proc_print_page(r4081_print_page);
26 const gx_device_printer far_data gs_r4081_device =
27   prn_device(prn_std_procs, "r4081",
28 	85,				/* width_10ths, 8.5" */
29 	110,				/* height_10ths, 11" */
30 	X_DPI, Y_DPI,
31 	0.25, 0.16, 0.25, 0.16,		/* margins */
32 	1, r4081_print_page);
33 
34 /* ------ Internal routines ------ */
35 
36 
37 /* Send the page to the printer. */
38 private int
r4081_print_page(gx_device_printer * pdev,FILE * prn_stream)39 r4081_print_page(gx_device_printer *pdev, FILE *prn_stream)
40 {
41 	int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
42 	int out_size = ((pdev->width + 7) & -8) ;
43 	byte *out = (byte *)gs_malloc(pdev->memory, out_size, 1, "r4081_print_page(out)");
44 	int lnum = 0;
45 	int last = pdev->height;
46 
47 	/* Check allocations */
48 	if ( out == 0 )
49 	{	if ( out )
50 			gs_free(pdev->memory, (char *)out, out_size, 1,
51 				"r4081_print_page(out)");
52 		return -1;
53 	}
54 
55 	/* find the first line which has something to print */
56 	while ( lnum < last )
57 	{
58 		gdev_prn_copy_scan_lines(pdev, lnum, (byte *)out, line_size);
59 		if ( out[0] != 0 ||
60 		     memcmp((char *)out, (char *)out+1, line_size-1)
61 		   )
62 			break;
63 		lnum ++;
64 	}
65 
66 	/* find the last line which has something to print */
67 	while (last > lnum) {
68 		gdev_prn_copy_scan_lines(pdev, last-1, (byte *)out, line_size);
69 		if ( out[0] != 0 ||
70 		     memcmp((char *)out, (char *)out+1, line_size-1)
71 		   )
72 			break;
73 		last --;
74 	}
75 
76 	/* Initialize the printer and set the starting position. */
77 	fprintf(prn_stream,"\033\rP\033\022YB2 \033\022G3,%d,%d,1,1,1,%d@",
78 			out_size, last-lnum, (lnum+1)*720/Y_DPI);
79 
80 	/* Print lines of graphics */
81 	while ( lnum < last )
82 	   {
83 		gdev_prn_copy_scan_lines(pdev, lnum, (byte *)out, line_size);
84 		fwrite(out, sizeof(char), line_size, prn_stream);
85 		lnum ++;
86 	   }
87 
88 	/* Eject the page and reinitialize the printer */
89 	fputs("\f\033\rP", prn_stream);
90 
91 	gs_free(pdev->memory, (char *)out, out_size, 1, "r4081_print_page(out)");
92 	return 0;
93 }
94