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