Debian Codegraph @

contrib/pcl3/src/pclgen.h

raw
1 /******************************************************************************
2 File: $Id: pclgen.h,v 1.25 2001/08/18 17:41:29 Martin Rel $
3 Contents: Header for PCL-generating routines
4 Author: Martin Lottermoser, Greifswaldstrasse 28, 38124 Braunschweig,
5 Germany. E-mail: [email protected].
6
7 *******************************************************************************
8 * *
9 * Copyright (C) 1999, 2000, 2001 by Martin Lottermoser *
10 * All rights reserved *
11 * *
12 *******************************************************************************
13
14 The functions declared in this header file generate code for
15 Hewlett-Packard's Printer Command Language level 3+ ("PCL 3+", also called
16 "PCL 3 Plus").
17
18 The routines support only raster graphics data.
19
20 ******************************************************************************/
21
22 #ifndef _pclgen_h /* Inclusion protection */
23 #define _pclgen_h
24
25 /*****************************************************************************/
26
27 /* Standard headers */
28 #include "gp.h"
29
30 /*****************************************************************************/
31
32 /* PCL dialects */
33 typedef enum {
34 pcl_level_3plus_DJ500,
35 /* End Raster Graphics is still ESC * r B, no Shingling */
36 pcl_level_3plus_ERG_both,
37 /* ESC*rbC, otherwise identical with 'pcl_level_3plus_S5' */
38 pcl_level_3plus_S5,
39 /* DeskJet 500 series except 540: old quality commands, no
40 Configure Raster Data, ESC*rC */
41 pcl_level_3plus_S68,
42 /* DeskJet 540, DeskJet 600 and 800 series */
43 pcl_level_3plus_CRD_only
44 /* printers always and only using Configure Raster Data instead of
45 Set Number of Planes per Row and Set Raster Graphics Resolution */
46 } pcl_Level;
47
48 /* Test macros */
49 #define pcl_use_oldERG(level) (level <= pcl_level_3plus_DJ500)
50 #define pcl_use_oldquality(level) (level <= pcl_level_3plus_S5)
51 #define pcl_has_CRD(level) (level >= pcl_level_3plus_S68)
52
53 /*****************************************************************************/
54
55 /* Page Size codes (permitted arguments for the PCL command "Page Size")
56
57 There exists an area of confusion around this command in connection with
58 "orientation" in various senses. Unfortunately, the documentation made
59 externally available by Hewlett-Packard is not only incomplete but also
60 inconsistent in this respect. (Well, not only in this respect, but don't
61 get me started on this topic or I'll run out of screen space.) In
62 particular, HP does not distinguish between "input orientation"
63 (orientation of a sheet with respect to the feeding direction: short edge
64 first or long edge first) and "page orientation" (orientation of a sheet
65 with respect to the "up" direction of the page contents: portrait or
66 landscape). This is further complicated by the fact that PCL permits
67 several relative orientations between text and graphics data.
68
69 The following information is therefore partially in disagreement with
70 HP documentation but does agree with the actual behaviour of the DJ 850C.
71
72 (1) The Page Orientation command has no influence on the orientation of
73 raster graphics data.
74 (2) Therefore it is possible to define, independent of the Page Orientation
75 setting, a coordinate system on the medium by reference to the printing
76 of raster lines ("rows"): the order of pixels within a row defines what
77 is left and right, and the order in which successive rows are printed
78 distinguishes between up and down. I call this the "raster space"
79 coordinate system. (Its units are irrelevant, but we need the
80 directions.)
81 (3) Because of the way DeskJet printers are constructed (limited memory!),
82 raster space is fixed with respect to the feeding direction: the "up"
83 edge of a sheet in raster space is the one entering the printer first
84 (the leading edge).
85 (4) Hence the media orientation in raster space depends only on the
86 input orientation: short edge first leads to portrait and long edge
87 first to landscape orientation in raster space.
88 (5) Among other effects, the Page Size command sets in particular the
89 printable region for the media size requested.
90 (6) For raster graphics data, clipping occurs at the edge of the printable
91 region. This happens at the right edge in raster space.
92 (7) It is not possible in PCL to specify the input orientation one has
93 chosen. In particular, the sign of a Page Size code has no influence on
94 the printable region as seen in raster space.
95 (8) Some Page Size codes do modify the orientation for text printing on
96 some printers, but this can be overridden with a subsequent Page
97 Orientation command.
98 (9) The Page Size command usually sets up the printable region under the
99 assumption of portrait orientation in raster space (i.e., the input
100 orientation is short edge first). Exceptions occur with envelope sizes
101 (Env10 and EnvDL) on older DeskJet printers (500 and 500C, possibly
102 also 400) where envelopes have to be fed long edge first.
103
104 The key conclusion to be drawn from this is that the layer represented by
105 the functions in this interface does not have any information on the media
106 orientation in raster space nor can this information be formulated in PCL
107 and passed through this layer. It is information shared between the printer
108 and the client code calling this interface, and the caller must therefore
109 obtain it from an external source.
110
111 In introducing the concept of a "raster space" I have deliberately avoided
112 the term "physical page" used in the PCL documentation. The latter is not
113 made sufficiently precise, and for printing raster data as done here the
114 first concept is the one required.
115
116 Two Page Size codes are marked "PS3". These are from Adobe's "LanguageLevel
117 3 Specification and Adobe PostScript 3 Version 3010 Product Supplement"
118 (dated 1997-10-10), page 352, where eight PCL-5 page size codes are listed.
119 Six of these agree with PCL-3 page size codes, and the remaining two are
120 those inserted here and marked "PS3". I have not heard of any PCL-3 printer
121 supporting these two sizes as discrete sizes.
122
123 The identifiers are usually named after the corresponding 'mediaOption'
124 keyword from Adobe's PPD 4.3 specification.
125 */
126 typedef enum {
127 pcl_ps_default = 0, /* default size for the printer (e.g., BPD03004 or
128 BPD02926; but note that in some versions of these documents the text
129 representation is wrong, you should look at the hex codes) */
130 pcl_ps_Executive = 1, /* US Executive (7.25 x 10.5 in).
131 According to Adobe's PPD 4.3 specification, media sizes called by this name
132 vary by up to 1/2 in. */
133 pcl_ps_Letter = 2, /* US Letter (8.5 x 11 in) */
134 pcl_ps_Legal = 3, /* US Legal (8.5 x 14 in) */
135 pcl_ps_Tabloid = 6, /* US Tabloid (11 x 17 in) or Ledger (17 x 11 in)
136 (DJ1120C). The designation as Tabloid versus Ledger
137 is not always consistent. I'm following PPD 4.3. */
138 pcl_ps_Statement = 15, /* US Statement (5.5 x 8.5 in) (DJ1120C) */
139 pcl_ps_HPSuperB = 16, /* Super B (13 x 19 in (330 x 483 mm) according to
140 DJ1120C, while 305 x 487 mm according to PPD 4.3).
141 Not supported in PCL 3 according to BPD07645
142 (HP 2500C). */
143 pcl_ps_A6 = 24, /* ISO/JIS A6 (105 x 148 mm) */
144 pcl_ps_A5 = 25, /* ISO/JIS A5 (148 x 210 mm) */
145 pcl_ps_A4 = 26, /* ISO/JIS A4 (210 x 297 mm) */
146 pcl_ps_A3 = 27, /* ISO/JIS A3 (297 x 420 mm) (DJ1120C, BPL02327) */
147 pcl_ps_JISB5 = 45, /* JIS B5 (182 x 257 mm) */
148 pcl_ps_JISB4 = 46, /* JIS B4 (257 x 364 mm) (DJ1120C, BPL02327) */
149 pcl_ps_Postcard = 71, /* Japanese Hagaki postcard (100 x 148 mm) */
150 pcl_ps_DoublePostcard = 72, /* Japanese Oufuko-Hagaki postcard
151 (148 x 200 mm) (DJ6/8) */
152 pcl_ps_A6Card = 73, /* "ISO and JIS A6 card" (DJ6/8, DJ1120C). This is the
153 value given for most DeskJets supporting A6. I do
154 not know what the difference between this value and
155 pcl_ps_A6 (24) is. */
156 pcl_ps_Index4x6in = 74, /* US Index card (4 x 6 in) */
157 pcl_ps_Index5x8in = 75, /* US Index card (5 x 8 in) */
158 pcl_ps_Index3x5in = 78, /* US Index card (3 x 5 in) */
159 pcl_ps_EnvMonarch = 80, /* US Monarch (3.875 x 7.5 in) (PS3, BPL02327) */
160 pcl_ps_Env10 = 81, /* US No. 10 envelope (4.125 x 9.5 in) */
161 pcl_ps_Env10_Negative = -81, /* also US No. 10 envelope */
162 /* According to Lexmark-PTR, 89 is US No. 9 envelope (3.875 x 8.875 in). */
163 pcl_ps_EnvDL = 90, /* ISO DL (110 x 220 mm) */
164 pcl_ps_EnvDL_Negative = -90, /* also ISO DL. This value is hinted at in
165 TRG500 p. 3-2 in the "Range" line at the bottom of the table and it is
166 explicitly listed in DJ3/4 on p. 36. On a DJ 850C, I found no difference in
167 text orientation with respect to the value 90. */
168 pcl_ps_EnvC5 = 91, /* ISO C5 (162 x 229 mm) in PCL 5 (PS3, BPL02327) */
169 pcl_ps_EnvC6 = 92, /* ISO C6 (114 x 162 mm) */
170 pcl_ps_ISOB5 = 100, /* ISO B5 (176 x 250 mm, BPL02327; the dimensions in
171 millimetres in BPL02327 are wrong, those in inches are right) */
172 pcl_ps_CustomPageSize = 101, /* Custom page size */
173 pcl_ps_EnvUS_A2 = 109, /* US A2 envelope (4.375 x 5.75 in) */
174 pcl_ps_EnvChou3 = 110, /* Japanese long Envelope #3 (120 mm x 235 mm)
175 (DJ1120C) */
176 pcl_ps_EnvChou4 = 111, /* Japanese long envelope #4 (90 mm x 205 mm)
177 (DJ1120C) */
178 pcl_ps_EnvKaku2 = 113 /* Kaku envelope (240 x 332 mm) (DJ1120C) */
179 } pcl_PageSize;
180
181 /*****************************************************************************/
182
183 /* Raster graphics compression methods */
184 typedef enum {
185 pcl_cm_none = 0, /* Unencoded, non-compressed method */
186 pcl_cm_rl = 1, /* Run-Length Encoding */
187 pcl_cm_tiff = 2, /* Tagged Image File Format (TIFF) revision 4.0
188 "packbits" encoding */
189 pcl_cm_delta = 3, /* Delta Row Compression */
190 pcl_cm_adaptive = 5, /* Adaptive Compression */
191 pcl_cm_crdr = 9 /* Compressed Replacement Delta Row Encoding */
192 } pcl_Compression;
193
194 /* Macro to test for differential compression methods */
195 #define pcl_cm_is_differential(cm) \
196 ((cm) == pcl_cm_delta || (cm) == pcl_cm_adaptive || (cm) == pcl_cm_crdr)
197
198 /*****************************************************************************/
199
200 /* Type and constants for boolean variables */
201 typedef int pcl_bool;
202 #ifndef FALSE
203 #define FALSE 0
204 #else
205 #if FALSE != 0
206 #error "FALSE is defined as non-zero."
207 #endif /* FALSE != 0 */
208 #endif /* FALSE */
209 #ifndef TRUE
210 #define TRUE 1
211 #else
212 #if TRUE == 0
213 #error "TRUE is defined as zero."
214 #endif /* TRUE == 0 */
215 #endif /* TRUE */
216
217 /* Palette (process colour model) */
218 typedef enum {
219 pcl_no_palette, /* Don't send Number of Planes per Row */
220 pcl_black,
221 pcl_CMY,
222 pcl_CMYK,
223 pcl_RGB, /* Using the RGB palette is discouraged by HP. */
224 pcl_any_palette /* Don't use this value unless you know what you are
225 doing. */
226 } pcl_Palette;
227
228 /* Information per colorant for raster images */
229 typedef struct {
230 unsigned int hres, vres; /* Resolution in ppi. The orientation refers to
231 raster space. Both values must be non-zero. */
232 unsigned int levels; /* Number of intensity levels. 2 or larger. */
233 } pcl_ColorantState;
234
235 /*****************************************************************************/
236
237 /* 'pcl_Octet' is used to store 8-bit bytes as unsigned numbers. */
238 #ifndef _pcl_Octet_defined
239 #define _pcl_Octet_defined
240 typedef unsigned char pcl_Octet;
241 #endif
242
243 /* Octet strings */
244 typedef struct {
245 pcl_Octet *str; /* Data area for storing the octet string. */
246 int length; /* Length of 'str' in octets (non-negative). */
247 } pcl_OctetString;
248 /* A "valid" pcl_OctetString is one where either 'length' is zero, or
249 'length' is positive and 'str' is non-NULL and points to a storage
250 area of at least 'length' octets.
251 A "zero" pcl_OctetString is one where 'length' is zero.
252 */
253
254 /*****************************************************************************/
255
256 /* File-global data */
257 typedef struct {
258 pcl_Level level;
259
260 /* Printer initialization */
261 int NULs_to_send;
262 char
263 *PJL_job, /* PJL job name. Ignored if NULL. */
264 *PJL_language; /* PJL personality. Ignored if NULL. */
265
266 /* Additional initialization commands (ignored if zero) */
267 pcl_OctetString
268 init1, /* send immediately after resetting the printer */
269 init2; /* send after all other initialization commands */
270
271 /* Media */
272 pcl_PageSize size;
273 int
274 media_type,
275 media_source, /* 0: don't request a particular media source */
276 media_destination, /* 0: don't request a particular media destination.
277 Not based on HP documentation. */
278 duplex; /* -1: don't request anything in this respect,
279 0: simplex, 1: duplex long-edge binding, 2: duplex short-edge binding
280 (BPL02705). I assume the correct interpretation of the duplex values to
281 be:
282 1: duplex, print back side with the same top edge in raster space
283 2: duplex, print back side with top and bottom edges exchanged in
284 raster space
285 */
286 pcl_bool manual_feed;
287
288 /* Print quality selection. Which of these variables are used depends on the
289 PCL level chosen. */
290 int
291 print_quality,
292 depletion, /* 0: no depletion command */
293 shingling,
294 raster_graphics_quality;
295
296 /* Colour information */
297 pcl_Palette palette;
298 unsigned int number_of_colorants;
299 pcl_ColorantState *colorant;
300 /* This variable must either be NULL or point to an array of at least
301 'number_of_colorants' elements. The order of colorants is (K)(CMY) except
302 for 'pcl_any_palette'. If the pointer is NULL, 'colorant_array' is used
303 instead. */
304 pcl_ColorantState colorant_array[4];
305 /* Used if 'colorant' is NULL and with the same meaning. This is only
306 possible if 'number_of_colorants' is at most 4. */
307 pcl_bool order_CMYK;
308 /* For pcl_CMYK, should the order of bit planes when sent to the printer be
309 reversed to CMYK instead of KCMY? This is not standard PCL but is needed
310 by at least one Olivetti printer (Olivetti JP792). */
311
312 int dry_time; /* negative for "don't send this command" */
313 pcl_Compression compression;
314
315 /* Derived information managed by the routines declared here. These fields
316 have reliable values only after a call to plc3_init_file(). */
317 unsigned short number_of_bitplanes;
318 unsigned short black_planes;
319 unsigned int minvres; /* minimal vertical resolution */
320 } pcl_FileData;
321
322 /*****************************************************************************/
323
324 /* Types for raster data */
325
326 typedef struct {
327 /* Data to be provided by the caller */
328 unsigned int width; /* maximal length of raster lines in pixels at the
329 lowest horizontal resolution. This may be zero to indicate "as large as
330 possible", but this could waste printer memory. Always set this when
331 using an RGB palette unless you have reliable data on the clipping
332 boundary. The value should probably always be a multiple of 8. */
333 pcl_FileData *global; /* must point to the data used in the last call
334 to pcl3_init_file() */
335 pcl_OctetString
336 *previous, *next;
337 /* These variables point to the sequences of bit planes for the old and
338 the new strip group. The total number of bit planes per group can be
339 obtained in the 'number_of_bitplanes' parameter in '*global'.
340
341 The order of bit planes within a strip group is as follows:
342 - Each strip group consists of a number of "colorant strips", one for
343 each colorant. All strips in such a group cover the same region on
344 the page. Except for 'pcl_RGB', colorant strips are ordered in the
345 sequence (K)(CMY), independent of 'order_CMYK'. For an RGB palette,
346 the order is (of course) RGB.
347 - Each colorant strip contains a number of pixel lines for this
348 colorant. If there is more than one line, the lines are ordered from
349 top to bottom as seen from raster space. The number of lines is
350 the ratio of that colorant's vertical resolution to the smallest
351 vertical resolution.
352 - Within each pixel line for a colorant, bit planes are ordered from
353 least to most significant. The number of bit planes within a line is
354 pcl3_levels_to_planes(levels) for this colorant.
355 When bit planes are again combined into lines for a particular
356 colorant, the resulting value per pixel denotes the intensity for
357 that colorant. A value of zero denotes absence of that colorant.
358 'previous' will be ignored (and may then be NULL) unless a differential
359 compression method is requested (pcl_cm_is_differential()).
360
361 When using an RGB palette you should always send bit planes extending
362 over the whole 'width' because shorter bit planes are implicitly
363 extended with null octets and a pixel value of zero denotes black in an
364 RGB palette which is not usually desired.
365 */
366 pcl_Octet *workspace[2];
367 /* Storage for the use of these routines. workspace[0] must be non-NULL,
368 workspace[1] will be ignored except for Delta Row Compression. */
369 size_t workspace_allocated;
370 /* Length allocated for each non-NULL 'workspace[]'. This should be at
371 least 2 larger than the longest possible bit plane, otherwise raster
372 data might have to be sent in uncompressed form even if that would take
373 more space. */
374
375 /* Internal data for these routines */
376 pcl_Compression current_compression; /* last compression method used */
377 pcl_OctetString **seed_plane; /* seed plane indexed by plane index */
378 } pcl_RasterData;
379
380 /******************************************************************************
381
382 The routines assume a simple state machine:
383
384 - You are either on a page or between pages.
385 - If you are on a page, you are either in raster mode or not.
386
387 You should call pcl3_init_file() before the first page and between pages
388 whenever you change the file-global data (like the resolution). Otherwise,
389 use the ..._begin() and ..._end() functions to navigate between the states.
390
391 Look into the implementation file for detailed interface descriptions for
392 these routines.
393
394 The error conventions are the same for all file, page and raster functions:
395 - A return code of zero indicates success.
396 - A positive return code indicates an argument error. This should be
397 avoidable by careful programming.
398 - A negative return code indicates an environment error (e.g., disk overflow).
399 If a function returns with a non-zero code, an error message will have been
400 issued on standard error.
401
402 ******************************************************************************/
403
404 /* Auxiliary functions */
405 extern unsigned int pcl3_levels_to_planes(unsigned int levels);
406 extern int pcl3_set_printquality(pcl_FileData *data, int quality);
407 extern int pcl3_set_mediatype(pcl_FileData *data, int mediatype);
408 extern int pcl3_set_oldquality(pcl_FileData *data);
409 extern int pcl_compress(pcl_Compression method, const pcl_OctetString *in,
410 const pcl_OctetString *prev, pcl_OctetString *out);
411
412 /* File and page functions */
413 extern int pcl3_init_file(gs_memory_t *mem, gp_file *out, pcl_FileData *global);
414 extern int pcl3_begin_page(gp_file *out, pcl_FileData *global);
415 extern int pcl3_end_page(gp_file *out, pcl_FileData *global);
416 extern int pcl3_end_file(gp_file *out, pcl_FileData *global);
417
418 /* Raster functions */
419 extern int pcl3_begin_raster(gp_file *out, pcl_RasterData *data);
420 extern int pcl3_skip_groups(gp_file *out, pcl_RasterData *data,
421 unsigned int count);
422 extern int pcl3_transfer_group(gp_file *out, pcl_RasterData *data);
423 extern int pcl3_end_raster(gp_file *out, pcl_RasterData *data);
424
425 /*****************************************************************************/
426
427 #endif /* Inclusion protection */