2 |
- |
1 |
/* Copyright (C) 1989, 1992, 1993, 1996, 1999 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: gdev3852.c,v 1.5 2002/02/21 22:24:51 giles Exp $*/
|
|
|
18 |
/* IBM 3852 JetPrinter color ink jet driver for Ghostscript */
|
|
|
19 |
|
|
|
20 |
/*
|
|
|
21 |
This driver program created by Kevin M. Gift <kgift@draper.com> in Sept. 1992.
|
|
|
22 |
Modified 3/93 to correct bug in cnt_2prn size.
|
|
|
23 |
Modified 3/93 to dimension page back to 8.5, which seems to
|
|
|
24 |
work better than the actual page width of 7.6, ie. it uses
|
|
|
25 |
the full printing width of the printer.
|
|
|
26 |
It was modeled after the V2.4.1 HP Paintjet driver (gdevpjet.c)
|
|
|
27 |
Modified by L. Peter Deutsch <ghost@aladdin.com> 1999-01-10 to remove _ss
|
|
|
28 |
modifiers inappropriately copied from other code.
|
|
|
29 |
*/
|
|
|
30 |
|
|
|
31 |
#include "gdevprn.h"
|
|
|
32 |
#include "gdevpcl.h"
|
|
|
33 |
|
|
|
34 |
/* X_DPI and Y_DPI must be the same - use the maximum graphics resolution */
|
|
|
35 |
/* for this printer */
|
|
|
36 |
#define X_DPI 84
|
|
|
37 |
#define Y_DPI 84
|
|
|
38 |
|
|
|
39 |
/* We round up LINE_SIZE to a multiple of 8 bytes */
|
|
|
40 |
/* because that's the unit of transposition from pixels to planes. */
|
|
|
41 |
/* Should = 96 (KMG) */
|
|
|
42 |
#define LINE_SIZE ((X_DPI * 86 / 10 + 63) / 64 * 8)
|
|
|
43 |
|
|
|
44 |
/* The device descriptor */
|
|
|
45 |
private dev_proc_print_page(jetp3852_print_page);
|
|
|
46 |
private gx_device_procs jetp3852_procs =
|
|
|
47 |
prn_color_procs(gdev_prn_open, gdev_prn_output_page, gdev_prn_close,
|
|
|
48 |
gdev_pcl_3bit_map_rgb_color, gdev_pcl_3bit_map_color_rgb);
|
|
|
49 |
const gx_device_printer far_data gs_jetp3852_device =
|
|
|
50 |
prn_device(jetp3852_procs, "jetp3852",
|
|
|
51 |
86, /* width_10ths, 8.6" (?) */
|
|
|
52 |
110, /* height_10ths, 11" */
|
|
|
53 |
X_DPI, Y_DPI,
|
|
|
54 |
0.0, 0, 0.0, 0, /* left, bottom, right, top margins */
|
|
|
55 |
3, jetp3852_print_page);
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
/* ------ Internal routines ------ */
|
|
|
59 |
|
|
|
60 |
/* Send the page to the printer. */
|
|
|
61 |
private int
|
|
|
62 |
jetp3852_print_page(gx_device_printer *pdev, FILE *prn_stream)
|
|
|
63 |
{
|
|
|
64 |
#define DATA_SIZE (LINE_SIZE * 8)
|
|
|
65 |
|
|
|
66 |
unsigned int cnt_2prn;
|
|
|
67 |
unsigned int count,tempcnt;
|
|
|
68 |
unsigned char vtp,cntc1,cntc2;
|
|
|
69 |
int line_size_color_plane;
|
|
|
70 |
|
|
|
71 |
byte data[DATA_SIZE];
|
|
|
72 |
byte plane_data[LINE_SIZE * 3];
|
|
|
73 |
|
|
|
74 |
/* Set initial condition for printer */
|
|
|
75 |
fputs("\033@",prn_stream);
|
|
|
76 |
|
|
|
77 |
/* Send each scan line in turn */
|
|
|
78 |
{ int lnum;
|
|
|
79 |
int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
|
|
|
80 |
int num_blank_lines = 0;
|
|
|
81 |
for ( lnum = 0; lnum < pdev->height; lnum++ )
|
|
|
82 |
{ byte *end_data = data + line_size;
|
|
|
83 |
gdev_prn_copy_scan_lines(pdev, lnum,
|
|
|
84 |
(byte *)data, line_size);
|
|
|
85 |
/* Remove trailing 0s. */
|
|
|
86 |
while ( end_data > data && end_data[-1] == 0 )
|
|
|
87 |
end_data--;
|
|
|
88 |
if ( end_data == data )
|
|
|
89 |
{ /* Blank line */
|
|
|
90 |
num_blank_lines++;
|
|
|
91 |
}
|
|
|
92 |
else
|
|
|
93 |
{ int i;
|
|
|
94 |
byte *odp;
|
|
|
95 |
byte *row;
|
|
|
96 |
|
|
|
97 |
/* Pad with 0s to fill out the last */
|
|
|
98 |
/* block of 8 bytes. */
|
|
|
99 |
memset(end_data, 0, 7);
|
|
|
100 |
|
|
|
101 |
/* Transpose the data to get pixel planes. */
|
|
|
102 |
for ( i = 0, odp = plane_data; i < DATA_SIZE;
|
|
|
103 |
i += 8, odp++
|
|
|
104 |
)
|
|
|
105 |
{ /* The following is for 16-bit machines */
|
|
|
106 |
#define spread3(c)\
|
|
|
107 |
{ 0, c, c*0x100, c*0x101, c*0x10000L, c*0x10001L, c*0x10100L, c*0x10101L }
|
|
|
108 |
static ulong spr40[8] = spread3(0x40);
|
|
|
109 |
static ulong spr8[8] = spread3(8);
|
|
|
110 |
static ulong spr2[8] = spread3(2);
|
|
|
111 |
register byte *dp = data + i;
|
|
|
112 |
register ulong pword =
|
|
|
113 |
(spr40[dp[0]] << 1) +
|
|
|
114 |
(spr40[dp[1]]) +
|
|
|
115 |
(spr40[dp[2]] >> 1) +
|
|
|
116 |
(spr8[dp[3]] << 1) +
|
|
|
117 |
(spr8[dp[4]]) +
|
|
|
118 |
(spr8[dp[5]] >> 1) +
|
|
|
119 |
(spr2[dp[6]]) +
|
|
|
120 |
(spr2[dp[7]] >> 1);
|
|
|
121 |
odp[0] = (byte)(pword >> 16);
|
|
|
122 |
odp[LINE_SIZE] = (byte)(pword >> 8);
|
|
|
123 |
odp[LINE_SIZE*2] = (byte)(pword);
|
|
|
124 |
}
|
|
|
125 |
/* Skip blank lines if any */
|
|
|
126 |
if ( num_blank_lines > 0 )
|
|
|
127 |
{
|
|
|
128 |
if (lnum == 0)
|
|
|
129 |
{ /* Skip down the page from the top */
|
|
|
130 |
/* set line spacing = 1/8 inch */
|
|
|
131 |
fputs("\0330",prn_stream);
|
|
|
132 |
/* Set vertical tab */
|
|
|
133 |
vtp = (num_blank_lines / 8);
|
|
|
134 |
fprintf(prn_stream,"\033B%c\000",vtp);
|
|
|
135 |
/* Do vertical tab */
|
|
|
136 |
fputs("\013",prn_stream);
|
|
|
137 |
num_blank_lines = 0;
|
|
|
138 |
}
|
|
|
139 |
else
|
|
|
140 |
{ /* Do "dot skips" */
|
|
|
141 |
while(num_blank_lines > 255)
|
|
|
142 |
{
|
|
|
143 |
fputs("\033e\377",prn_stream);
|
|
|
144 |
num_blank_lines -= 255;
|
|
|
145 |
}
|
|
|
146 |
vtp = num_blank_lines;
|
|
|
147 |
fprintf(prn_stream,"\033e%c",vtp);
|
|
|
148 |
num_blank_lines = 0;
|
|
|
149 |
}
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
/* Transfer raster graphics in the order R, G, B. */
|
|
|
153 |
/* Apparently it is stored in B, G, R */
|
|
|
154 |
/* Calculate the amount of data to send by what */
|
|
|
155 |
/* Ghostscript tells us the scan line_size in (bytes) */
|
|
|
156 |
|
|
|
157 |
count = line_size / 3;
|
|
|
158 |
line_size_color_plane = count / 3;
|
|
|
159 |
cnt_2prn = line_size_color_plane * 3 + 5;
|
|
|
160 |
tempcnt = cnt_2prn;
|
|
|
161 |
cntc1 = (tempcnt & 0xFF00) >> 8;
|
|
|
162 |
cntc2 = (tempcnt & 0x00FF);
|
|
|
163 |
fprintf(prn_stream, "\033[O%c%c\200\037",cntc2,cntc1);
|
|
|
164 |
fputc('\000',prn_stream);
|
|
|
165 |
fputs("\124\124",prn_stream);
|
|
|
166 |
|
|
|
167 |
for ( row = plane_data + LINE_SIZE * 2, i = 0;
|
|
|
168 |
i < 3; row -= LINE_SIZE, i++ )
|
|
|
169 |
{ int jj;
|
|
|
170 |
byte ctemp;
|
|
|
171 |
odp = row;
|
|
|
172 |
/* Complement bytes */
|
|
|
173 |
for (jj=0; jj< line_size_color_plane; jj++)
|
|
|
174 |
{ ctemp = *odp;
|
|
|
175 |
*odp++ = ~ctemp;
|
|
|
176 |
}
|
|
|
177 |
fwrite(row, sizeof(byte),
|
|
|
178 |
line_size_color_plane, prn_stream);
|
|
|
179 |
}
|
|
|
180 |
}
|
|
|
181 |
}
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
/* eject page */
|
|
|
185 |
fputs("\014", prn_stream);
|
|
|
186 |
|
|
|
187 |
return 0;
|
|
|
188 |
}
|