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: gdevbjcl.c 8250 2007-09-25 13:31:24Z giles $*/
15
/* Canon BJC command generation library */
19
/****** PRELIMINARY, SUBJECT TO CHANGE WITHOUT NOTICE. ******/
21
/* ---------------- Utilities ---------------- */
24
bjc_put_bytes(stream *s, const byte *data, uint count)
28
sputs(s, data, count, &ignore);
32
bjc_put_hi_lo(stream *s, int value)
34
spputc(s, value >> 8);
35
spputc(s, value & 0xff);
39
bjc_put_lo_hi(stream *s, int value)
41
spputc(s, value & 0xff);
42
spputc(s, value >> 8);
46
bjc_put_command(stream *s, int ch, int count)
48
spputc(s, 033 /*ESC*/);
51
bjc_put_lo_hi(s, count);
54
/* ---------------- Commands ---------------- */
70
/* Carriage return (^M) */
77
/* Return to initial condition (ESC @) */
79
bjc_put_initialize(stream *s)
81
bjc_put_bytes(s, (const byte *)"\033@", 2);
84
/* Set initial condition (ESC [ K <count> <init> <id> <parm1> <parm2>) */
86
bjc_put_set_initial(stream *s)
88
bjc_put_bytes(s, (const byte *)"\033[K\002\000\000\017", 7);
91
/* Set data compression (ESC [ b <count> <state>) */
93
bjc_put_set_compression(stream *s, bjc_raster_compression_t compression)
95
bjc_put_command(s, 'b', 1);
96
spputc(s, compression);
99
/* Select print method (ESC ( c <count> <parm1> <parm2> [<parm3>]) */
101
bjc_put_print_method_short(stream *s, bjc_print_color_short_t color)
103
bjc_put_command(s, 'c', 1);
107
bjc_put_print_method(stream *s, bjc_print_color_t color,
108
bjc_print_media_t media, bjc_print_quality_t quality,
109
bjc_black_density_t density)
111
bjc_put_command(s, 'c', 2 + (density != 0));
112
spputc(s, 0x10 | color);
113
spputc(s, (media << 4) | quality);
115
spputc(s, density << 4);
118
/* Set raster resolution (ESC ( d <count> <y_res> [<x_res>]) */
120
bjc_put_raster_resolution(stream *s, int x_resolution, int y_resolution)
122
if (x_resolution == y_resolution) {
123
bjc_put_command(s, 'd', 2);
125
bjc_put_command(s, 'd', 4);
126
bjc_put_hi_lo(s, y_resolution);
128
bjc_put_hi_lo(s, x_resolution);
131
/* Raster skip (ESC ( e <count> <skip>) */
133
bjc_put_raster_skip(stream *s, int skip)
135
bjc_put_command(s, 'e', 2);
136
bjc_put_hi_lo(s, skip);
139
/* Set page margins (ESC ( g <count> <length> <lm> <rm> <top>) */
141
bjc_put_page_margins(stream *s, int length, int lm, int rm, int top)
146
parms[0] = length, parms[1] = lm, parms[2] = rm, parms[3] = top;
147
count = 4; /* could be 1..3 */
148
bjc_put_command(s, 'g', count);
149
bjc_put_bytes(s, parms, count);
152
/* Set media supply method (ESC * l <count> <parm1> <parm2>) */
154
bjc_put_media_supply(stream *s, bjc_media_supply_t supply,
155
bjc_media_type_t type)
157
bjc_put_command(s, 'l', 2);
158
spputc(s, 0x10 | supply);
159
spputc(s, type << 4);
162
/* Identify ink cartridge (ESC ( m <count> <type>) */
164
bjc_put_identify_cartridge(stream *s,
165
bjc_identify_cartridge_command_t command)
167
bjc_put_command(s, 'm', 1);
171
/* CMYK raster image (ESC ( A <count> <color>) */
173
bjc_put_cmyk_image(stream *s, bjc_cmyk_image_component_t component,
174
const byte *data, int count)
176
bjc_put_command(s, 'A', count + 1);
177
spputc(s, component);
178
bjc_put_bytes(s, data, count);
181
/* Move by raster lines (ESC ( n <count> <lines>) */
183
bjc_put_move_lines(stream *s, int lines)
185
bjc_put_command(s, 'n', 2);
186
bjc_put_hi_lo(s, lines);
189
/* Set unit for movement by raster lines (ESC ( o <count> <unit>) */
191
bjc_put_move_lines_unit(stream *s, int unit)
193
bjc_put_command(s, 'o', 2);
194
bjc_put_hi_lo(s, unit);
197
/* Set extended margins (ESC ( p <count> <length60ths> <lm60ths> */
198
/* <rm60ths> <top60ths>) */
200
bjc_put_extended_margins(stream *s, int length, int lm, int rm, int top)
202
bjc_put_command(s, 'p', 8);
203
bjc_put_hi_lo(s, length);
204
bjc_put_hi_lo(s, lm);
205
bjc_put_hi_lo(s, rm);
206
bjc_put_hi_lo(s, top);
209
/* Set image format (ESC ( t <count> <depth> <format> <ink>) */
211
bjc_put_image_format(stream *s, int depth, bjc_image_format_t format,
212
bjc_ink_system_t ink)
215
bjc_put_command(s, 't', 3);
221
/* Page ID (ESC ( q <count> <id>) */
223
bjc_put_page_id(stream *s, int id)
225
bjc_put_command(s, 'q', 1);
229
/* Continue raster image (ESC ( F <count> <data>) */
231
bjc_put_continue_image(stream *s, const byte *data, int count)
233
bjc_put_command(s, 'F', count);
234
bjc_put_bytes(s, data, count);
237
/* BJ indexed image (ESC ( f <count> R <dot_rows> <dot_cols> <layers> */
240
bjc_put_indexed_image(stream *s, int dot_rows, int dot_cols, int layers)
242
bjc_put_command(s, 'f', 5);
243
spputc(s, 'R'); /* per spec */