/src/libspectre/ghostscript/devices/gdev4081.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2020 Artifex Software, Inc. |
2 | | All Rights Reserved. |
3 | | |
4 | | This software is provided AS-IS with no warranty, either express or |
5 | | implied. |
6 | | |
7 | | This software is distributed under license and may not be copied, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato, |
13 | | CA 94945, U.S.A., +1(415)492-9861, for further information. |
14 | | */ |
15 | | |
16 | | /* Ricoh 4081 laser printer driver */ |
17 | | #include "gdevprn.h" |
18 | | |
19 | | #define X_DPI 300 /* pixels per inch */ |
20 | 0 | #define Y_DPI 300 /* pixels per inch */ |
21 | | |
22 | | /* The device descriptor */ |
23 | | static dev_proc_print_page(r4081_print_page); |
24 | | const gx_device_printer far_data gs_r4081_device = |
25 | | prn_device(prn_bg_procs, "r4081", /* The print_page proc is compatible with allowing bg printing */ |
26 | | 85, /* width_10ths, 8.5" */ |
27 | | 110, /* height_10ths, 11" */ |
28 | | X_DPI, Y_DPI, |
29 | | 0.25, 0.16, 0.25, 0.16, /* margins */ |
30 | | 1, r4081_print_page); |
31 | | |
32 | | /* ------ Internal routines ------ */ |
33 | | |
34 | | /* Send the page to the printer. */ |
35 | | static int |
36 | | r4081_print_page(gx_device_printer *pdev, gp_file *prn_stream) |
37 | 0 | { |
38 | 0 | int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev); |
39 | 0 | int out_size = ((pdev->width + 7) & -8) ; |
40 | 0 | byte *out = (byte *)gs_malloc(pdev->memory, out_size, 1, "r4081_print_page(out)"); |
41 | 0 | int lnum = 0, code = 0; |
42 | 0 | int last = pdev->height; |
43 | | |
44 | | /* Check allocations */ |
45 | 0 | if ( out == 0 ) |
46 | 0 | return_error(gs_error_VMerror); |
47 | | |
48 | | /* find the first line which has something to print */ |
49 | 0 | while ( lnum < last ) |
50 | 0 | { |
51 | 0 | code = gdev_prn_copy_scan_lines(pdev, lnum, (byte *)out, line_size); |
52 | 0 | if (code < 0) |
53 | 0 | goto xit; |
54 | 0 | if ( out[0] != 0 || |
55 | 0 | memcmp((char *)out, (char *)out+1, line_size-1) |
56 | 0 | ) |
57 | 0 | break; |
58 | 0 | lnum ++; |
59 | 0 | } |
60 | | |
61 | | /* find the last line which has something to print */ |
62 | 0 | while (last > lnum) { |
63 | 0 | code = gdev_prn_copy_scan_lines(pdev, last-1, (byte *)out, line_size); |
64 | 0 | if (code < 0) |
65 | 0 | goto xit; |
66 | 0 | if ( out[0] != 0 || |
67 | 0 | memcmp((char *)out, (char *)out+1, line_size-1) |
68 | 0 | ) |
69 | 0 | break; |
70 | 0 | last --; |
71 | 0 | } |
72 | | |
73 | | /* Initialize the printer and set the starting position. */ |
74 | 0 | gp_fprintf(prn_stream,"\033\rP\033\022YB2 \033\022G3,%d,%d,1,1,1,%d@", |
75 | 0 | out_size, last-lnum, (lnum+1)*720/Y_DPI); |
76 | | |
77 | | /* Print lines of graphics */ |
78 | 0 | while ( lnum < last ) |
79 | 0 | { |
80 | 0 | code = gdev_prn_copy_scan_lines(pdev, lnum, (byte *)out, line_size); |
81 | 0 | if (code < 0) |
82 | 0 | goto xit; |
83 | 0 | gp_fwrite(out, sizeof(char), line_size, prn_stream); |
84 | 0 | lnum ++; |
85 | 0 | } |
86 | | |
87 | | /* Eject the page and reinitialize the printer */ |
88 | 0 | gp_fputs("\f\033\rP", prn_stream); |
89 | |
|
90 | 0 | xit: |
91 | 0 | gs_free(pdev->memory, (char *)out, out_size, 1, "r4081_print_page(out)"); |
92 | 0 | return code; |
93 | 0 | } |