1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
/* Copyright (C) 1998 Aladdin Enterprises. All rights reserved.
This file is part of AFPL Ghostscript.
AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
distributor accepts any responsibility for the consequences of using it, or
for whether it serves any particular purpose or works at all, unless he or
she says so in writing. Refer to the Aladdin Free Public License (the
"License") for full details.
Every copy of AFPL Ghostscript must include a copy of the License, normally
in a plain ASCII text file named PUBLIC. The License grants you the right
to copy, modify and redistribute AFPL Ghostscript, but only under certain
conditions described in the License. Among other things, the License
requires that the copyright notice and this notice be preserved on all
copies.
*/
/*$Id$*/
/* Canon BJC command generation library */
#include "std.h"
#include "gdevbjcl.h"
/****** PRELIMINARY, SUBJECT TO CHANGE WITHOUT NOTICE. ******/
/* ---------------- Utilities ---------------- */
private void
bjc_put_bytes(stream *s, const byte *data, uint count)
{
uint ignore;
sputs(s, data, count, &ignore);
}
private void
bjc_put_hi_lo(stream *s, int value)
{
spputc(s, value >> 8);
spputc(s, value & 0xff);
}
private void
bjc_put_lo_hi(stream *s, int value)
{
spputc(s, value & 0xff);
spputc(s, value >> 8);
}
private void
bjc_put_command(stream *s, int ch, int count)
{
spputc(s, 033 /*ESC*/);
spputc(s, '(');
spputc(s, ch);
bjc_put_lo_hi(s, count);
}
/* ---------------- Commands ---------------- */
/* Line feed (^J) */
void
bjc_put_LF(stream *s)
{
spputc(s, 0x0a);
}
/* Form feed (^L) */
void
bjc_put_FF(stream *s)
{
spputc(s, 0x0c);
}
/* Carriage return (^M) */
void
bjc_put_CR(stream *s)
{
spputc(s, 0x0d);
}
/* Return to initial condition (ESC @) */
void
bjc_put_initialize(stream *s)
{
bjc_put_bytes(s, (const byte *)"\033@", 2);
}
/* Set initial condition (ESC [ K <count> <init> <id> <parm1> <parm2>) */
void
bjc_put_set_initial(stream *s)
{
bjc_put_bytes(s, (const byte *)"\033[K\002\000\000\017", 7);
}
/* Set data compression (ESC [ b <count> <state>) */
void
bjc_put_set_compression(stream *s, bjc_raster_compression_t compression)
{
bjc_put_command(s, 'b', 1);
spputc(s, compression);
}
/* Select print method (ESC ( c <count> <parm1> <parm2> [<parm3>]) */
void
bjc_put_print_method_short(stream *s, bjc_print_color_short_t color)
{
bjc_put_command(s, 'c', 1);
spputc(s, color);
}
void
bjc_put_print_method(stream *s, bjc_print_color_t color,
bjc_print_media_t media, bjc_print_quality_t quality,
bjc_black_density_t density)
{
bjc_put_command(s, 'c', 2 + (density != 0));
spputc(s, 0x10 | color);
spputc(s, (media << 4) | quality);
if (density)
spputc(s, density << 4);
}
/* Set raster resolution (ESC ( d <count> <y_res> [<x_res>]) */
void
bjc_put_raster_resolution(stream *s, int x_resolution, int y_resolution)
{
if (x_resolution == y_resolution) {
bjc_put_command(s, 'd', 2);
} else {
bjc_put_command(s, 'd', 4);
bjc_put_hi_lo(s, y_resolution);
}
bjc_put_hi_lo(s, x_resolution);
}
/* Raster skip (ESC ( e <count> <skip>) */
void
bjc_put_raster_skip(stream *s, int skip)
{
bjc_put_command(s, 'e', 2);
bjc_put_hi_lo(s, skip);
}
/* Set page margins (ESC ( g <count> <length> <lm> <rm> <top>) */
void
bjc_put_page_margins(stream *s, int length, int lm, int rm, int top)
{
byte parms[4];
int count;
parms[0] = length, parms[1] = lm, parms[2] = rm, parms[3] = top;
count = 4; /* could be 1..3 */
bjc_put_command(s, 'g', count);
bjc_put_bytes(s, parms, count);
}
/* Set media supply method (ESC * l <count> <parm1> <parm2>) */
void
bjc_put_media_supply(stream *s, bjc_media_supply_t supply,
bjc_media_type_t type)
{
bjc_put_command(s, 'l', 2);
spputc(s, 0x10 | supply);
spputc(s, type << 4);
}
/* Identify ink cartridge (ESC ( m <count> <type>) */
void
bjc_put_identify_cartridge(stream *s,
bjc_identify_cartridge_command_t command)
{
bjc_put_command(s, 'm', 1);
spputc(s, command);
}
/* CMYK raster image (ESC ( A <count> <color>) */
void
bjc_put_cmyk_image(stream *s, bjc_cmyk_image_component_t component,
const byte *data, int count)
{
bjc_put_command(s, 'A', count + 1);
spputc(s, component);
bjc_put_bytes(s, data, count);
}
/* Move by raster lines (ESC ( n <count> <lines>) */
void
bjc_put_move_lines(stream *s, int lines)
{
bjc_put_command(s, 'n', 2);
bjc_put_hi_lo(s, lines);
}
/* Set unit for movement by raster lines (ESC ( o <count> <unit>) */
void
bjc_put_move_lines_unit(stream *s, int unit)
{
bjc_put_command(s, 'o', 2);
bjc_put_hi_lo(s, unit);
}
/* Set extended margins (ESC ( p <count> <length60ths> <lm60ths> */
/* <rm60ths> <top60ths>) */
void
bjc_put_extended_margins(stream *s, int length, int lm, int rm, int top)
{
bjc_put_command(s, 'p', 8);
bjc_put_hi_lo(s, length);
bjc_put_hi_lo(s, lm);
bjc_put_hi_lo(s, rm);
bjc_put_hi_lo(s, top);
}
/* Set image format (ESC ( t <count> <depth> <format> <ink>) */
void
bjc_put_image_format(stream *s, int depth, bjc_image_format_t format,
bjc_ink_system_t ink)
{
bjc_put_command(s, 't', 3);
spputc(s, depth);
spputc(s, format);
spputc(s, ink);
}
/* Page ID (ESC ( q <count> <id>) */
void
bjc_put_page_id(stream *s, int id)
{
bjc_put_command(s, 'q', 1);
spputc(s, id);
}
/* Continue raster image (ESC ( F <count> <data>) */
void
bjc_put_continue_image(stream *s, const byte *data, int count)
{
bjc_put_command(s, 'F', count);
bjc_put_bytes(s, data, count);
}
/* BJ indexed image (ESC ( f <count> R <dot_rows> <dot_cols> <layers> */
/* <index>) */
void
bjc_put_indexed_image(stream *s, int dot_rows, int dot_cols, int layers)
{
bjc_put_command(s, 'f', 5);
spputc(s, 'R'); /* per spec */
spputc(s, dot_rows);
spputc(s, dot_cols);
spputc(s, layers);
}
|