1
/* Copyright (C) 2001-2006 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, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gdevsppr.c 8250 2007-09-25 13:31:24Z giles $*/
15
/* SPARCprinter driver for Ghostscript */
18
#include <sys/types.h>
19
#include <sys/ioccom.h>
20
#include <unbdev/lpviio.h>
23
Thanks to Martin Schulte (schulte@thp.Uni-Koeln.DE) for contributing
24
this driver to Ghostscript. He supplied the following notes.
26
The device-driver (normally) returns two differnt types of Error-Conditions,
27
FATALS and WARNINGS. In case of a fatal, the print routine returns -1, in
28
case of a warning (such as paper out), a string describing the error is
29
printed to stderr and the output-operation is repeated after five seconds.
31
A problem is that not all possible errors seem to return the correct error,
32
under some circumstance I get the same response as if an error repeated,
33
that's why there is this the strange code about guessing the error.
35
I didn't implement asynchronous IO (yet), because "`normal"' multipage-
36
printings like TEX-Output seem to be printed with the maximum speed whereas
37
drawings normally occur as one-page outputs, where asynchronous IO doesn't
41
static dev_proc_open_device(sparc_open);
42
static dev_proc_print_page(sparc_print_page);
44
#define SPARC_MARGINS_A4 0.15, 0.12, 0.12, 0.15
45
#define SPARC_MARGINS_LETTER 0.15, 0.12, 0.12, 0.15
47
gx_device_procs prn_sparc_procs =
48
prn_procs(sparc_open, gdev_prn_output_page, gdev_prn_close);
50
const gx_device_printer far_data gs_sparc_device =
51
prn_device(prn_sparc_procs,
53
DEFAULT_WIDTH_10THS,DEFAULT_HEIGHT_10THS,
59
/* Open the printer, and set the margins. */
61
sparc_open(gx_device *pdev)
62
{ /* Change the margins according to the paper size. */
64
static const float m_a4[4] = { SPARC_MARGINS_A4 };
65
static const float m_letter[4] = { SPARC_MARGINS_LETTER };
67
m = (pdev->height / pdev->y_pixels_per_inch >= 11.1 ? m_a4 : m_letter);
68
gx_device_set_margins(pdev, m, true);
69
return gdev_prn_open(pdev);
94
/* The static buffer is unfortunate.... */
95
static char err_buffer[80];
97
err_code_string(int err_code)
99
if ((err_code<EMOTOR)||(err_code>ESERIAL))
101
sprintf(err_buffer,"err_code out of range: %d",err_code);
104
return errmsg[err_code];
110
sparc_print_page(gx_device_printer *pdev, FILE *prn)
112
struct lpvi_page lpvipage;
113
struct lpvi_err lpvierr;
116
if (ioctl(fileno(prn),LPVIIOC_GETPAGE,&lpvipage)!=0)
118
errprintf("sparc_print_page: LPVIIOC_GETPAGE failed\n");
121
lpvipage.bitmap_width=gdev_mem_bytes_per_scan_line((gx_device *)pdev);
122
lpvipage.page_width=lpvipage.bitmap_width*8;
123
lpvipage.page_length=pdev->height;
124
lpvipage.resolution = (pdev->x_pixels_per_inch == 300 ? DPI300 : DPI400);
125
if (ioctl(fileno(prn),LPVIIOC_SETPAGE,&lpvipage)!=0)
127
errprintf("sparc_print_page: LPVIIOC_SETPAGE failed\n");
130
out_size=lpvipage.bitmap_width*lpvipage.page_length;
131
out_buf=gs_malloc(pdev->memory, out_size,1,"sparc_print_page: out_buf");
132
gdev_prn_copy_scan_lines(pdev,0,out_buf,out_size);
133
while (write(fileno(prn),out_buf,out_size)!=out_size)
135
if (ioctl(fileno(prn),LPVIIOC_GETERR,&lpvierr)!=0)
137
errprintf("sparc_print_page: LPVIIOC_GETERR failed\n");
140
switch (lpvierr.err_type)
146
"sparc_print_page: Printer Problem with unknown reason...");
154
"sparc_print_page: Printer-Warning: %s...",
155
err_code_string(lpvierr.err_code));
162
"sparc_print_page: Printer-Fatal: %s\n",
163
err_code_string(lpvierr.err_code));
167
"sparc_print_page: Interface/driver error: %s\n",
168
err_code_string(lpvierr.err_code));
172
"sparc_print_page: Unknown err_type=%d(err_code=%d)\n",
173
lpvierr.err_type,lpvierr.err_code);
182
gs_free(pdev->memory, out_buf,out_size,1,"sparc_print_page: out_buf");