1
/* Copyright (C) 2001-2012 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
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.
11
Refer to licensing information at http://www.artifex.com or contact
12
Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael,
13
CA 94903, U.S.A., +1(415)492-9861, for further information.
17
/* SPARCprinter driver for Ghostscript */
20
#include <sys/types.h>
21
#include <sys/ioccom.h>
22
#include <unbdev/lpviio.h>
25
Thanks to Martin Schulte (schulte@thp.Uni-Koeln.DE) for contributing
26
this driver to Ghostscript. He supplied the following notes.
28
The device-driver (normally) returns two differnt types of Error-Conditions,
29
FATALS and WARNINGS. In case of a fatal, the print routine returns -1, in
30
case of a warning (such as paper out), a string describing the error is
31
printed to stderr and the output-operation is repeated after five seconds.
33
A problem is that not all possible errors seem to return the correct error,
34
under some circumstance I get the same response as if an error repeated,
35
that's why there is this the strange code about guessing the error.
37
I didn't implement asynchronous IO (yet), because "`normal"' multipage-
38
printings like TEX-Output seem to be printed with the maximum speed whereas
39
drawings normally occur as one-page outputs, where asynchronous IO doesn't
43
static dev_proc_open_device(sparc_open);
44
static dev_proc_print_page(sparc_print_page);
46
#define SPARC_MARGINS_A4 0.15, 0.12, 0.12, 0.15
47
#define SPARC_MARGINS_LETTER 0.15, 0.12, 0.12, 0.15
49
/* Since the print_page doesn't alter the device, this device can print in the background */
50
gx_device_procs prn_sparc_procs =
51
prn_procs(sparc_open, gdev_prn_bg_output_page, gdev_prn_close);
53
const gx_device_printer far_data gs_sparc_device =
54
prn_device(prn_sparc_procs,
56
DEFAULT_WIDTH_10THS,DEFAULT_HEIGHT_10THS,
62
/* Open the printer, and set the margins. */
64
sparc_open(gx_device *pdev)
65
{ /* Change the margins according to the paper size. */
67
static const float m_a4[4] = { SPARC_MARGINS_A4 };
68
static const float m_letter[4] = { SPARC_MARGINS_LETTER };
70
m = (pdev->height / pdev->y_pixels_per_inch >= 11.1 ? m_a4 : m_letter);
71
gx_device_set_margins(pdev, m, true);
72
return gdev_prn_open(pdev);
97
/* The static buffer is unfortunate.... */
98
static char err_buffer[80];
100
err_code_string(int err_code)
102
if ((err_code<EMOTOR)||(err_code>ESERIAL))
104
gs_sprintf(err_buffer,"err_code out of range: %d",err_code);
107
return errmsg[err_code];
113
sparc_print_page(gx_device_printer *pdev, FILE *prn)
115
struct lpvi_page lpvipage;
116
struct lpvi_err lpvierr;
119
if (ioctl(fileno(prn),LPVIIOC_GETPAGE,&lpvipage)!=0)
121
errprintf(pdev->memory, "sparc_print_page: LPVIIOC_GETPAGE failed\n");
124
lpvipage.bitmap_width=gdev_mem_bytes_per_scan_line((gx_device *)pdev);
125
lpvipage.page_width=lpvipage.bitmap_width*8;
126
lpvipage.page_length=pdev->height;
127
lpvipage.resolution = (pdev->x_pixels_per_inch == 300 ? DPI300 : DPI400);
128
if (ioctl(fileno(prn),LPVIIOC_SETPAGE,&lpvipage)!=0)
130
errprintf(pdev->memory, "sparc_print_page: LPVIIOC_SETPAGE failed\n");
133
out_size=lpvipage.bitmap_width*lpvipage.page_length;
134
out_buf=gs_malloc(pdev->memory, out_size,1,"sparc_print_page: out_buf");
135
gdev_prn_copy_scan_lines(pdev,0,out_buf,out_size);
136
while (write(fileno(prn),out_buf,out_size)!=out_size)
138
if (ioctl(fileno(prn),LPVIIOC_GETERR,&lpvierr)!=0)
140
errprintf(pdev->memory, "sparc_print_page: LPVIIOC_GETERR failed\n");
143
switch (lpvierr.err_type)
148
errprintf(pdev->memory,
149
"sparc_print_page: Printer Problem with unknown reason...");
150
dmflush(pdev->memory);
156
errprintf(pdev->memory,
157
"sparc_print_page: Printer-Warning: %s...",
158
err_code_string(lpvierr.err_code));
159
dmflush(pdev->memory);
164
errprintf(pdev->memory,
165
"sparc_print_page: Printer-Fatal: %s\n",
166
err_code_string(lpvierr.err_code));
169
errprintf(pdev->memory,
170
"sparc_print_page: Interface/driver error: %s\n",
171
err_code_string(lpvierr.err_code));
174
errprintf(pdev->memory,
175
"sparc_print_page: Unknown err_type=%d(err_code=%d)\n",
176
lpvierr.err_type,lpvierr.err_code);
182
errprintf(pdev->memory, "OK.\n");
185
gs_free(pdev->memory, out_buf,out_size,1,"sparc_print_page: out_buf");