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