Debian Codegraph @

contrib/pcl3/eprn/gdeveprn.h

raw
1 /******************************************************************************
2 File: $Id: gdeveprn.h,v 1.23 2001/04/30 05:15:51 Martin Rel $
3 Contents: Header file for the abstract ghostscript device 'eprn'
4 Author: Martin Lottermoser, Greifswaldstrasse 28, 38124 Braunschweig,
5 Germany; e-mail: [email protected].
6
7 *******************************************************************************
8 * *
9 * Copyright (C) 2000, 2001 by Martin Lottermoser *
10 * All rights reserved *
11 * *
12 *******************************************************************************
13
14 The 'eprn' device
15 *****************
16 In developing my hpdj/pcl3 driver for PCL 3+ I had to implement a lot of
17 functionality which was logically independent of PCL. This indicated that the
18 functionality offered by ghostscript's 'prn' device was insufficient and
19 should be extended, leading to this "extended prn device".
20
21 Functionality
22 =============
23 The "eprn" device offers the following services to derived devices:
24 - A simple but still flexible rendering model. A derived device defines
25 printer capability descriptions listing the supported rendering parameters,
26 lets the eprn device handle the user's rendering requests, and then just
27 fetches the pixels.
28 - A PostScript-conforming initialization of default user space with respect
29 to landscape orientation and support for the standard page device parameter
30 "LeadingEdge".
31 - Recognition of media sizes from the document and checking of supported
32 sizes based on printer descriptions
33 - Flexible handling of size-specific hardware margins
34 - Counting of pages printed across gs invocations by means of page count
35 files
36
37 Rendering Model
38 ===============
39 The "eprn" device parameterizes the printer's rendering capabilities as
40 follows:
41 - process colour model (Gray, RGB, CMY, CMY+K, CMYK)
42 - resolution in horizontal and vertical directions
43 - number of intensity levels per colorant, chosen independently for black
44 and non-black (RGB or CMY) colorants.
45 In addition, the rendering process as implemented in this driver is
46 parameterized by:
47 - method for rendering intensities (printer, halftones or error diffusion)
48 These parameters are specified by the user. The device checks whether the
49 printer supports the requested combination and, if it does, sets
50 ghostscript's internal data structures accordingly.
51
52 The derived device can obtain the resulting pixels by successively calling
53 eprn_get_planes() from the page printing procedure.
54
55 Device Coordinates
56 ==================
57 "Pixmap device space" is the coordinate system used by the "prn" device for
58 generating a pixmap and implicit in the API for accessing it (e.g.,
59 gdev_prn_copy_scan_lines()). In identifying the directions "left", "bottom",
60 "right" and "top" I'm assuming that the x axis is pointing to the right and
61 the y axis downwards. This is not concerned with the orientation of device
62 space on a sheet printed but is merely a definition of what, e.g., "down"
63 means for the eprn device: it is defined as "towards increasing prn y values".
64 This makes the code more readable for the case where the real device
65 coordinate system (on the sheet) has just this orientation. Too bad for the
66 others :-).
67
68 Terms like "width" and "height" are also defined with respect to this
69 interpretation, i.e., "width" is an extension in x direction.
70
71 Note that names and interpretations of some of ghostscript's standard
72 device structure fields (like 'width', 'height') are also based on this
73 convention although this is not explicitly stated. This does however not
74 apply to all parameters: for example, HWMargins[] and MediaSize[] are to be
75 interpreted in default user space (see gx_default_clip_box()).
76
77 One key assumption of the eprn device is that the top edge of pixmap device
78 space is the edge closest to and parallel with the medium's leading edge.
79 It is the responsibility of the derived device to ensure this. Usually
80 it means that raster lines have to be printed in the order of ascending y.
81 (The eprn device will work if the derived device violates this condition, but
82 the meaning of user-visible properties of the device would change.)
83
84 The device sets up the device coordinate system such that the device space
85 origin is the top left corner of the imageable area where "top" and "left"
86 refer to you holding the sheet with the printed side towards you and the
87 leading edge at the top. Units and directions are identical with pixmap
88 device space.
89
90 Page Descriptions
91 =================
92 When a PostScript document requests a particular page size by specifying its
93 width and height in default user space the eprn device combines this
94 information with certain conditions imposed by the derived device and looks
95 for a matching page description entry in the printer's capability
96 description. The following information from such an entry is needed for
97 correctly setting up the relation between default user space and device space:
98
99 - default orientation of the sheet in pixmap device space
100 (MS_TRANSVERSE_FLAG; set iff the sheet has width > height in pixmap
101 device space)
102 - hardware margins
103
104 This part is interpreted by the eprn device.
105
106 In addition, a page description entry may contain a number of flags
107 indicating special conditions under which this entry is to be selected or
108 carrying information on how to configure the printer. The flags are those
109 defined by mediasize.h (except that MS_TRANSVERSE_FLAG and MS_ROTATED_FLAG
110 may not be used for this purpose), their interpretation is up to the derived
111 device which must request them or to which they will become visible when the
112 entry is selected.
113
114 The eprn device takes the following items as the request to be matched with a
115 page description entry in the printer's capability description:
116
117 - the media size of the document and, if set, the "LeadingEdge" page device
118 parameter
119 - a pattern of desired (not necessarily *required*) flags
120 - an ordered list of optional flags
121
122 Media size and LeadingEdge are set via PostScript or the command line, the
123 flags can be set by the derived device through its device structure instance
124 or by calling eprn_set_media_flags(). The optional flags when combined with
125 the bitwise OR effectively define a mask of bits which may be ignored when
126 checking whether an entry matches the desired flags. The order of optional
127 flags is from most to least desirable to ignore.
128
129 The complete request is compared to the list of page descriptions as follows:
130
131 1. If the media size, irrespective of flags, cannot be matched at 5 bp
132 tolerance, the request fails with an error message to standard error.
133 2. Otherwise a shortened list containing all entries having a matching
134 size is compiled, at least conceptually. If the device supports custom
135 page sizes, they are listed at the end. This is the "base list".
136 3. If LeadingEdge is not null, the MS_TRANSVERSE_FLAG is set or cleared
137 accordingly in the pattern of desired flags. This flag is also always
138 added to the front of the list of optional flags.
139 4. A mask of flags to be ignored is set to zero.
140 5. The base list is searched for an entry agreeing with the desired flags
141 except possibly for those in the ignore mask.
142 6. If no such entry is found, the next flag in the list of optional flags is
143 added to the ignore mask and execution continues with step 5. If there is
144 no such flag, the request fails and the flag mismatch reporting function
145 is called (see below).
146 7. If a matching entry is found the list of optional flags is processed
147 backwards starting with the flag before the last one added to the ignore
148 mask. For each such flag an attempt is made to remove it from the mask.
149 If there still is at least one matching entry in the base list the flag
150 remains cleared, otherwise it is put back into the mask.
151 8. Finally, the first entry matching the request mask and the current
152 ignore mask will be selected:
153 - its media code will be made available to the derived device in the
154 eprn device's 'code' field,
155 - the hardware margins will be set from the page description (unless the
156 user has explicitly specified a value for the ".HWMargins" page device
157 parameter),
158 - default user space will be configured based on sheet orientation
159 (transverse or not in device space) and page orientation (portrait or
160 landscape in default user space).
161
162 Because the error message in step 6 has to report a mismatch on the flags
163 and because the interpretation of the flags is fixed by the derived device,
164 an error message issued by the eprn device may not be particularly
165 illuminating to the user (the user will usually think in terms of the
166 interpretation the derived device associates with these flags). Therefore
167 issuing this error message can be delegated to a function ("flag mismatch
168 reporting function") specified by the derived device in its device structure
169 instance.
170
171 ******************************************************************************/
172
173 #ifndef _gdeveprn_h /* Inclusion protection */
174 #define _gdeveprn_h
175
176 /*****************************************************************************/
177
178 /* Special Aladdin header, must be included before <sys/types.h> on some
179 platforms (e.g., FreeBSD). This necessity seems to be triggered for example
180 by <stdio.h>. */
181 #include "std.h"
182
183 /* Standard headers */
184 #include <stdio.h> /* for 'FILE' and 'size_t' */
185
186 /* Ghostscript headers */
187 #include "gdevprn.h"
188 /* This header is assumed to include a definition for 'bool' (stdpre.h). */
189
190 /* Other header files */
191 #include "mediasize.h"
192
193 /*****************************************************************************/
194
195 /* Types to describe supported page sizes and associated setup information.
196 All sizes are in bp and all orientations refer to pixmap device space.
197 */
198
199 /* Discrete page sizes */
200 typedef struct {
201 ms_MediaCode code;
202 /* The media flags in 'code' identify the conditions under which the size
203 is supported ("required flags") and carry information needed in order
204 to adapt ghostscript or the printer to using this entry ("optional
205 flags"). The distinction between the two groups of flags is fixed by the
206 derived device when calling eprn_set_media_flags() except that special
207 rules apply to MS_TRANSVERSE_FLAG which is handled by eprn.
208 Setting MS_TRANSVERSE_FLAG indicates that media of this size are normally
209 fed such that width > height in pixmap device space, otherwise
210 width <= height is assumed.
211 Setting MS_ROTATED_FLAG is not permitted.
212 The interpretation of all other flags is up to the derived device.
213 */
214 float left, bottom, right, top;
215 /* Hardware margins (non-negative) in bp */
216 } eprn_PageDescription;
217
218 /* Custom page sizes */
219 typedef struct {
220 /* The first two lines have the same meaning as for 'eprn_PageDescription'.
221 However, apart from flags, the 'code' field must be 'ms_CustomPageSize'.
222 */
223 ms_MediaCode code;
224 float left, bottom, right, top;
225 float width_min, width_max, height_min, height_max;
226 /* Permissible range in bp for width and height when a sheet's dimension is
227 given such that width <= height. */
228 } eprn_CustomPageDescription;
229
230 /*
231 Here follows an example of using "eprn_PageDescription". It describes a
232 printer supporting A4 and US Letter, the first with 5 mm margins, the latter
233 with 0.2 inches:
234
235 const eprn_PageDescription page_description[] = {
236 {ms_A4, 5*BP_PER_MM, 5*BP_PER_MM, 5*BP_PER_MM, 5*BP_PER_MM},
237 {ms_Letter, 0.2*BP_PER_IN, 0.2*BP_PER_IN, 0.2*BP_PER_IN, 0.2*BP_PER_IN},
238 {ms_none, 0, 0, 0, 0}
239 };
240
241 The last entry is a sentinel value which will be required later.
242
243 ******************************************************************************/
244
245 /* Types to describe supported combinations of resolutions, process colour
246 models and intensity levels per colorant
247
248 These types often contain pointers to lists terminated with a sentinel
249 value. As these are usually static data, this makes it easier to share data
250 between printer descriptions.
251 */
252
253 /* Process colour models */
254 typedef enum {
255 eprn_DeviceGray,
256 eprn_DeviceRGB,
257 eprn_DeviceCMY,
258 eprn_DeviceCMY_plus_K,
259 /* 'eprn_DeviceCMY_plus_K' is a process colour model using the CMYK
260 colorants but never mixing black with one of the others. The underlying
261 native colour space is 'DeviceRGB'. */
262 eprn_DeviceCMYK
263 } eprn_ColourModel;
264
265 /* Horizontal and vertical resolutions w.r.t. pixmap device space */
266 typedef struct {
267 float h, v;
268 } eprn_Resolution;
269
270 /* Range for the number of intensity levels */
271 typedef struct {
272 unsigned short from, to; /* both inclusive */
273 } eprn_IntensityLevels;
274
275 /* Combined resolutions and intensities. Any combination of the listed
276 resolutions and the listed intensity levels is permitted. */
277 typedef struct {
278 const eprn_Resolution *resolutions;
279 /* either NULL (all resolutions are accepted) or a list terminated with
280 a {0.0, 0.0} entry */
281 const eprn_IntensityLevels *levels;
282 /* non-NULL; this list is terminated with {0, 0}. The variable is a list in
283 order to permit easier specification of discrete levels. */
284 } eprn_ResLev;
285
286 /* A complete instance of a rendering capability entry */
287 typedef struct {
288 eprn_ColourModel colour_model;
289 /* A value of 'eprn_DeviceCMYK' implies the capability for
290 'eprn_DeviceCMY_plus_K' because the difference is realized in this driver
291 and is not part of the printer's capabilities.
292 In contrast, 'eprn_DeviceCMY_plus_K' or 'eprn_DeviceCMYK' do *not* imply
293 the capability for CMY or Gray! This is because we assume that
294 'colour_model' corresponds to particular hardware settings for the
295 printer.
296 */
297 const eprn_ResLev *info[2];
298 /* Supported resolutions and intensities indexed by colorant. The first
299 entry refers to black except for eprn_DeviceRGB and eprn_DeviceCMY when
300 it describes the three non-black colorants. The second entry is ignored
301 unless both black and non-black colorants are used in which case it can
302 either refer to the latter or be NULL to indicate that the black entry
303 applies also to the non-black colorants.
304 Any non-null info[] points to a list terminated with a {NULL, NULL} entry.
305 Only values for those colorants described by different (non-NULL) 'info'
306 entries in an instance of this type can be chosen independently. Hence at
307 most black can have values different from those of the other colorants.
308 */
309 } eprn_ColourInfo;
310
311 /*
312 As an example application of these types, consider a bilevel device
313 supporting 600 ppi monochrome printing:
314
315 const eprn_Resolution sixhundred[] = { {600, 600}, {0, 0}};
316 const eprn_IntensityLevels bilevel[] = { {2, 2}, {0, 0}};
317 const eprn_ResLev rl_600_2[] = { {sixhundred, bilevel}, {NULL, NULL}};
318 const eprn_ColourInfo mono_600_2[] = {
319 {eprn_DeviceGray, {rl_600_2, NULL}},
320 {eprn_DeviceGray, {NULL, NULL}}
321 };
322
323 ******************************************************************************/
324
325 /* Printer capability description */
326 typedef struct {
327 const char *name;
328 /* This string is used in error messages generated by the device. It should
329 describe the printer, not a gs device. In selecting an appropriate value
330 imagine a statement like "... is not supported by the <name>" or "The
331 <name> does not support ...".
332 */
333
334 /* Media sizes and hardware margins */
335 const eprn_PageDescription *sizes;
336 /* List of supported discrete media sizes and associated hardware margins,
337 terminated by an entry with 'code' == ms_none. This must always be
338 non-NULL. */
339 const eprn_CustomPageDescription *custom;
340 /* This may be NULL, in which case the printer does not support custom
341 page sizes. Otherwise it is a list of entries, terminated with an entry
342 having 0.0 for 'width_max'. */
343 float bottom_increment;
344 /* Change of bottom hardware margin when not printing in DeviceGray,
345 specified in bp. This correction is ignored if the bottom margin is
346 exactly zero.
347 Some HP DeskJets have a larger hardware margin at the bottom for the
348 colour cartridge but this is not the case for banner printing. */
349
350 /* Colour capabilities */
351 const eprn_ColourInfo *colour_info;
352 /* List of supported colour models, resolutions and intensity levels.
353 This must always be non-NULL and terminated with an entry having NULL as
354 'info[0]'. There must be at least one 'eprn_ColourInfo' entry permitting
355 identical resolution for all colorants.
356 */
357 } eprn_PrinterDescription;
358
359 /*
360 To continue our series of examples, here is a complete printer description:
361
362 const eprn_PrinterDescription description = {
363 "Wrzlbrnf printer", page_description, NULL, 0, mono_600_2
364 };
365
366 ******************************************************************************/
367
368 /* Intensity rendering methods */
369 typedef enum {
370 eprn_IR_printer,
371 eprn_IR_halftones,
372 eprn_IR_FloydSteinberg
373 } eprn_IR;
374
375 /*****************************************************************************/
376
377 /* Unsigned 8-bit values (should really be 'uint8_t') */
378 typedef unsigned char eprn_Octet;
379
380 /* Octet strings */
381 typedef struct {
382 eprn_Octet *str;
383 int length; /* zero or the length in 'eprn_Octet' instances of the area
384 filled starting at '*str' */
385 } eprn_OctetString;
386
387 /* Type for flag mismatch reporting function */
388 struct s_eprn_Device;
389 /* The preceding statement is needed in order to establish a forward
390 declaration for "struct s_eprn_Device" at file scope. */
391 typedef void (*eprn_FlagMismatchReporter)(const struct s_eprn_Device *dev,
392 bool no_match);
393 /* A function of this kind will be called if the requested media flags cannot
394 be satisfied by the printer although the size itself is supported for some
395 (unspecified) set of flags. The parameter 'no_match' indicates whether the
396 printer supports the set of required flags for some size or not at all
397 (this is intended to be useful in the case of flags denoting printer
398 capabilities). The requested set of media selection flags is available in
399 'dev->eprn.desired_flags' and 'dev->eprn.optional_flags' (MS_ROTATED_FLAG
400 will never be set).
401 The function must write an error message.
402 */
403
404 /*****************************************************************************/
405
406 /* The eprn device variables. These are deliberately defined as a structure
407 and not as usual in ghostscript as a macro body to be inserted into a
408 structure because I want to have namespace isolation for these fields.
409 A derived device may read any of these parameters but should never change
410 them directly. The only exception is 'soft_tumble'.
411 */
412 typedef struct s_eprn_Device {
413 /* Capabilities */
414 const eprn_PrinterDescription *cap;
415 /* non-NULL. The data pointed to may not change unless this is immediately
416 followed by a call to eprn_init_device(). */
417 char *media_file;
418 /* gs_malloc()-allocated media configuration file name.
419 Non-NULL if 'media_overrides' is non-NULL. */
420 eprn_PageDescription *media_overrides;
421 /* A list of supported media dimensions and corresponding hardware margins.
422 This is usually NULL, meaning that 'cap->sizes' and 'cap->custom' should
423 be used.
424 If non-NULL, 'media_overrides' must be terminated with an entry having
425 'code' == ms_none. If this field is non-NULL, only the sizes listed here
426 will be supported. The device will support custom page sizes only if
427 'cap->custom' is not NULL and 'media_overrides' contains an entry for
428 'ms_CustomPageSize'.
429 The pointer refers to gs_malloc()-allocated storage.
430 */
431
432 /* Page setup */
433 const ms_Flag *flag_desc;
434 /* Description of the additional flags the derived device understands. This
435 can be NULL or a list terminated with an entry having 'code' equal to
436 'ms_none'. */
437 ms_MediaCode
438 desired_flags;
439 const ms_MediaCode
440 *optional_flags; /* may be NULL; terminated with 'ms_none'. */
441 eprn_FlagMismatchReporter fmr; /* may be NULL */
442 ms_MediaCode code;
443 /* Page size and other media attributes determined based on printer
444 capabilities. A value of 'ms_none' indicates that the page description
445 entry to be used has not (yet) been successfully identified and that
446 therefore some of the other fields in this structure are not valid. */
447
448 /* Coordinates */
449 int default_orientation;
450 /* Direction of the positive y axis of default default user space (the
451 requested PageSize had width <= height) as seen from pixmap device space:
452 0 up
453 1 left
454 2 down
455 3 right
456 Hence the value is the number of +90 degrees rotations necessary to
457 obtain the "up" direction of default default user space (positive y axis)
458 from the "up" direction of pixmap device space (negative y axis).
459 The values 0 and 2 imply that the medium has width <= height in pixmap
460 device space, 1 and 3 imply height <= width. */
461 bool leading_edge_set;
462 /* True iff someone set the 'LeadingEdge' page device parameter. In this
463 case its value is stored in 'default_orientation'. The values permitted
464 for 'default_orientation' and their interpretation are chosen such that
465 this gives the desired result.
466 If this value is false, the device will select a value for
467 'default_orientation' based on the MS_TRANSVERSE_FLAG in 'code'. */
468 float
469 right_shift,
470 down_shift;
471 /* Seen from pixmap device space, the top left corner of the sheet is at
472 (-right_shift, -down_shift). Both values are in bp and represent
473 hardware margins, i.e., the origin of pixmap device space is a corner
474 of the sheet's imageable area.
475 These parameters are logically superfluous and could be derived from
476 'HWMargins[]' and possibly other data (like 'default_orientation'),
477 provided one knows what the reference system for 'HWMargins[]' is.
478 This is not documented but it seems to be default user space. In order
479 to have values with a reliable interpretation and because the data are
480 originally given in pixmap device space anyway I have introduced these
481 variables. */
482 bool keep_margins;
483 /* True iff margin information should be taken from 'HWMargins[]' instead
484 of from the printer description. */
485 bool soft_tumble;
486 /* If this field is set, every second page will have its default user
487 coordinate system rotated by 180 degrees. */
488
489 dev_proc_fillpage((*orig_fillpage));
490
491 /* Colour */
492 eprn_ColourModel
493 colour_model; /* Colour model selected */
494 unsigned int
495 black_levels, /* Number of intensity levels for black colorant */
496 non_black_levels; /* Number of intensity levels for non-black colorants */
497 eprn_IR
498 intensity_rendering; /* method to use */
499
500 /* Page counting and other spooler support */
501 char
502 *pagecount_file; /* gs_malloc()-allocated name of page count file.
503 May be NULL. */
504 bool
505 CUPS_accounting, /* Send CUPS page accounting messages. */
506 CUPS_messages; /* Add CUPS message prefixes to error messages and
507 warnings. */
508
509 /* Support for the standard page device parameter "MediaPosition" */
510 bool media_position_set;
511 int media_position;
512
513 /* Internal parameters. These have reliable values only after a successful
514 call to eprn_open(). */
515 unsigned int
516 bits_per_colorant; /* Number of bits per colorant used in 'gx_color_index'
517 values. Constant while the device is open. */
518 eprn_OctetString
519 scan_line, /* 'str' is gs_malloc()-allocated */
520 next_scan_line; /* 'str' is gs_malloc()-allocated. Non-null only for
521 Floyd-Steinberg error diffusion. */
522 unsigned int
523 octets_per_line, /* Constant while the device is open. */
524 output_planes; /* Constant while the device is open. */
525 int next_y; /* During a call to eprn_output_page(), the device y
526 coordinate for the next scan line to fetch from the "prn" device. For
527 eprn_IR_FloydSteinberg, the next scan line to return is actually already
528 present in 'next_scan_line' with its device coordinate being "next_y - 1",
529 unless 'next_y' is zero in which case we have finished. */
530 gs_gstate * pgs;
531 mediasize_table table;
532 } eprn_Eprn;
533
534 /* Macro for device structure type definitions. Note that in contrast to
535 gx_prn_device_common this macro does include the inherited attributes. */
536 #define gx_eprn_device_common \
537 gx_device_common; /* Attributes common to all devices */ \
538 gx_prn_device_common; /* Attributes for all printers */ \
539 eprn_Eprn eprn
540
541 /* Base type needed for casts */
542 typedef struct {
543 gx_eprn_device_common;
544 } eprn_Device;
545
546 #define private_st_device_EPRN(eprn_enum, eprn_reloc) \
547 gs_private_st_composite(st_eprn_Device, eprn_Device, \
548 "eprn_Device", eprn_enum, eprn_reloc);
549
550 /* Macro for initializing device structure instances (device prototypes)
551
552 This macro corresponds to the prn_device*() macros which are used when
553 basing a device directly on the prn device.
554
555 The parameters are:
556 dtype: identifier of the device structure type
557 procs: pointer to static device procedure table
558 (const gx_device_procs *, not NULL)
559 dname: name of the device (const char *, not NULL)
560 xdpi: horizontal resolution in ppi (float, positive)
561 ydpi: vertical resolution in ppi (float, positive)
562 print_page: page printing procedure to be called by
563 gdev_prn_output_page(), not NULL
564 cap: pointer to printer capability description
565 (const eprn_PrinterDescription *, not NULL, the description may
566 not change until immediately before the next call to
567 eprn_init_device())
568 flag_desc description of the non-standard flags the derived device
569 accepts (const ms_Flag *, may be NULL, otherwise terminated
570 with an entry having 'ms_none' for 'code')
571 desired pattern of desired media flags (ms_MediaCode)
572 optional NULL or a list of optional media flags (const ms_MediaCode *)
573 terminated with an 'ms_none' value
574 fmr NULL or pointer to a flag mismatch reporting function
575 (eprn_FlagMismatchReporter)
576
577 All storage referred to by pointers remains under the control of the
578 derived device and should not be modified during the lifetime of the
579 device unless explicitly permitted.
580
581 This macro assumes that it is dealing with a printer supporting at least
582 DeviceGray with 2 intensity levels and the page size described by
583 (DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS), usually US Letter or ISO A4.
584 This is also the initial state. If a derived device wishes to use another
585 initial state, it should define its own macro.
586 */
587 #define eprn_device_initdata(dtype, procs, dname, xdpi, ydpi, print_page, cap, flag_desc, desired, optional, fmr) \
588 prn_device_std_body( \
589 dtype, \
590 procs, \
591 dname, \
592 DEFAULT_WIDTH_10THS, \
593 DEFAULT_HEIGHT_10THS, \
594 xdpi, ydpi, \
595 0.0, 0.0, 0.0, 0.0, /* margins */ \
596 1, /* color_info.depth */ \
597 print_page), \
598 { \
599 cap, /* cap */ \
600 NULL, /* media_file */ \
601 NULL, /* media_overrides */ \
602 flag_desc, /* flag_desc */ \
603 desired, /* desired_flags */ \
604 optional, /* optional_flags */ \
605 fmr, /* fmr */ \
606 ms_none, /* code */ \
607 0, /* default_orientation */\
608 false, /* leading_edge_set */ \
609 0.0, /* right_shift */ \
610 0.0, /* down_shift */ \
611 false, /* keep_margins */ \
612 false, /* soft_tumble */ \
613 NULL, /* orig_fillpage */ \
614 eprn_DeviceGray, /* colour_model */ \
615 2, /* black_levels */ \
616 0, /* non_black_levels */ \
617 eprn_IR_halftones, /* intensity_rendering */ \
618 NULL, /* pagecount_file */ \
619 false, /* CUPS_accounting */ \
620 false, /* CUPS_messages */ \
621 false, /* media_position_set */\
622 0, /* media_position */ \
623 0, /* bits_per_colorant */ \
624 {NULL, 0}, /* scan_line */ \
625 {NULL, 0}, /* next_scan_line */ \
626 0, /* octets_per_line */ \
627 0, /* output_planes */ \
628 0, /* next_y */ \
629 NULL, /* pgs */ \
630 { 0 } /* table */ \
631 }
632
633 /* For the calling conventions of the following functions consult the comments
634 preceding each function's implementation. */
635
636 /* Initialize the eprn device for another printer model */
637 extern int eprn_init_device(eprn_Device *dev,
638 const eprn_PrinterDescription *desc);
639
640 /* Modify the information on supported media sizes and associated hardware
641 margins by reading new values from a file */
642 extern int eprn_set_media_data(eprn_Device *dev, const char *media_file,
643 size_t length);
644
645 /* Set media flags */
646 extern void eprn_set_media_flags(eprn_Device *dev, ms_MediaCode desired,
647 const ms_MediaCode *optional);
648
649 /*****************************************************************************/
650
651 extern dev_proc_open_device(eprn_open_device);
652 extern dev_proc_get_initial_matrix(eprn_get_initial_matrix);
653 extern dev_proc_output_page(eprn_output_page);
654 extern dev_proc_close_device(eprn_close_device);
655 extern dev_proc_map_rgb_color(eprn_map_rgb_color_for_RGB);
656 extern dev_proc_map_rgb_color(eprn_map_rgb_color_for_RGB_flex);
657 extern dev_proc_map_rgb_color(eprn_map_rgb_color_for_RGB_max);
658 extern dev_proc_map_rgb_color(eprn_map_rgb_color_for_CMY_or_K);
659 extern dev_proc_map_rgb_color(eprn_map_rgb_color_for_CMY_or_K_flex);
660 extern dev_proc_map_rgb_color(eprn_map_rgb_color_for_CMY_or_K_max);
661 extern dev_proc_map_color_rgb(eprn_map_color_rgb);
662 extern dev_proc_get_params(eprn_get_params);
663 extern dev_proc_put_params(eprn_put_params);
664 extern dev_proc_map_cmyk_color(eprn_map_cmyk_color);
665 extern dev_proc_map_cmyk_color(eprn_map_cmyk_color_flex);
666 extern dev_proc_map_cmyk_color(eprn_map_cmyk_color_max);
667 extern dev_proc_map_cmyk_color(eprn_map_cmyk_color_glob);
668 extern dev_proc_fillpage(eprn_fillpage);
669
670
671 /*****************************************************************************/
672
673 /* Access to pixels
674
675 Of course, you could also use the prn interface to obtain pixel values.
676 This, however, requires information on how eprn interprets 'gx_color_index'
677 values (see eprnrend.c for a description) and bypasses all processing steps
678 (error diffusion and the clipping of null bytes) which happen in
679 eprn_get_planes().
680 */
681
682 /* Number of bits and hence bit planes used to represent 'levels' intensity
683 levels in eprn_get_planes(). The return values are independent of the
684 device's state. */
685 extern unsigned int eprn_bits_for_levels(unsigned int levels);
686
687 /* Total number of bit planes written by eprn_get_planes().
688 The value returned is reliable only after the eprn part of the device has
689 been successfully opened. The value remains constant while the device is
690 open and equals the sum of eprn_bits_for_levels() for all colorants. */
691 extern unsigned int eprn_number_of_bitplanes(eprn_Device *dev);
692
693 /* Maximal lengths, in terms of the number of 'eprn_Octet' instances, for each
694 bit plane returned by eprn_get_planes() for this device.
695 These values are reliable after the eprn part of the device has been
696 successfully opened and remain constant while the device is open.
697 The array 'lengths' must have at least the length returned by
698 eprn_number_of_bitplanes(). */
699 extern void eprn_number_of_octets(eprn_Device *dev, unsigned int lengths[]);
700
701 /* The following function may be called only from the page printing procedure
702 (see the macro eprn_device_initdata() above). For every invocation of that
703 procedure, the first call of this function returns the scan line with
704 device coordinate y = 0, subsequent invocations return the lines with the
705 y coordinate incremented by 1 for every call.
706
707 This function returns each scan line split into bit planes and stored into
708 the areas pointed to by the 'bitplanes' array. The order of colorants is
709 (K)(CMY) or RGB, where the parentheses indicate optional groups, depending
710 on the colour model. Within each colorant, bit planes are stored from least
711 to most significant. The number of bit planes per colorant is given by
712 eprn_bits_for_levels(levels) where 'levels' is the number of intensity
713 levels for this colorant.
714
715 If the bit planes for a particular colorant result in the value zero for a
716 certain pixel, this indicates a complete absence of that colorant for this
717 pixel. The highest possible value is one less than the number of intensity
718 levels for that colorant.
719
720 The 'str' entries in the 'bitplanes' array must be non-NULL and point to
721 storage areas of a length sufficient to hold the number of octets as
722 returned by eprn_number_of_octets(). The 'length' entries will be set such
723 that there will be no trailing zero octets in the octet strings returned.
724 Bits are stored in an octet from most to least signicant bit (left to
725 right). If a bit plane does not fill an integral number of octets the last
726 octet will be filled on the right as if there were additional white pixels.
727
728 This function returns zero if there was a scan line to be fetched and a
729 non-zero value otherwise.
730 */
731 extern int eprn_get_planes(eprn_Device *dev, eprn_OctetString bitplanes[]);
732
733 /*****************************************************************************/
734
735 /* Auxiliary types and functions for parameter processing */
736
737 /* Type to describe an association between a string and an integer */
738 typedef struct {
739 const char *name;
740 int value;
741 } eprn_StringAndInt;
742
743 /* Routines on 'eprn_StringAndInt' arrays
744 These are used to map names to integers and vice versa. It is possible to
745 have several names for the same value. The first name given in the array
746 for a particular 'value' is the canonical name for this value, i.e. the one
747 returned by the eprn_get_string() routine.
748 The arrays must be terminated by entries with a NULL pointer for 'name'.
749 */
750 struct gs_param_string_s; /* Forward declaration */
751 extern int eprn_get_string(int in_value, const eprn_StringAndInt *table,
752 struct gs_param_string_s *out_value);
753 extern int eprn_get_int(const struct gs_param_string_s *in_value,
754 const eprn_StringAndInt *table, int *out_value);
755
756 /*****************************************************************************/
757
758 /* CUPS message prefixes */
759 #define CUPS_ERRPREF "ERROR: "
760 #define CUPS_WARNPREF "WARNING: "
761
762 /*****************************************************************************/
763
764 /* Selection character for tracing */
765 #ifndef EPRN_TRACE_CHAR
766 #define EPRN_TRACE_CHAR '_'
767 #endif /* !EPRN_TRACE_CHAR */
768
769 /* Debugging function */
770 struct gs_param_list_s;
771 extern void eprn_dump_parameter_list(struct gs_param_list_s *plist);
772
773 /* Internal data structures */
774 extern const eprn_StringAndInt eprn_colour_model_list[];
775
776 /* Internal functions */
777 extern int eprn_set_page_layout(eprn_Device *dev);
778 extern int eprn_check_colour_info(const eprn_ColourInfo *list,
779 eprn_ColourModel *model, float *hres, float *vres,
780 unsigned int *black_levels, unsigned int *non_black_levels);
781 extern int eprn_fetch_scan_line(eprn_Device *dev, eprn_OctetString *line);
782 extern void eprn_finalize(bool is_RGB, unsigned int non_black_levels,
783 int planes, eprn_OctetString *plane, eprn_Octet **ptr, int pixels);
784 extern void eprn_split_FS(eprn_OctetString *line, eprn_OctetString *next_line,
785 int max_octets, eprn_ColourModel colour_model, unsigned int black_levels,
786 unsigned int non_black_levels, eprn_OctetString bitplanes[]);
787
788 /*****************************************************************************/
789
790 #endif /* Inclusion protection */