1 /* Copyright (C) 2001-2019 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
13    CA 94945, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* Utilities for PCL XL generation */
18 /* Requires gdevpxat.h, gdevpxen.h, gdevpxop.h */
19 
20 #ifndef gdevpxut_INCLUDED
21 #  define gdevpxut_INCLUDED
22 
23 #include "gsdevice.h"
24 #include "scommon.h"
25 #include "gdevpxen.h"
26 #include "gdevpxat.h"
27 #include "gdevpxop.h"
28 #include "gxfixed.h"
29 
30 /* ---------------- High-level constructs ---------------- */
31 
32 /* Write the file header, including the resolution. */
33 int px_write_file_header(stream *s, const gx_device *dev, bool staple);
34 
35 /* Write the page header, including orientation. */
36 int px_write_page_header(stream *s, const gx_device *dev);
37 
38 /* Write the media selection command if needed, updating the media size. */
39 int px_write_select_media(stream *s, const gx_device *dev,
40                           pxeMediaSize_t *pms,
41                           byte *media_source,
42                           int page, bool Duplex, bool Tumble,
43                           int media_type_set, char *media_type);
44 
45 /*
46  * Write the file trailer.  Note that this takes a gp_file *, not a stream *,
47  * since it may be called after the stream is closed.
48  */
49 int px_write_file_trailer(gp_file *file);
50 
51 /* ---------------- Low-level data output ---------------- */
52 
53 /* Write a sequence of bytes. */
54 #define PX_PUT_LIT(s, bytes) px_put_bytes(s, bytes, sizeof(bytes))
55 void px_put_bytes(stream * s, const byte * data, uint count);
56 
57 /* Utilities for writing data values. */
58 /* H-P printers only support little-endian data, so that's what we emit. */
59 
60 #define DA(a) pxt_attr_ubyte, (a)
61 void px_put_a(stream * s, px_attribute_t a);
62 void px_put_ac(stream *s, px_attribute_t a, px_tag_t op);
63 
64 #define DUB(b) pxt_ubyte, (byte)(b)
65 void px_put_ub(stream * s, byte b);
66 void px_put_uba(stream *s, byte b, px_attribute_t a);
67 
68 /* signed and unsigned shorts */
69 #define DS(i) (byte)(i), (byte)(((i) >= 0 ? (i) : ((i)|0x8000)) >> 8)
70 #define US(i) (byte)(i), (byte)((i) >> 8)
71 void px_put_s(stream * s, int i);
72 
73 #define DUS(i) pxt_uint16, US(i)
74 void px_put_us(stream * s, uint i);
75 void px_put_usa(stream *s, uint i, px_attribute_t a);
76 void px_put_u(stream * s, uint i);
77 
78 #define DUSP(ix,iy) pxt_uint16_xy, US(ix), US(iy)
79 void px_put_usp(stream * s, uint ix, uint iy);
80 void px_put_usq_fixed(stream * s, fixed x0, fixed y0, fixed x1, fixed y1);
81 
82 void px_put_ss(stream * s, int i);
83 void px_put_ssp(stream * s, int ix, int iy);
84 
85 void px_put_l(stream * s, ulong l);
86 
87 void px_put_r(stream * s, double r);  /* no tag */
88 void px_put_rl(stream * s, double r);  /* pxt_real32 tag */
89 void px_put_rp(stream * s, double rx, double ry);
90 void px_put_rpa(stream * s, double rx, double ry, px_attribute_t a);
91 
92 void px_put_ubaa(stream * s, const byte * data, uint count, px_attribute_t a);
93 
94 void px_put_data_length(stream * s, uint num_bytes);
95 
96 #endif /* gdevpxut_INCLUDED */
97