1/*
2** PCL6Writer.h
3** Copyright 2005, Michael Pfeiffer, laplace@users.sourceforge.net.
4** All rights reserved.
5** Distributed under the terms of the MIT License.
6*/
7#ifndef _PCL6_WRITER_H
8#define _PCL6_WRITER_H
9
10
11#include <SupportDefs.h>
12
13
14class PCL6Driver;
15
16
17class PCL6WriterStream {
18public:
19	virtual			~PCL6WriterStream() {}
20	virtual	void	Write(const uint8* data, uint32 size) = 0;
21};
22
23
24class PCL6Writer {
25public:
26	// DO NOT change this enumerations the order is important!!!
27			enum Orientation {
28				kPortrait,
29				kLandscape,
30				kReversePortrait,
31				kReverseLandscape
32			};
33
34			enum MediaSize {
35				kLetterPaper,
36				kLegalPaper,
37				kA4Paper,
38				kExecPaper,
39				kLedgerPaper,
40				kA3Paper,
41				kCOM10Envelope,
42				kMonarchEnvelope,
43				kC5Envelope,
44				kDLEnvelope,
45				kJB4Paper,
46				kJB5Paper,
47				kB5Envelope,
48				kB5Paper,
49				kJPostcard,
50				kJDoublePostcard,
51				kA5Paper,
52				kA6Paper,
53				kJB6Paper,
54				kJIS8KPaper,
55				kJIS16KPaper,
56				kJISExecPaper
57			};
58
59			enum MediaSource {
60				kDefaultSource,
61				kAutoSelect,
62				kManualFeed,
63				kMultiPurposeTray,
64				kUpperCassette,
65				kLowerCassette,
66				kEnvelopeTray,
67				kThirdCassette
68			};
69
70			enum Compression {
71				kNoCompression,
72				kRLECompression,
73				kJPEGCompression,
74				kDeltaRowCompression
75			};
76
77			enum ColorSpace {
78				kBiLevel,
79				kGray,
80				kRGB,
81				kCMY,
82				kCIELab,
83				kCRGB,
84				kSRGB
85			};
86
87			enum ColorDepth {
88				k1Bit,
89				k4Bit,
90				k8Bit
91			};
92
93			enum ColorMapping {
94				kDirectPixel,
95				kIndexedPixel,
96				kDirectPlane
97			};
98
99			enum Transparency {
100				kOpaque,
101				kTransparent
102			};
103
104			enum DuplexPageMode {
105				kDuplexHorizontalBinding,
106				kDuplexVerticalBinding
107			};
108
109			enum MediaSide {
110				kFrontMediaSide,
111				kBackMediaSide
112			};
113
114			enum SimplexPageMode {
115				kSimplexFrontSide
116			};
117
118			enum UnitOfMeasure {
119				kInch,
120				kMillimeter,
121				kTenthsOfAMillimeter
122			};
123
124			enum ErrorReporting {
125				kNoReporting,
126				kBackChannel,
127				kErrorPage,
128				kBackChAndErrPage,
129				kNWBackChannel,
130				kNWErrorPage,
131				kNWBackChAndErrPage
132			};
133
134			enum Enable {
135				kOn,
136				kOff
137			};
138
139			enum Boolean {
140				kFalse,
141				kTrue
142			};
143
144			enum ProtocolClass {
145				kProtocolClass1_1,
146				kProtocolClass2_0,
147				kProtocolClass2_1,
148				kProtocolClass3_0,
149			};
150
151					PCL6Writer(PCL6WriterStream* stream,
152						uint32 bufferSize = 16 * 1024);
153	virtual 		~PCL6Writer();
154
155	// these methods throw TransportException if data could not
156	// be written
157			void	Flush();
158
159			void	PJLHeader(ProtocolClass protocolClass, int dpi,
160						const char* comment = NULL);
161			void	PJLFooter();
162
163			void	BeginSession(uint16 xres, uint16 yres,
164						UnitOfMeasure unitOfMeasure,
165						ErrorReporting errorReporting);
166			void	EndSession();
167
168			void	OpenDataSource();
169			void	CloseDataSource();
170
171			void	BeginPage(Orientation orientation, MediaSize mediaSize,
172						MediaSource mediaSource);
173			void	BeginPage(Orientation orientation, MediaSize mediaSize,
174						MediaSource mediaSource, DuplexPageMode duplexPageMode,
175						MediaSide mediaSide);
176			void	EndPage(uint16 copies);
177
178			void	SetPageOrigin(int16 x, int16 y);
179			void	SetColorSpace(ColorSpace colorSpace);
180			void	SetPaintTxMode(Transparency transparency);
181			void	SetSourceTxMode(Transparency transparency);
182			void	SetROP(uint8 rop);
183			void	SetCursor(int16 x, int16 y);
184
185			void	BeginImage(ColorMapping colorMapping, ColorDepth colorDepth,
186						uint16 sourceWidth, uint16 sourceHeight,
187						uint16 destWidth, uint16 destHeight);
188			void	ReadImage(Compression compression, uint16 startLine,
189						uint16 blockHeight, uint8 padBytes = 4);
190			void	EndImage();
191			void	EmbeddedDataPrefix(uint32 size);
192			void	EmbeddedDataPrefix32(uint32 size);
193
194			void	Append(uint8 value);
195			void	Append(int16 value);
196			void	Append(uint16 value);
197			void	Append(int32 value);
198			void	Append(uint32 value);
199			void	Append(float value);
200			void	Append(const uint8* data, uint32 size);
201
202			void	AppendData(uint8 value);
203			void	AppendData(int16 value);
204			void	AppendData(uint16 value);
205			void	AppendData(int32 value);
206			void	AppendData(uint32 value);
207			void	AppendData(float value);
208
209			void	AppendDataXY(uint8 x, uint8 y);
210			void	AppendDataXY(int16 x, int16 y);
211			void	AppendDataXY(uint16 x, uint16 y);
212			void	AppendDataXY(int32 x, int32 y);
213			void	AppendDataXY(uint32 x, uint32 y);
214			void	AppendDataXY(float x, float y);
215
216private:
217			enum Operator {
218				kBeginSession = 0x41,
219				kEndSession,
220				kBeginPage,
221				kEndPage,
222
223				kVendorUnique = 0x46,
224				kComment,
225				kOpenDataSource,
226				kCloseDataSource,
227				kEchoComment,
228				kQuery,
229				kDiagnostic3,
230
231				kBeginStream = 0x5b,
232				kReadStream,
233				kEndStream,
234
235				kSetColorSpace = 0x6a,
236				kSetCursor,
237
238				kSetPageOrigin = 0x75,
239				kSetPageRotation,
240				kSetPageScale,
241				kSetPaintTxMode,
242				kSetPenSource,
243				kSetPenWidth,
244				kSetROP,
245				kSetSourceTxMode,
246
247				kBeginImage = 0xb0,
248				kReadImage,
249				kEndImage,
250			};
251
252			enum DataTag {
253				kUByteData = 0xc0,
254				kUInt16Data,
255				kUInt32Data,
256				kSInt16Data,
257				kSInt32Data,
258				kReal32Data,
259
260				kString = 0xc7,
261				kUByteArray,
262				kUInt16Array,
263				kUInt32Array,
264				kSInt16Array,
265				kSInt32Array,
266				kReal32Array,
267
268				kUByteXY = 0xd0,
269				kUInt16XY,
270				kUInt32XY,
271				kSInt16XY,
272				kSInt32XY,
273				kReal32XY,
274
275				kUByteBox = 0xe0,
276				kUInt16Box,
277				kUInt32Box,
278				kSInt16Box,
279				kSInt32Box,
280				kReal32Box,
281
282				k8BitAttrId = 0xf8,
283
284				kEmbeddedData = 0xfa,
285				kEmbeddedDataByte,
286			};
287
288			enum DataType {
289				kUByte,
290				kSByte,
291				kUInt16,
292				kSInt16,
293				kReal32
294			};
295
296			enum Attribute {
297				kCMYColor = 1,
298				kPaletteDepth,
299				kColorSpace,
300
301				kRGBColor = 11,
302
303				kMediaDest = 36,
304				kMediaSize,
305				kMediaSource,
306				kMediaType,
307				kOrientation,
308				kPageAngle,
309				kPageOrigin,
310				kPageScale,
311				kROP3,
312				kTxMode,
313
314				kCustomMediaSize = 47,
315				kCustomMediaSizeUnits,
316				kPageCopies,
317				kDitherMatrixSize,
318				kDitherMatrixDepth,
319				kSimplexPageMode,
320				kDuplexPageMode,
321				kDuplexPageSide,
322
323				kPoint = 76,
324
325				kColorDepth = 98,
326				kBlockHeight,
327				kColorMapping,
328				kCompressMode,
329				kDestinationBox,
330				kDestinationSize,
331
332				kSourceHeight = 107,
333				kSourceWidth,
334				kStartLine,
335				kPadBytesMultiple,
336				kBlockByteLength,
337
338				kNumberOfScanLines = 115,
339
340				kDataOrg = 130,
341				kMeasure = 134,
342
343				kSourceType = 136,
344				kUnitsPerMeasure,
345				kQueryKey,
346				kStreamName,
347				kStreamDataLength,
348
349				kErrorReport = 143,
350				kIOReadTimeOut,
351
352				kWritingMode = 173
353			};
354
355			enum DataSource {
356				kDefaultDataSource
357			};
358
359			enum DataOrganization {
360				kBinaryHighByteFirst,
361				kBinaryLowByteFirst
362			};
363
364			void	AppendString(const char* string);
365			void	AppendOperator(Operator op);
366			void	AppendAttribute(Attribute attr);
367			void	AppendDataTag(DataTag tag);
368
369			PCL6WriterStream* fStream;
370				// the stream used for writing the generated PCL6 data
371			uint8*	fBuffer;	// the buffer
372			uint32	fSize;		// the size of the buffer
373			uint32	fIndex;		// the index of the next byte to be written
374};
375
376#endif // _PCL6_WRITER_H
377