* Code style changed in class GraphicsDriver and and

child classes
* Removed namespace handling for Metrowerks compiler
* Initialize all fields in constructor


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39765 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer
2010-12-08 10:22:40 +00:00
parent 9028c687fb
commit fefd3ba588
18 changed files with 871 additions and 793 deletions
+105 -71
View File
@@ -6,6 +6,7 @@
#ifndef __GRAPHICSDRIVER_H #ifndef __GRAPHICSDRIVER_H
#define __GRAPHICSDRIVER_H #define __GRAPHICSDRIVER_H
#include "JobData.h" #include "JobData.h"
#include "PrinterData.h" #include "PrinterData.h"
#include "PrintProcess.h" #include "PrintProcess.h"
@@ -13,137 +14,170 @@
#include "Transport.h" #include "Transport.h"
#include "StatusWindow.h" #include "StatusWindow.h"
class BView; class BView;
class BBitmap; class BBitmap;
class BMessage; class BMessage;
class PrinterData; class PrinterData;
class PrinterCap; class PrinterCap;
enum { enum {
kGDFRotateBandBitmap = 1 kGDFRotateBandBitmap = 1
}; };
class GraphicsDriver { class GraphicsDriver {
public: public:
GraphicsDriver(BMessage *, PrinterData *, const PrinterCap *); GraphicsDriver(BMessage* message, PrinterData* printerData,
virtual ~GraphicsDriver(); const PrinterCap *printerCap);
const JobData *getJobData(BFile *spoolFile); virtual ~GraphicsDriver();
BMessage *takeJob(BFile *spoolFile, uint32 flags = 0);
static BPoint getScale(int32 nup, BRect physicalRect, float scaling); const JobData* GetJobData(BFile* spoolFile);
static BPoint getOffset(int32 nup, int index, JobData::Orientation orientation, const BPoint *scale, BMessage* TakeJob(BFile* spoolFile, uint32 flags = 0);
BRect scaledPhysicalRect, BRect scaledPrintableRect, BRect physicalRect); static BPoint GetScale(int32 nup, BRect physicalRect, float scaling);
static BPoint GetOffset(int32 nup, int index,
JobData::Orientation orientation, const BPoint* scale,
BRect scaledPhysicalRect, BRect scaledPrintableRect,
BRect physicalRect);
protected: protected:
virtual bool startDoc(); GraphicsDriver(const GraphicsDriver &);
virtual bool startPage(int page_number);
virtual bool nextBand(BBitmap *bitmap, BPoint *offset);
virtual bool endPage(int page_number);
virtual bool endDoc(bool success);
void writeSpoolData(const void *buffer, size_t size) throw(TransportException); GraphicsDriver& operator = (const GraphicsDriver &);
void writeSpoolString(const char *buffer, ...) throw(TransportException);
void writeSpoolChar(char c) throw(TransportException);
static void convert_to_rgb24(void* src, void* dst, int width, color_space cs); virtual bool StartDocument();
static void convert_to_gray(void* src, void* dst, int width, color_space cs); virtual bool StartPage(int page_number);
virtual bool NextBand(BBitmap* bitmap, BPoint* offset);
virtual bool EndPage(int page_number);
virtual bool EndDocument(bool success);
const JobData *getJobData() const; void WriteSpoolData(const void* buffer, size_t size)
const PrinterData *getPrinterData() const; throw (TransportException);
const PrinterCap *getPrinterCap() const; void WriteSpoolString(const char* buffer, ...)
const SpoolMetaData *getSpoolMetaData() const; throw (TransportException);
int getProtocolClass() const; void WriteSpoolChar(char c)
throw (TransportException);
int getPageWidth() const; static void ConvertToRGB24(const void* src, void* dst, int width,
int getPageHeight() const; color_space cs);
int getBandWidth() const; static void ConvertToGray(const void* src, void* dst, int width,
int getBandHeight() const; color_space cs);
int getPixelDepth() const;
GraphicsDriver(const GraphicsDriver &); const JobData* GetJobData() const;
GraphicsDriver &operator = (const GraphicsDriver &); const PrinterData* GetPrinterData() const;
const PrinterCap* GetPrinterCap() const;
const SpoolMetaData* GetSpoolMetaData() const;
int GetProtocolClass() const;
int GetPageWidth() const;
int GetPageHeight() const;
int GetBandWidth() const;
int GetBandHeight() const;
int GetPixelDepth() const;
private: private:
bool setupData(BFile *file); bool _SetupData(BFile* file);
void setupBitmap(); void _SetupBitmap();
void cleanupData(); void _CleanupData();
void cleanupBitmap(); void _CleanupBitmap();
bool printPage(PageDataList *pages); bool _PrintPage(PageDataList* pages);
bool collectPages(SpoolData *spool_data, PageDataList *pages); bool _CollectPages(SpoolData* spoolData, PageDataList* pages);
bool skipPages(SpoolData *spool_data); bool _SkipPages(SpoolData* spoolData);
bool printDocument(SpoolData *spool_data); bool _PrintDocument(SpoolData* spoolData);
bool printJob(BFile *file); bool PrintJob(BFile* file);
static void rgb32_to_rgb24(void* src, void* dst, int width); static void _ConvertRGB32ToRGB24(const void* src, void* dst, int width);
static void cmap8_to_rgb24(void* src, void* dst, int width); static void _ConvertCMAP8ToRGB24(const void* src, void* dst, int width);
static uint8 gray(uint8 r, uint8 g, uint8 b); static uint8 _ConvertToGray(uint8 r, uint8 g, uint8 b);
static void rgb32_to_gray(void* src, void* dst, int width); static void _ConvertRGB32ToGray(const void* src, void* dst, int width);
static void cmap8_to_gray(void* src, void* dst, int width); static void _ConvertCMAP8ToGray(const void* src, void* dst, int width);
uint32 fFlags; uint32 fFlags;
BMessage *fMsg; BMessage* fMessage;
BView *fView; BView* fView;
BBitmap *fBitmap; BBitmap* fBitmap;
Transport *fTransport; Transport* fTransport;
JobData *fOrgJobData; JobData* fOrgJobData;
JobData *fRealJobData; JobData* fRealJobData;
PrinterData *fPrinterData; PrinterData* fPrinterData;
const PrinterCap *fPrinterCap; const PrinterCap* fPrinterCap;
SpoolMetaData *fSpoolMetaData; SpoolMetaData* fSpoolMetaData;
int fPageWidth; int fPageWidth;
int fPageHeight; int fPageHeight;
int fBandWidth; int fBandWidth;
int fBandHeight; int fBandHeight;
int fPixelDepth; int fPixelDepth;
int fBandCount; int fBandCount;
int fInternalCopies; int fInternalCopies;
uint32 fPageCount; uint32 fPageCount;
StatusWindow *fStatusWindow;
StatusWindow* fStatusWindow;
}; };
inline const JobData *GraphicsDriver::getJobData() const
inline const JobData*
GraphicsDriver::GetJobData() const
{ {
return fRealJobData; return fRealJobData;
} }
inline const PrinterData *GraphicsDriver::getPrinterData() const
inline const PrinterData*
GraphicsDriver::GetPrinterData() const
{ {
return fPrinterData; return fPrinterData;
} }
inline const PrinterCap *GraphicsDriver::getPrinterCap() const
inline const PrinterCap*
GraphicsDriver::GetPrinterCap() const
{ {
return fPrinterCap; return fPrinterCap;
} }
inline const SpoolMetaData *GraphicsDriver::getSpoolMetaData() const
inline const SpoolMetaData*
GraphicsDriver::GetSpoolMetaData() const
{ {
return fSpoolMetaData; return fSpoolMetaData;
} }
inline int GraphicsDriver::getProtocolClass() const
inline int
GraphicsDriver::GetProtocolClass() const
{ {
return fPrinterData->getProtocolClass(); return fPrinterData->getProtocolClass();
} }
inline int GraphicsDriver::getPageWidth() const
inline int
GraphicsDriver::GetPageWidth() const
{ {
return fPageWidth; return fPageWidth;
} }
inline int GraphicsDriver::getPageHeight() const
inline int
GraphicsDriver::GetPageHeight() const
{ {
return fPageHeight; return fPageHeight;
} }
inline int GraphicsDriver::getBandWidth() const
inline int
GraphicsDriver::GetBandWidth() const
{ {
return fBandWidth; return fBandWidth;
} }
inline int GraphicsDriver::getBandHeight() const
inline int
GraphicsDriver::GetBandHeight() const
{ {
return fBandHeight; return fBandHeight;
} }
#endif /* __GRAPHICSDRIVER_H */ #endif /* __GRAPHICSDRIVER_H */
@@ -22,38 +22,31 @@
#include "ValidRect.h" #include "ValidRect.h"
#if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE)) LIPS3Driver::LIPS3Driver(BMessage* message, PrinterData* printerData,
using namespace std; const PrinterCap* printerCap)
#else
#define std
#endif
LIPS3Driver::LIPS3Driver(BMessage *msg, PrinterData *printer_data,
const PrinterCap *printer_cap)
: :
GraphicsDriver(msg, printer_data, printer_cap) GraphicsDriver(message, printerData, printerCap),
fHalftone(NULL)
{ {
fHalftone = NULL;
} }
bool bool
LIPS3Driver::startDoc() LIPS3Driver::StartDocument()
{ {
try { try {
beginTextMode(); _BeginTextMode();
jobStart(); _JobStart();
softReset(); _SoftReset();
sizeUnitMode(); _SizeUnitMode();
selectSizeUnit(); _SelectSizeUnit();
selectPageFormat(); _SelectPageFormat();
paperFeedMode(); _PaperFeedMode();
disableAutoFF(); _DisableAutoFF();
setNumberOfCopies(); _SetNumberOfCopies();
fHalftone = new Halftone(getJobData()->getSurfaceType(), fHalftone = new Halftone(GetJobData()->getSurfaceType(),
getJobData()->getGamma(), getJobData()->getInkDensity(), GetJobData()->getGamma(), GetJobData()->getInkDensity(),
getJobData()->getDitherType()); GetJobData()->getDitherType());
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -63,12 +56,12 @@ LIPS3Driver::startDoc()
bool bool
LIPS3Driver::startPage(int) LIPS3Driver::StartPage(int)
{ {
try { try {
fCurrentX = 0; fCurrentX = 0;
fCurrentY = 0; fCurrentY = 0;
memorizedPosition(); _MemorizedPosition();
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -78,10 +71,10 @@ LIPS3Driver::startPage(int)
bool bool
LIPS3Driver::endPage(int) LIPS3Driver::EndPage(int)
{ {
try { try {
formFeed(); _FormFeed();
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -91,13 +84,13 @@ LIPS3Driver::endPage(int)
bool bool
LIPS3Driver::endDoc(bool) LIPS3Driver::EndDocument(bool)
{ {
try { try {
if (fHalftone) { if (fHalftone)
delete fHalftone; delete fHalftone;
}
jobEnd(); _JobEnd();
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -107,7 +100,7 @@ LIPS3Driver::endDoc(bool)
bool bool
LIPS3Driver::nextBand(BBitmap* bitmap, BPoint* offset) LIPS3Driver::NextBand(BBitmap* bitmap, BPoint* offset)
{ {
DBGMSG(("> nextBand\n")); DBGMSG(("> nextBand\n"));
@@ -125,7 +118,7 @@ LIPS3Driver::nextBand(BBitmap* bitmap, BPoint* offset)
int x = (int)offset->x; int x = (int)offset->x;
int y = (int)offset->y; int y = (int)offset->y;
int page_height = getPageHeight(); int page_height = GetPageHeight();
if (y + height > page_height) if (y + height > page_height)
height = page_height - y; height = page_height - y;
@@ -165,8 +158,8 @@ LIPS3Driver::nextBand(BBitmap* bitmap, BPoint* offset)
+ rc.top * delta + rc.top * delta
+ (rc.left * fHalftone->getPixelDepth()) / 8; + (rc.left * fHalftone->getPixelDepth()) / 8;
int compression_method; int compressionMethod;
int compressed_size; int compressedSize;
const uchar* buffer; const uchar* buffer;
uchar* in_buffer = new uchar[in_size]; uchar* in_buffer = new uchar[in_size];
@@ -179,7 +172,7 @@ LIPS3Driver::nextBand(BBitmap* bitmap, BPoint* offset)
DBGMSG(("move\n")); DBGMSG(("move\n"));
move(x, y); _Move(x, y);
for (int i = rc.top; i <= rc.bottom; i++) { for (int i = rc.top; i <= rc.bottom; i++) {
fHalftone->dither(ptr2, ptr, x, y, width); fHalftone->dither(ptr2, ptr, x, y, width);
@@ -188,33 +181,33 @@ LIPS3Driver::nextBand(BBitmap* bitmap, BPoint* offset)
y++; y++;
} }
compressed_size = compress3(out_buffer, in_buffer, in_size); compressedSize = compress3(out_buffer, in_buffer, in_size);
if (compressed_size < in_size) { if (compressedSize < in_size) {
compression_method = 9; compressionMethod = 9;
// compress3 // compress3
buffer = out_buffer; buffer = out_buffer;
} else if (compressed_size > out_size) { } else if (compressedSize > out_size) {
BAlert* alert = new BAlert("memory overrun!!!", "warning", BAlert* alert = new BAlert("memory overrun!!!", "warning",
"OK"); "OK");
alert->Go(); alert->Go();
return false; return false;
} else { } else {
compression_method = 0; compressionMethod = 0;
buffer = in_buffer; buffer = in_buffer;
compressed_size = in_size; compressedSize = in_size;
} }
DBGMSG(("compressed_size = %d\n", compressed_size)); DBGMSG(("compressedSize = %d\n", compressedSize));
DBGMSG(("widthByte = %d\n", widthByte)); DBGMSG(("widthByte = %d\n", widthByte));
DBGMSG(("height = %d\n", height)); DBGMSG(("height = %d\n", height));
DBGMSG(("compression_method = %d\n", compression_method)); DBGMSG(("compression_method = %d\n", compressionMethod));
rasterGraphics( _RasterGraphics(
compressed_size, // size, compressedSize, // size,
widthByte, // widthByte widthByte, // widthByte
height, // height, height, // height,
compression_method, compressionMethod,
buffer); buffer);
} else } else
@@ -238,48 +231,48 @@ LIPS3Driver::nextBand(BBitmap* bitmap, BPoint* offset)
void void
LIPS3Driver::beginTextMode() LIPS3Driver::_BeginTextMode()
{ {
writeSpoolString("\033%%@"); WriteSpoolString("\033%%@");
} }
void void
LIPS3Driver::jobStart() LIPS3Driver::_JobStart()
{ {
writeSpoolString("\033P31;300;1J\033\\"); WriteSpoolString("\033P31;300;1J\033\\");
} }
void void
LIPS3Driver::softReset() LIPS3Driver::_SoftReset()
{ {
writeSpoolString("\033<"); WriteSpoolString("\033<");
} }
void void
LIPS3Driver::sizeUnitMode() LIPS3Driver::_SizeUnitMode()
{ {
writeSpoolString("\033[11h"); WriteSpoolString("\033[11h");
} }
void void
LIPS3Driver::selectSizeUnit() LIPS3Driver::_SelectSizeUnit()
{ {
writeSpoolString("\033[7 I"); WriteSpoolString("\033[7 I");
} }
void void
LIPS3Driver::selectPageFormat() LIPS3Driver::_SelectPageFormat()
{ {
int i; int i;
int width = 0; int width = 0;
int height = 0; int height = 0;
switch (getJobData()->getPaper()) { switch (GetJobData()->getPaper()) {
case JobData::kA3: case JobData::kA3:
i = 12; i = 12;
break; break;
@@ -326,23 +319,23 @@ LIPS3Driver::selectPageFormat()
// //
default: default:
i = 80; i = 80;
width = getJobData()->getPaperRect().IntegerWidth(); width = GetJobData()->getPaperRect().IntegerWidth();
height = getJobData()->getPaperRect().IntegerHeight(); height = GetJobData()->getPaperRect().IntegerHeight();
break; break;
} }
if (JobData::kLandscape == getJobData()->getOrientation()) if (JobData::kLandscape == GetJobData()->getOrientation())
i++; i++;
if (i < 80) if (i < 80)
writeSpoolString("\033[%d;;p", i); WriteSpoolString("\033[%d;;p", i);
else else
writeSpoolString("\033[%d;%d;%dp", i, height, width); WriteSpoolString("\033[%d;%d;%dp", i, height, width);
} }
void void
LIPS3Driver::paperFeedMode() LIPS3Driver::_PaperFeedMode()
{ {
// 0 auto // 0 auto
// -------------- // --------------
@@ -361,7 +354,7 @@ LIPS3Driver::paperFeedMode()
int i; int i;
switch (getJobData()->getPaperSource()) { switch (GetJobData()->getPaperSource()) {
case JobData::kManual: case JobData::kManual:
i = 1; i = 1;
break; break;
@@ -377,93 +370,93 @@ LIPS3Driver::paperFeedMode()
break; break;
} }
writeSpoolString("\033[%dq", i); WriteSpoolString("\033[%dq", i);
} }
void void
LIPS3Driver::disableAutoFF() LIPS3Driver::_DisableAutoFF()
{ {
writeSpoolString("\033[?2h"); WriteSpoolString("\033[?2h");
} }
void void
LIPS3Driver::setNumberOfCopies() LIPS3Driver::_SetNumberOfCopies()
{ {
writeSpoolString("\033[%ldv", getJobData()->getCopies()); WriteSpoolString("\033[%ldv", GetJobData()->getCopies());
} }
void void
LIPS3Driver::memorizedPosition() LIPS3Driver::_MemorizedPosition()
{ {
writeSpoolString("\033[0;1;0x"); WriteSpoolString("\033[0;1;0x");
} }
void void
LIPS3Driver::moveAbsoluteHorizontal(int x) LIPS3Driver::_MoveAbsoluteHorizontal(int x)
{ {
writeSpoolString("\033[%d`", x); WriteSpoolString("\033[%d`", x);
} }
void void
LIPS3Driver::carriageReturn() LIPS3Driver::_CarriageReturn()
{ {
writeSpoolChar('\x0d'); WriteSpoolChar('\x0d');
} }
void void
LIPS3Driver::moveDown(int dy) LIPS3Driver::_MoveDown(int dy)
{ {
writeSpoolString("\033[%de", dy); WriteSpoolString("\033[%de", dy);
} }
void void
LIPS3Driver::rasterGraphics( int compression_size, int widthbyte, int height, LIPS3Driver::_RasterGraphics( int compressionSize, int widthbyte, int height,
int compression_method, const uchar *buffer) int compressionMethod, const uchar* buffer)
{ {
// 0 RAW // 0 RAW
// 9 compress-3 // 9 compress-3
writeSpoolString("\033[%d;%d;%d;%d;%d.r", compression_size, widthbyte, WriteSpoolString("\033[%d;%d;%d;%d;%d.r", compressionSize, widthbyte,
getJobData()->getXres(), compression_method, height); GetJobData()->getXres(), compressionMethod, height);
writeSpoolData(buffer, compression_size); WriteSpoolData(buffer, compressionSize);
} }
void void
LIPS3Driver::formFeed() LIPS3Driver::_FormFeed()
{ {
writeSpoolChar('\014'); WriteSpoolChar('\014');
} }
void void
LIPS3Driver::jobEnd() LIPS3Driver::_JobEnd()
{ {
writeSpoolString("\033P0J\033\\"); WriteSpoolString("\033P0J\033\\");
} }
void void
LIPS3Driver::move(int x, int y) LIPS3Driver::_Move(int x, int y)
{ {
if (fCurrentX != x) { if (fCurrentX != x) {
if (x) if (x)
moveAbsoluteHorizontal(x); _MoveAbsoluteHorizontal(x);
else else
carriageReturn(); _CarriageReturn();
fCurrentX = x; fCurrentX = x;
} }
if (fCurrentY != y) { if (fCurrentY != y) {
int dy = y - fCurrentY; int dy = y - fCurrentY;
moveDown(dy); _MoveDown(dy);
fCurrentY = y; fCurrentY = y;
} }
} }
@@ -18,31 +18,31 @@ public:
const PrinterCap* printer_cap); const PrinterCap* printer_cap);
protected: protected:
virtual bool startDoc(); virtual bool StartDocument();
virtual bool startPage(int page); virtual bool StartPage(int page);
virtual bool nextBand(BBitmap *bitmap, BPoint *offset); virtual bool NextBand(BBitmap *bitmap, BPoint *offset);
virtual bool endPage(int page); virtual bool EndPage(int page);
virtual bool endDoc(bool success); virtual bool EndDocument(bool success);
private: private:
void move(int x, int y); void _Move(int x, int y);
void beginTextMode(); void _BeginTextMode();
void jobStart(); void _JobStart();
void softReset(); void _SoftReset();
void sizeUnitMode(); void _SizeUnitMode();
void selectSizeUnit(); void _SelectSizeUnit();
void paperFeedMode(); void _PaperFeedMode();
void selectPageFormat(); void _SelectPageFormat();
void disableAutoFF(); void _DisableAutoFF();
void setNumberOfCopies(); void _SetNumberOfCopies();
void memorizedPosition(); void _MemorizedPosition();
void moveAbsoluteHorizontal(int x); void _MoveAbsoluteHorizontal(int x);
void carriageReturn(); void _CarriageReturn();
void moveDown(int dy); void _MoveDown(int dy);
void rasterGraphics(int size, int widthbyte, int height, void _RasterGraphics(int size, int widthbyte, int height,
int compression_method, const uchar* buffer); int compression_method, const uchar* buffer);
void formFeed(); void _FormFeed();
void jobEnd(); void _JobEnd();
int fCurrentX; int fCurrentX;
int fCurrentY; int fCurrentY;
@@ -20,41 +20,35 @@
#include "PrinterData.h" #include "PrinterData.h"
#include "ValidRect.h" #include "ValidRect.h"
#if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE))
using namespace std;
#else
#define std
#endif
LIPS4Driver::LIPS4Driver(BMessage* message, PrinterData* printerData,
LIPS4Driver::LIPS4Driver(BMessage* msg, PrinterData* printer_data, const PrinterCap* printerCap)
const PrinterCap *printer_cap)
: :
GraphicsDriver(msg, printer_data, printer_cap) GraphicsDriver(message, printerData, printerCap),
fHalftone(NULL)
{ {
fHalftone = NULL;
} }
bool bool
LIPS4Driver::startDoc() LIPS4Driver::StartDocument()
{ {
try { try {
beginTextMode(); _BeginTextMode();
jobStart(); _JobStart();
colorModeDeclaration(); _ColorModeDeclaration();
softReset(); _SoftReset();
sizeUnitMode(); _SizeUnitMode();
selectSizeUnit(); _SelectSizeUnit();
paperFeedMode(); _PaperFeedMode();
selectPageFormat(); _SelectPageFormat();
disableAutoFF(); _DisableAutoFF();
setNumberOfCopies(); _SetNumberOfCopies();
sidePrintingControl(); _SidePrintingControl();
setBindingMargin(); _SetBindingMargin();
fHalftone = new Halftone(getJobData()->getSurfaceType(), fHalftone = new Halftone(GetJobData()->getSurfaceType(),
getJobData()->getGamma(), getJobData()->getInkDensity(), GetJobData()->getGamma(), GetJobData()->getInkDensity(),
getJobData()->getDitherType()); GetJobData()->getDitherType());
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -64,12 +58,12 @@ LIPS4Driver::startDoc()
bool bool
LIPS4Driver::startPage(int) LIPS4Driver::StartPage(int)
{ {
try { try {
fCurrentX = 0; fCurrentX = 0;
fCurrentY = 0; fCurrentY = 0;
memorizedPosition(); _MemorizedPosition();
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -79,10 +73,10 @@ LIPS4Driver::startPage(int)
bool bool
LIPS4Driver::endPage(int) LIPS4Driver::EndPage(int)
{ {
try { try {
formFeed(); _FormFeed();
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -92,13 +86,13 @@ LIPS4Driver::endPage(int)
bool bool
LIPS4Driver::endDoc(bool) LIPS4Driver::EndDocument(bool)
{ {
try { try {
if (fHalftone) if (fHalftone)
delete fHalftone; delete fHalftone;
jobEnd(); _JobEnd();
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -108,7 +102,7 @@ LIPS4Driver::endDoc(bool)
bool bool
LIPS4Driver::nextBand(BBitmap* bitmap, BPoint* offset) LIPS4Driver::NextBand(BBitmap* bitmap, BPoint* offset)
{ {
DBGMSG(("> nextBand\n")); DBGMSG(("> nextBand\n"));
@@ -117,7 +111,7 @@ LIPS4Driver::nextBand(BBitmap* bitmap, BPoint* offset)
if (bitmap == NULL) { if (bitmap == NULL) {
uchar dummy[1]; uchar dummy[1];
dummy[0] = '\0'; dummy[0] = '\0';
rasterGraphics(1, 1, 1, 0, dummy); _RasterGraphics(1, 1, 1, 0, dummy);
DBGMSG(("< next_band\n")); DBGMSG(("< next_band\n"));
return true; return true;
} }
@@ -135,7 +129,7 @@ LIPS4Driver::nextBand(BBitmap* bitmap, BPoint* offset)
int x = (int)offset->x; int x = (int)offset->x;
int y = (int)offset->y; int y = (int)offset->y;
int page_height = getPageHeight(); int page_height = GetPageHeight();
if (y + height > page_height) if (y + height > page_height)
height = page_height - y; height = page_height - y;
@@ -188,7 +182,7 @@ LIPS4Driver::nextBand(BBitmap* bitmap, BPoint* offset)
DBGMSG(("move\n")); DBGMSG(("move\n"));
move(x, y); _Move(x, y);
for (int i = rc.top; i <= rc.bottom; i++) { for (int i = rc.top; i <= rc.bottom; i++) {
fHalftone->dither(ptr2, ptr, x, y, width); fHalftone->dither(ptr2, ptr, x, y, width);
@@ -219,7 +213,7 @@ LIPS4Driver::nextBand(BBitmap* bitmap, BPoint* offset)
DBGMSG(("height = %d\n", height)); DBGMSG(("height = %d\n", height));
DBGMSG(("compression_method = %d\n", compression_method)); DBGMSG(("compression_method = %d\n", compression_method));
rasterGraphics( _RasterGraphics(
compressed_size, // size, compressed_size, // size,
widthByte, // widthByte widthByte, // widthByte
height, // height, height, // height,
@@ -247,52 +241,52 @@ LIPS4Driver::nextBand(BBitmap* bitmap, BPoint* offset)
void void
LIPS4Driver::beginTextMode() LIPS4Driver::_BeginTextMode()
{ {
writeSpoolString("\033%%@"); WriteSpoolString("\033%%@");
} }
void void
LIPS4Driver::jobStart() LIPS4Driver::_JobStart()
{ {
writeSpoolString("\033P41;%d;1J\033\\", getJobData()->getXres()); WriteSpoolString("\033P41;%d;1J\033\\", GetJobData()->getXres());
} }
void void
LIPS4Driver::colorModeDeclaration() LIPS4Driver::_ColorModeDeclaration()
{ {
// if (color) // if (color)
// writeSpoolString("\033[1\"p"); // WriteSpoolString("\033[1\"p");
// else // else
writeSpoolString("\033[0\"p"); WriteSpoolString("\033[0\"p");
} }
void void
LIPS4Driver::softReset() LIPS4Driver::_SoftReset()
{ {
writeSpoolString("\033<"); WriteSpoolString("\033<");
} }
void void
LIPS4Driver::sizeUnitMode() LIPS4Driver::_SizeUnitMode()
{ {
writeSpoolString("\033[11h"); WriteSpoolString("\033[11h");
} }
void void
LIPS4Driver::selectSizeUnit() LIPS4Driver::_SelectSizeUnit()
{ {
writeSpoolString("\033[?7;%d I", getJobData()->getXres()); WriteSpoolString("\033[?7;%d I", GetJobData()->getXres());
} }
void void
LIPS4Driver::paperFeedMode() LIPS4Driver::_PaperFeedMode()
{ {
// 0 auto // 0 auto
// -------------- // --------------
@@ -311,7 +305,7 @@ LIPS4Driver::paperFeedMode()
int i; int i;
switch (getJobData()->getPaperSource()) { switch (GetJobData()->getPaperSource()) {
case JobData::kManual: case JobData::kManual:
i = 10; i = 10;
break; break;
@@ -330,16 +324,16 @@ LIPS4Driver::paperFeedMode()
break; break;
} }
writeSpoolString("\033[%dq", i); WriteSpoolString("\033[%dq", i);
} }
void void
LIPS4Driver::selectPageFormat() LIPS4Driver::_SelectPageFormat()
{ {
int i; int i;
switch (getJobData()->getPaper()) { switch (GetJobData()->getPaper()) {
case JobData::kA3: case JobData::kA3:
i = 12; i = 12;
break; break;
@@ -389,41 +383,41 @@ LIPS4Driver::selectPageFormat()
break; break;
} }
if (JobData::kLandscape == getJobData()->getOrientation()) if (JobData::kLandscape == GetJobData()->getOrientation())
i++; i++;
writeSpoolString("\033[%d;;p", i); WriteSpoolString("\033[%d;;p", i);
} }
void void
LIPS4Driver::disableAutoFF() LIPS4Driver::_DisableAutoFF()
{ {
writeSpoolString("\033[?2h"); WriteSpoolString("\033[?2h");
} }
void void
LIPS4Driver::setNumberOfCopies() LIPS4Driver::_SetNumberOfCopies()
{ {
writeSpoolString("\033[%ldv", getJobData()->getCopies()); WriteSpoolString("\033[%ldv", GetJobData()->getCopies());
} }
void void
LIPS4Driver::sidePrintingControl() LIPS4Driver::_SidePrintingControl()
{ {
if (getJobData()->getPrintStyle() == JobData::kSimplex) if (GetJobData()->getPrintStyle() == JobData::kSimplex)
writeSpoolString("\033[0#x"); WriteSpoolString("\033[0#x");
else else
writeSpoolString("\033[2;0#x"); WriteSpoolString("\033[2;0#x");
} }
void void
LIPS4Driver::setBindingMargin() LIPS4Driver::_SetBindingMargin()
{ {
if (getJobData()->getPrintStyle() == JobData::kDuplex) { if (GetJobData()->getPrintStyle() == JobData::kDuplex) {
int i; int i;
// switch (job_data()->binding_location()) { // switch (job_data()->binding_location()) {
// case kLongEdgeLeft: // case kLongEdgeLeft:
@@ -439,87 +433,87 @@ LIPS4Driver::setBindingMargin()
// i = 3; // i = 3;
// break; // break;
// } // }
writeSpoolString("\033[%d;0#w", i); WriteSpoolString("\033[%d;0#w", i);
} }
} }
void void
LIPS4Driver::memorizedPosition() LIPS4Driver::_MemorizedPosition()
{ {
writeSpoolString("\033[0;1;0x"); WriteSpoolString("\033[0;1;0x");
} }
void void
LIPS4Driver::moveAbsoluteHorizontal(int x) LIPS4Driver::_MoveAbsoluteHorizontal(int x)
{ {
writeSpoolString("\033[%ld`", x); WriteSpoolString("\033[%ld`", x);
} }
void void
LIPS4Driver::carriageReturn() LIPS4Driver::_CarriageReturn()
{ {
writeSpoolChar('\x0d'); WriteSpoolChar('\x0d');
} }
void void
LIPS4Driver::moveDown(int dy) LIPS4Driver::_MoveDown(int dy)
{ {
writeSpoolString("\033[%lde", dy); WriteSpoolString("\033[%lde", dy);
} }
void void
LIPS4Driver::rasterGraphics(int compression_size, int widthbyte, int height, LIPS4Driver::_RasterGraphics(int compression_size, int widthbyte, int height,
int compression_method, const uchar* buffer) int compression_method, const uchar* buffer)
{ {
// 0 RAW // 0 RAW
// 10 RLE // 10 RLE
// 11 packbits // 11 packbits
writeSpoolString( WriteSpoolString(
"\033[%ld;%ld;%d;%ld;%ld.r", "\033[%ld;%ld;%d;%ld;%ld.r",
compression_size, compression_size,
widthbyte, widthbyte,
getJobData()->getXres(), GetJobData()->getXres(),
compression_method, compression_method,
height); height);
writeSpoolData(buffer, compression_size); WriteSpoolData(buffer, compression_size);
} }
void void
LIPS4Driver::formFeed() LIPS4Driver::_FormFeed()
{ {
writeSpoolChar('\014'); WriteSpoolChar('\014');
} }
void void
LIPS4Driver::jobEnd() LIPS4Driver::_JobEnd()
{ {
writeSpoolString("\033P0J\033\\"); WriteSpoolString("\033P0J\033\\");
} }
void void
LIPS4Driver::move(int x, int y) LIPS4Driver::_Move(int x, int y)
{ {
if (fCurrentX != x) { if (fCurrentX != x) {
if (x) { if (x) {
moveAbsoluteHorizontal(x); _MoveAbsoluteHorizontal(x);
} else { } else {
carriageReturn(); _CarriageReturn();
} }
fCurrentX = x; fCurrentX = x;
} }
if (fCurrentY != y) { if (fCurrentY != y) {
int dy = y - fCurrentY; int dy = y - fCurrentY;
moveDown(dy); _MoveDown(dy);
fCurrentY = y; fCurrentY = y;
} }
} }
@@ -14,37 +14,39 @@ class Halftone;
class LIPS4Driver : public GraphicsDriver { class LIPS4Driver : public GraphicsDriver {
public: public:
LIPS4Driver(BMessage *msg, PrinterData *printer_data, const PrinterCap *cap); LIPS4Driver(BMessage* message,
PrinterData* printerData,
const PrinterCap* printerCap);
protected: protected:
virtual bool startDoc(); virtual bool StartDocument();
virtual bool startPage(int page); virtual bool StartPage(int page);
virtual bool nextBand(BBitmap *bitmap, BPoint *offset); virtual bool NextBand(BBitmap* bitmap, BPoint* offset);
virtual bool endPage(int page); virtual bool EndPage(int page);
virtual bool endDoc(bool success); virtual bool EndDocument(bool success);
private: private:
void move(int x, int y); void _Move(int x, int y);
void beginTextMode(); void _BeginTextMode();
void jobStart(); void _JobStart();
void colorModeDeclaration(); void _ColorModeDeclaration();
void softReset(); void _SoftReset();
void sizeUnitMode(); void _SizeUnitMode();
void selectSizeUnit(); void _SelectSizeUnit();
void paperFeedMode(); void _PaperFeedMode();
void selectPageFormat(); void _SelectPageFormat();
void disableAutoFF(); void _DisableAutoFF();
void setNumberOfCopies(); void _SetNumberOfCopies();
void sidePrintingControl(); void _SidePrintingControl();
void setBindingMargin(); void _SetBindingMargin();
void memorizedPosition(); void _MemorizedPosition();
void moveAbsoluteHorizontal(int x); void _MoveAbsoluteHorizontal(int x);
void carriageReturn(); void _CarriageReturn();
void moveDown(int dy); void _MoveDown(int dy);
void rasterGraphics(int size, int widthbyte, int height, void _RasterGraphics(int size, int widthbyte, int height,
int compression_method, const uchar* buffer); int compressionMethod, const uchar* buffer);
void formFeed(); void _FormFeed();
void jobEnd(); void _JobEnd();
int fCurrentX; int fCurrentX;
int fCurrentY; int fCurrentY;
@@ -28,44 +28,44 @@
using namespace std; using namespace std;
GPDriver::GPDriver(BMessage* msg, PrinterData* printer_data, GPDriver::GPDriver(BMessage* message, PrinterData* printerData,
const PrinterCap* printer_cap) const PrinterCap* printerCap)
: :
GraphicsDriver(msg, printer_data, printer_cap) GraphicsDriver(message, printerData, printerCap)
{ {
} }
void void
GPDriver::Write(const void *buffer, size_t size) GPDriver::Write(const void* buffer, size_t size)
throw(TransportException) throw (TransportException)
{ {
writeSpoolData(buffer, size); WriteSpoolData(buffer, size);
} }
bool bool
GPDriver::startDoc() GPDriver::StartDocument()
{ {
try { try {
const GPData* data = dynamic_cast<const GPData*>(getPrinterData()); const GPData* data = dynamic_cast<const GPData*>(GetPrinterData());
ASSERT(data != NULL); ASSERT(data != NULL);
fConfiguration.fDriver = data->fGutenprintDriverName; fConfiguration.fDriver = data->fGutenprintDriverName;
SetParameter(fConfiguration.fPageSize, PrinterCap::kPaper, SetParameter(fConfiguration.fPageSize, PrinterCap::kPaper,
getJobData()->getPaper()); GetJobData()->getPaper());
SetParameter(fConfiguration.fResolution, PrinterCap::kResolution, SetParameter(fConfiguration.fResolution, PrinterCap::kResolution,
getJobData()->getResolutionID()); GetJobData()->getResolutionID());
fConfiguration.fXDPI = getJobData()->getXres(); fConfiguration.fXDPI = GetJobData()->getXres();
fConfiguration.fYDPI = getJobData()->getYres(); fConfiguration.fYDPI = GetJobData()->getYres();
SetParameter(fConfiguration.fInputSlot, PrinterCap::kPaperSource, SetParameter(fConfiguration.fInputSlot, PrinterCap::kPaperSource,
getJobData()->getPaperSource()); GetJobData()->getPaperSource());
SetParameter(fConfiguration.fPrintingMode, PrinterCap::kColor, SetParameter(fConfiguration.fPrintingMode, PrinterCap::kColor,
getJobData()->getColor()); GetJobData()->getColor());
if (getPrinterCap()->isSupport(PrinterCap::kDriverSpecificCapabilities)) if (GetPrinterCap()->isSupport(PrinterCap::kDriverSpecificCapabilities))
SetDriverSpecificSettings(); SetDriverSpecificSettings();
fprintf(stderr, "Driver: %s\n", fConfiguration.fDriver.String()); fprintf(stderr, "Driver: %s\n", fConfiguration.fDriver.String());
@@ -87,7 +87,7 @@ GPDriver::SetParameter(BString& parameter, PrinterCap::CapID category,
int value) int value)
{ {
const EnumCap* capability; const EnumCap* capability;
capability = getPrinterCap()->findCap(category, value); capability = GetPrinterCap()->findCap(category, value);
if (capability != NULL && capability->fKey != "") if (capability != NULL && capability->fKey != "")
parameter = capability->Key(); parameter = capability->Key();
} }
@@ -97,8 +97,8 @@ void
GPDriver::SetDriverSpecificSettings() GPDriver::SetDriverSpecificSettings()
{ {
PrinterCap::CapID category = PrinterCap::kDriverSpecificCapabilities; PrinterCap::CapID category = PrinterCap::kDriverSpecificCapabilities;
int count = getPrinterCap()->countCap(category); int count = GetPrinterCap()->countCap(category);
const BaseCap** capabilities = getPrinterCap()->enumCap(category); const BaseCap** capabilities = GetPrinterCap()->enumCap(category);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
const DriverSpecificCap* capability = const DriverSpecificCap* capability =
dynamic_cast<const DriverSpecificCap*>(capabilities[i]); dynamic_cast<const DriverSpecificCap*>(capabilities[i]);
@@ -134,16 +134,16 @@ GPDriver::SetDriverSpecificSettings()
void void
GPDriver::AddDriverSpecificSetting(PrinterCap::CapID category, const char* key) { GPDriver::AddDriverSpecificSetting(PrinterCap::CapID category, const char* key) {
const EnumCap* capability = NULL; const EnumCap* capability = NULL;
if (getJobData()->Settings().HasString(key)) if (GetJobData()->Settings().HasString(key))
{ {
const string& value = getJobData()->Settings().GetString(key); const string& value = GetJobData()->Settings().GetString(key);
capability = getPrinterCap()->findCapWithKey(category, value.c_str()); capability = GetPrinterCap()->findCapWithKey(category, value.c_str());
} }
if (capability == NULL) { if (capability == NULL) {
// job data should contain a value; // job data should contain a value;
// try to use the default value anyway // try to use the default value anyway
capability = getPrinterCap()->getDefaultCap(category); capability = GetPrinterCap()->getDefaultCap(category);
} }
if (capability == NULL) { if (capability == NULL) {
@@ -158,41 +158,41 @@ GPDriver::AddDriverSpecificSetting(PrinterCap::CapID category, const char* key)
void void
GPDriver::AddDriverSpecificBooleanSetting(PrinterCap::CapID category, GPDriver::AddDriverSpecificBooleanSetting(PrinterCap::CapID category,
const char* key) { const char* key) {
if (getJobData()->Settings().HasBoolean(key)) if (GetJobData()->Settings().HasBoolean(key))
fConfiguration.fBooleanSettings[key] = fConfiguration.fBooleanSettings[key] =
getJobData()->Settings().GetBoolean(key); GetJobData()->Settings().GetBoolean(key);
} }
void void
GPDriver::AddDriverSpecificIntSetting(PrinterCap::CapID category, GPDriver::AddDriverSpecificIntSetting(PrinterCap::CapID category,
const char* key) { const char* key) {
if (getJobData()->Settings().HasInt(key)) if (GetJobData()->Settings().HasInt(key))
fConfiguration.fIntSettings[key] = fConfiguration.fIntSettings[key] =
getJobData()->Settings().GetInt(key); GetJobData()->Settings().GetInt(key);
} }
void void
GPDriver::AddDriverSpecificDimensionSetting(PrinterCap::CapID category, GPDriver::AddDriverSpecificDimensionSetting(PrinterCap::CapID category,
const char* key) { const char* key) {
if (getJobData()->Settings().HasInt(key)) if (GetJobData()->Settings().HasInt(key))
fConfiguration.fDimensionSettings[key] = fConfiguration.fDimensionSettings[key] =
getJobData()->Settings().GetInt(key); GetJobData()->Settings().GetInt(key);
} }
void void
GPDriver::AddDriverSpecificDoubleSetting(PrinterCap::CapID category, GPDriver::AddDriverSpecificDoubleSetting(PrinterCap::CapID category,
const char* key) { const char* key) {
if (getJobData()->Settings().HasDouble(key)) if (GetJobData()->Settings().HasDouble(key))
fConfiguration.fDoubleSettings[key] = fConfiguration.fDoubleSettings[key] =
getJobData()->Settings().GetDouble(key); GetJobData()->Settings().GetDouble(key);
} }
bool bool
GPDriver::startPage(int) GPDriver::StartPage(int)
{ {
fBinding.BeginPage(); fBinding.BeginPage();
return true; return true;
@@ -200,7 +200,7 @@ GPDriver::startPage(int)
bool bool
GPDriver::endPage(int) GPDriver::EndPage(int)
{ {
try { try {
fBinding.EndPage(); fBinding.EndPage();
@@ -214,7 +214,7 @@ GPDriver::endPage(int)
bool bool
GPDriver::endDoc(bool) GPDriver::EndDocument(bool)
{ {
try { try {
fBinding.EndJob(); fBinding.EndJob();
@@ -228,7 +228,7 @@ GPDriver::endDoc(bool)
bool bool
GPDriver::nextBand(BBitmap* bitmap, BPoint* offset) GPDriver::NextBand(BBitmap* bitmap, BPoint* offset)
{ {
DBGMSG(("> nextBand\n")); DBGMSG(("> nextBand\n"));
try { try {
@@ -245,10 +245,10 @@ GPDriver::nextBand(BBitmap* bitmap, BPoint* offset)
int x = (int)offset->x; int x = (int)offset->x;
int y = (int)offset->y; int y = (int)offset->y;
int page_height = getPageHeight(); int pageHeight = GetPageHeight();
if (y + height > page_height) if (y + height > pageHeight)
height = page_height - y; height = pageHeight - y;
rc.bottom = height - 1; rc.bottom = height - 1;
@@ -284,7 +284,7 @@ GPDriver::nextBand(BBitmap* bitmap, BPoint* offset)
DBGMSG(("band bitmap is empty.\n")); DBGMSG(("band bitmap is empty.\n"));
} }
if (y >= page_height) { if (y >= pageHeight) {
offset->x = -1.0; offset->x = -1.0;
offset->y = -1.0; offset->y = -1.0;
} else } else
@@ -24,7 +24,7 @@ public:
throw(TransportException); throw(TransportException);
protected: protected:
bool startDoc(); bool StartDocument();
void SetParameter(BString& parameter, PrinterCap::CapID category, void SetParameter(BString& parameter, PrinterCap::CapID category,
int value); int value);
void SetDriverSpecificSettings(); void SetDriverSpecificSettings();
@@ -38,10 +38,10 @@ protected:
const char* key); const char* key);
void AddDriverSpecificDoubleSetting(PrinterCap::CapID category, void AddDriverSpecificDoubleSetting(PrinterCap::CapID category,
const char* key); const char* key);
bool startPage(int page); bool StartPage(int page);
bool nextBand(BBitmap* bitmap, BPoint* offset); bool NextBand(BBitmap* bitmap, BPoint* offset);
bool endPage(int page); bool EndPage(int page);
bool endDoc(bool success); bool EndDocument(bool success);
void ShowError(const char* message); void ShowError(const char* message);
private: private:
+71 -76
View File
@@ -23,30 +23,24 @@
#include "ValidRect.h" #include "ValidRect.h"
#if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE)) PCL5Driver::PCL5Driver(BMessage* message, PrinterData* printerData,
using namespace std; const PrinterCap* printerCap)
#else
#define std
#endif
PCL5Driver::PCL5Driver(BMessage* msg, PrinterData* printer_data,
const PrinterCap* printer_cap)
: :
GraphicsDriver(msg, printer_data, printer_cap) GraphicsDriver(message, printerData, printerCap),
fCompressionMethod(0),
fHalftone(NULL)
{ {
fHalftone = NULL;
} }
bool bool
PCL5Driver::startDoc() PCL5Driver::StartDocument()
{ {
try { try {
jobStart(); _JobStart();
fHalftone = new Halftone(getJobData()->getSurfaceType(), fHalftone = new Halftone(GetJobData()->getSurfaceType(),
getJobData()->getGamma(), getJobData()->getInkDensity(), GetJobData()->getGamma(), GetJobData()->getInkDensity(),
getJobData()->getDitherType()); GetJobData()->getDitherType());
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -56,17 +50,17 @@ PCL5Driver::startDoc()
bool bool
PCL5Driver::startPage(int) PCL5Driver::StartPage(int)
{ {
return true; return true;
} }
bool bool
PCL5Driver::endPage(int) PCL5Driver::EndPage(int)
{ {
try { try {
writeSpoolChar('\014'); WriteSpoolChar('\014');
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -76,13 +70,14 @@ PCL5Driver::endPage(int)
bool bool
PCL5Driver::endDoc(bool) PCL5Driver::EndDocument(bool)
{ {
try { try {
if (fHalftone) { if (fHalftone != NULL) {
delete fHalftone; delete fHalftone;
fHalftone = NULL;
} }
jobEnd(); _JobEnd();
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -92,7 +87,7 @@ PCL5Driver::endDoc(bool)
bool bool
PCL5Driver::nextBand(BBitmap* bitmap, BPoint* offset) PCL5Driver::NextBand(BBitmap* bitmap, BPoint* offset)
{ {
DBGMSG(("> nextBand\n")); DBGMSG(("> nextBand\n"));
@@ -110,10 +105,10 @@ PCL5Driver::nextBand(BBitmap* bitmap, BPoint* offset)
int x = (int)offset->x; int x = (int)offset->x;
int y = (int)offset->y; int y = (int)offset->y;
int page_height = getPageHeight(); int pageHeight = GetPageHeight();
if (y + height > page_height) if (y + height > pageHeight)
height = page_height - y; height = pageHeight - y;
rc.bottom = height - 1; rc.bottom = height - 1;
@@ -149,8 +144,8 @@ PCL5Driver::nextBand(BBitmap* bitmap, BPoint* offset)
+ rc.top * delta + rc.top * delta
+ (rc.left * fHalftone->getPixelDepth()) / 8; + (rc.left * fHalftone->getPixelDepth()) / 8;
int compression_method; int compressionMethod;
int compressed_size; int compressedSize;
const uchar* buffer; const uchar* buffer;
uchar* in_buffer = new uchar[in_size]; uchar* in_buffer = new uchar[in_size];
@@ -161,10 +156,10 @@ PCL5Driver::nextBand(BBitmap* bitmap, BPoint* offset)
DBGMSG(("move\n")); DBGMSG(("move\n"));
move(x, y); _Move(x, y);
startRasterGraphics(width, height); _StartRasterGraphics(width, height);
const bool color = getJobData()->getColor() == JobData::kColor; const bool color = GetJobData()->getColor() == JobData::kColor;
const int num_planes = color ? 3 : 1; const int num_planes = color ? 3 : 1;
if (color) { if (color) {
@@ -178,22 +173,22 @@ PCL5Driver::nextBand(BBitmap* bitmap, BPoint* offset)
fHalftone->dither(in_buffer, ptr, x, y, width); fHalftone->dither(in_buffer, ptr, x, y, width);
compressed_size = pack_bits(out_buffer, in_buffer, in_size); compressedSize = pack_bits(out_buffer, in_buffer, in_size);
if (compressed_size + bytesToEnterCompressionMethod(2) if (compressedSize + _BytesToEnterCompressionMethod(2)
< in_size + bytesToEnterCompressionMethod(0)) { < in_size + _BytesToEnterCompressionMethod(0)) {
compression_method = 2; // back bits compressionMethod = 2; // back bits
buffer = out_buffer; buffer = out_buffer;
} else { } else {
compression_method = 0; // uncompressed compressionMethod = 0; // uncompressed
buffer = in_buffer; buffer = in_buffer;
compressed_size = in_size; compressedSize = in_size;
} }
rasterGraphics( _RasterGraphics(
compression_method, compressionMethod,
buffer, buffer,
compressed_size, compressedSize,
plane == num_planes - 1); plane == num_planes - 1);
} }
@@ -202,12 +197,12 @@ PCL5Driver::nextBand(BBitmap* bitmap, BPoint* offset)
y++; y++;
} }
endRasterGraphics(); _EndRasterGraphics();
} else } else
DBGMSG(("band bitmap is clean.\n")); DBGMSG(("band bitmap is clean.\n"));
if (y >= page_height) { if (y >= pageHeight) {
offset->x = -1.0; offset->x = -1.0;
offset->y = -1.0; offset->y = -1.0;
} else } else
@@ -225,93 +220,93 @@ PCL5Driver::nextBand(BBitmap* bitmap, BPoint* offset)
void void
PCL5Driver::jobStart() PCL5Driver::_JobStart()
{ {
const bool color = getJobData()->getColor() == JobData::kColor; const bool color = GetJobData()->getColor() == JobData::kColor;
// enter PCL5 // enter PCL5
writeSpoolString("\033%%-12345X@PJL ENTER LANGUAGE=PCL\n"); WriteSpoolString("\033%%-12345X@PJL ENTER LANGUAGE=PCL\n");
// reset // reset
writeSpoolString("\033E"); WriteSpoolString("\033E");
// dpi // dpi
writeSpoolString("\033*t%dR", getJobData()->getXres()); WriteSpoolString("\033*t%dR", GetJobData()->getXres());
// unit of measure // unit of measure
writeSpoolString("\033&u%dD", getJobData()->getXres()); WriteSpoolString("\033&u%dD", GetJobData()->getXres());
// page size // page size
writeSpoolString("\033&l0A"); WriteSpoolString("\033&l0A");
// page orientation // page orientation
writeSpoolString("\033&l0O"); WriteSpoolString("\033&l0O");
if (color) { if (color) {
// 3 color planes (red, green, blue) // 3 color planes (red, green, blue)
writeSpoolString("\033*r3U"); WriteSpoolString("\033*r3U");
} }
// raster presentation // raster presentation
writeSpoolString("\033*r0F"); WriteSpoolString("\033*r0F");
// top maring and perforation skip // top maring and perforation skip
writeSpoolString("\033&l0e0L"); WriteSpoolString("\033&l0e0L");
// clear horizontal margins // clear horizontal margins
writeSpoolString("\0339"); WriteSpoolString("\0339");
// number of copies // number of copies
// writeSpoolString("\033&l%ldL", getJobData()->getCopies()); // WriteSpoolString("\033&l%ldL", GetJobData()->getCopies());
} }
void void
PCL5Driver::startRasterGraphics(int width, int height) PCL5Driver::_StartRasterGraphics(int width, int height)
{ {
// width // width
writeSpoolString("\033*r%dS", width); WriteSpoolString("\033*r%dS", width);
// height // height
writeSpoolString("\033*r%dT", height); WriteSpoolString("\033*r%dT", height);
// start raster graphics // start raster graphics
writeSpoolString("\033*r1A"); WriteSpoolString("\033*r1A");
fCompressionMethod = -1; fCompressionMethod = -1;
} }
void void
PCL5Driver::endRasterGraphics() PCL5Driver::_EndRasterGraphics()
{ {
writeSpoolString("\033*rB"); WriteSpoolString("\033*rB");
} }
void void
PCL5Driver::rasterGraphics(int compression_method, const uchar* buffer, PCL5Driver::_RasterGraphics(int compressionMethod, const uchar* buffer,
int size, bool lastPlane) int size, bool lastPlane)
{ {
if (fCompressionMethod != compression_method) { if (fCompressionMethod != compressionMethod) {
writeSpoolString("\033*b%dM", compression_method); WriteSpoolString("\033*b%dM", compressionMethod);
fCompressionMethod = compression_method; fCompressionMethod = compressionMethod;
} }
writeSpoolString("\033*b%d", size); WriteSpoolString("\033*b%d", size);
if (lastPlane) if (lastPlane)
writeSpoolString("W"); WriteSpoolString("W");
else else
writeSpoolString("V"); WriteSpoolString("V");
writeSpoolData(buffer, size); WriteSpoolData(buffer, size);
} }
void void
PCL5Driver::jobEnd() PCL5Driver::_JobEnd()
{ {
writeSpoolString("\033&l1T"); WriteSpoolString("\033&l1T");
writeSpoolString("\033E"); WriteSpoolString("\033E");
} }
void void
PCL5Driver::move(int x, int y) PCL5Driver::_Move(int x, int y)
{ {
writeSpoolString("\033*p%dx%dY", x, y + 75); WriteSpoolString("\033*p%dx%dY", x, y + 75);
} }
int int
PCL5Driver::bytesToEnterCompressionMethod(int compression_method) PCL5Driver::_BytesToEnterCompressionMethod(int compressionMethod)
{ {
if (fCompressionMethod == compression_method) if (fCompressionMethod == compressionMethod)
return 0; return 0;
else else
return 5; return 5;
+14 -14
View File
@@ -14,25 +14,25 @@ class Halftone;
class PCL5Driver : public GraphicsDriver { class PCL5Driver : public GraphicsDriver {
public: public:
PCL5Driver(BMessage* msg, PrinterData* printer_data, PCL5Driver(BMessage* message, PrinterData* printerData,
const PrinterCap* printer_cap); const PrinterCap* printerCap);
protected: protected:
virtual bool startDoc(); virtual bool StartDocument();
virtual bool startPage(int page); virtual bool StartPage(int page);
virtual bool nextBand(BBitmap* bitmap, BPoint* offset); virtual bool NextBand(BBitmap* bitmap, BPoint* offset);
virtual bool endPage(int page); virtual bool EndPage(int page);
virtual bool endDoc(bool success); virtual bool EndDocument(bool success);
private: private:
void move(int x, int y); void _Move(int x, int y);
void jobStart(); void _JobStart();
void startRasterGraphics(int width, int height); void _StartRasterGraphics(int width, int height);
void endRasterGraphics(); void _EndRasterGraphics();
void rasterGraphics(int compression_method, void _RasterGraphics(int compression_method,
const uchar* buffer, int size, bool lastPlane); const uchar* buffer, int size, bool lastPlane);
void jobEnd(); void _JobEnd();
int bytesToEnterCompressionMethod(int compression_method); int _BytesToEnterCompressionMethod(int compression_method);
int fCompressionMethod; int fCompressionMethod;
Halftone* fHalftone; Halftone* fHalftone;
+59 -64
View File
@@ -25,12 +25,6 @@
#include "UIDriver.h" #include "UIDriver.h"
#include "ValidRect.h" #include "ValidRect.h"
#if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE))
using namespace std;
#else
#define std
#endif
// DeltaRowStreamCompressor writes the delta row directly to the // DeltaRowStreamCompressor writes the delta row directly to the
// in the contructor specified stream. // in the contructor specified stream.
@@ -55,31 +49,32 @@ private:
}; };
PCL6Driver::PCL6Driver(BMessage* msg, PrinterData* printer_data, PCL6Driver::PCL6Driver(BMessage* message, PrinterData* printerData,
const PrinterCap* printer_cap) const PrinterCap* printerCap)
: :
GraphicsDriver(msg, printer_data, printer_cap) GraphicsDriver(message, printerData, printerCap),
fWriter(NULL),
fMediaSide(PCL6Writer::kFrontMediaSide),
fHalftone(NULL)
{ {
fHalftone = NULL;
fWriter = NULL;
} }
void void
PCL6Driver::write(const uint8* data, uint32 size) PCL6Driver::Write(const uint8* data, uint32 size)
{ {
writeSpoolData(data, size); WriteSpoolData(data, size);
} }
bool bool
PCL6Driver::startDoc() PCL6Driver::StartDocument()
{ {
try { try {
jobStart(); _JobStart();
fHalftone = new Halftone(getJobData()->getSurfaceType(), fHalftone = new Halftone(GetJobData()->getSurfaceType(),
getJobData()->getGamma(), getJobData()->getInkDensity(), GetJobData()->getGamma(), GetJobData()->getInkDensity(),
getJobData()->getDitherType()); GetJobData()->getDitherType());
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -89,12 +84,12 @@ PCL6Driver::startDoc()
bool bool
PCL6Driver::endDoc(bool) PCL6Driver::EndDocument(bool)
{ {
try { try {
if (fHalftone) if (fHalftone)
delete fHalftone; delete fHalftone;
jobEnd(); _JobEnd();
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -104,7 +99,7 @@ PCL6Driver::endDoc(bool)
bool bool
PCL6Driver::nextBand(BBitmap* bitmap, BPoint* offset) PCL6Driver::NextBand(BBitmap* bitmap, BPoint* offset)
{ {
DBGMSG(("> nextBand\n")); DBGMSG(("> nextBand\n"));
@@ -112,7 +107,7 @@ PCL6Driver::nextBand(BBitmap* bitmap, BPoint* offset)
int y = (int)offset->y; int y = (int)offset->y;
PCL6Rasterizer* rasterizer; PCL6Rasterizer* rasterizer;
if (useColorMode()) { if (_UseColorMode()) {
#if COLOR_DEPTH == 8 #if COLOR_DEPTH == 8
rasterizer = new ColorRGBRasterizer(fHalftone); rasterizer = new ColorRGBRasterizer(fHalftone);
#elif COLOR_DEPTH == 1 #elif COLOR_DEPTH == 1
@@ -125,14 +120,14 @@ PCL6Driver::nextBand(BBitmap* bitmap, BPoint* offset)
auto_ptr<Rasterizer> _rasterizer(rasterizer); auto_ptr<Rasterizer> _rasterizer(rasterizer);
bool valid = rasterizer->SetBitmap((int)offset->x, (int)offset->y, bool valid = rasterizer->SetBitmap((int)offset->x, (int)offset->y,
bitmap, getPageHeight()); bitmap, GetPageHeight());
if (valid) { if (valid) {
rasterizer->InitializeBuffer(); rasterizer->InitializeBuffer();
// Use compressor to calculate delta row size // Use compressor to calculate delta row size
DeltaRowCompressor* deltaRowCompressor = NULL; DeltaRowCompressor* deltaRowCompressor = NULL;
if (supportsDeltaRowCompression()) { if (_SupportsDeltaRowCompression()) {
deltaRowCompressor = deltaRowCompressor =
new DeltaRowCompressor(rasterizer->GetOutRowSize(), 0); new DeltaRowCompressor(rasterizer->GetOutRowSize(), 0);
if (deltaRowCompressor->InitCheck() != B_OK) { if (deltaRowCompressor->InitCheck() != B_OK) {
@@ -166,11 +161,11 @@ PCL6Driver::nextBand(BBitmap* bitmap, BPoint* offset)
int outRowSize = rasterizer->GetOutRowSize(); int outRowSize = rasterizer->GetOutRowSize();
int width = rasterizer->GetWidth(); int width = rasterizer->GetWidth();
int height = rasterizer->GetHeight(); int height = rasterizer->GetHeight();
writeBitmap(outBuffer, outBufferSize, outRowSize, xPage, yPage, _WriteBitmap(outBuffer, outBufferSize, outRowSize, xPage, yPage,
width, height, deltaRowSize); width, height, deltaRowSize);
} }
if (y >= getPageHeight()) { if (y >= GetPageHeight()) {
offset->x = -1.0; offset->x = -1.0;
offset->y = -1.0; offset->y = -1.0;
} else { } else {
@@ -188,7 +183,7 @@ PCL6Driver::nextBand(BBitmap* bitmap, BPoint* offset)
void void
PCL6Driver::writeBitmap(const uchar* buffer, int outSize, int rowSize, int x, PCL6Driver::_WriteBitmap(const uchar* buffer, int outSize, int rowSize, int x,
int y, int width, int height, int deltaRowSize) int y, int width, int height, int deltaRowSize)
{ {
// choose the best compression method // choose the best compression method
@@ -196,14 +191,14 @@ PCL6Driver::writeBitmap(const uchar* buffer, int outSize, int rowSize, int x,
int dataSize = outSize; int dataSize = outSize;
#if ENABLE_DELTA_ROW_COMPRESSION #if ENABLE_DELTA_ROW_COMPRESSION
if (supportsDeltaRowCompression() && deltaRowSize < dataSize) { if (_SupportsDeltaRowCompression() && deltaRowSize < dataSize) {
compressionMethod = PCL6Writer::kDeltaRowCompression; compressionMethod = PCL6Writer::kDeltaRowCompression;
dataSize = deltaRowSize; dataSize = deltaRowSize;
} }
#endif #endif
#if ENABLE_RLE_COMPRESSION #if ENABLE_RLE_COMPRESSION
if (supportsRLECompression()) { if (_SupportsRLECompression()) {
int rleSize = pack_bits_size(buffer, outSize); int rleSize = pack_bits_size(buffer, outSize);
if (rleSize < dataSize) { if (rleSize < dataSize) {
compressionMethod = PCL6Writer::kRLECompression; compressionMethod = PCL6Writer::kRLECompression;
@@ -213,14 +208,14 @@ PCL6Driver::writeBitmap(const uchar* buffer, int outSize, int rowSize, int x,
#endif #endif
// write bitmap // write bitmap
move(x, y); _Move(x, y);
startRasterGraphics(x, y, width, height, compressionMethod); _StartRasterGraphics(x, y, width, height, compressionMethod);
rasterGraphics(buffer, outSize, dataSize, rowSize, height, _RasterGraphics(buffer, outSize, dataSize, rowSize, height,
compressionMethod); compressionMethod);
endRasterGraphics(); _EndRasterGraphics();
#if DISPLAY_COMPRESSION_STATISTICS #if DISPLAY_COMPRESSION_STATISTICS
fprintf(stderr, "Out Size %d %2.2f\n", (int)outSize, 100.0); fprintf(stderr, "Out Size %d %2.2f\n", (int)outSize, 100.0);
@@ -239,15 +234,15 @@ PCL6Driver::writeBitmap(const uchar* buffer, int outSize, int rowSize, int x,
void void
PCL6Driver::jobStart() PCL6Driver::_JobStart()
{ {
// PCL6 begin // PCL6 begin
fWriter = new PCL6Writer(this); fWriter = new PCL6Writer(this);
PCL6Writer::ProtocolClass pc = PCL6Writer::ProtocolClass pc =
(PCL6Writer::ProtocolClass)getProtocolClass(); (PCL6Writer::ProtocolClass)GetProtocolClass();
fWriter->PJLHeader(pc, getJobData()->getXres(), fWriter->PJLHeader(pc, GetJobData()->getXres(),
"Copyright (c) 2003, 2004 Haiku"); "Copyright (c) 2003 - 2010 Haiku");
fWriter->BeginSession(getJobData()->getXres(), getJobData()->getYres(), fWriter->BeginSession(GetJobData()->getXres(), GetJobData()->getYres(),
PCL6Writer::kInch, PCL6Writer::kBackChAndErrPage); PCL6Writer::kInch, PCL6Writer::kBackChAndErrPage);
fWriter->OpenDataSource(); fWriter->OpenDataSource();
fMediaSide = PCL6Writer::kFrontMediaSide; fMediaSide = PCL6Writer::kFrontMediaSide;
@@ -255,20 +250,20 @@ PCL6Driver::jobStart()
bool bool
PCL6Driver::startPage(int) PCL6Driver::StartPage(int)
{ {
PCL6Writer::Orientation orientation = PCL6Writer::kPortrait; PCL6Writer::Orientation orientation = PCL6Writer::kPortrait;
if (getJobData()->getOrientation() == JobData::kLandscape) { if (GetJobData()->getOrientation() == JobData::kLandscape) {
orientation = PCL6Writer::kLandscape; orientation = PCL6Writer::kLandscape;
} }
PCL6Writer::MediaSize mediaSize = PCL6Writer::MediaSize mediaSize =
PCL6Driver::mediaSize(getJobData()->getPaper()); _MediaSize(GetJobData()->getPaper());
PCL6Writer::MediaSource mediaSource = PCL6Writer::MediaSource mediaSource =
PCL6Driver::mediaSource(getJobData()->getPaperSource()); _MediaSource(GetJobData()->getPaperSource());
if (getJobData()->getPrintStyle() == JobData::kSimplex) { if (GetJobData()->getPrintStyle() == JobData::kSimplex) {
fWriter->BeginPage(orientation, mediaSize, mediaSource); fWriter->BeginPage(orientation, mediaSize, mediaSource);
} else if (getJobData()->getPrintStyle() == JobData::kDuplex) { } else if (GetJobData()->getPrintStyle() == JobData::kDuplex) {
// TODO move duplex binding option to UI // TODO move duplex binding option to UI
fWriter->BeginPage(orientation, mediaSize, mediaSource, fWriter->BeginPage(orientation, mediaSize, mediaSource,
PCL6Writer::kDuplexVerticalBinding, fMediaSide); PCL6Writer::kDuplexVerticalBinding, fMediaSide);
@@ -281,10 +276,10 @@ PCL6Driver::startPage(int)
return false; return false;
// PageOrigin from Windows NT printer driver // PageOrigin from Windows NT printer driver
int x = 142 * getJobData()->getXres() / 600; int x = 142 * GetJobData()->getXres() / 600;
int y = 100 * getJobData()->getYres() / 600; int y = 100 * GetJobData()->getYres() / 600;
fWriter->SetPageOrigin(x, y); fWriter->SetPageOrigin(x, y);
fWriter->SetColorSpace(useColorMode() ? PCL6Writer::kRGB fWriter->SetColorSpace(_UseColorMode() ? PCL6Writer::kRGB
: PCL6Writer::kGray); : PCL6Writer::kGray);
fWriter->SetPaintTxMode(PCL6Writer::kOpaque); fWriter->SetPaintTxMode(PCL6Writer::kOpaque);
fWriter->SetSourceTxMode(PCL6Writer::kOpaque); fWriter->SetSourceTxMode(PCL6Writer::kOpaque);
@@ -294,11 +289,11 @@ PCL6Driver::startPage(int)
void void
PCL6Driver::startRasterGraphics(int x, int y, int width, int height, PCL6Driver::_StartRasterGraphics(int x, int y, int width, int height,
PCL6Writer::Compression compressionMethod) PCL6Writer::Compression compressionMethod)
{ {
PCL6Writer::ColorDepth colorDepth; PCL6Writer::ColorDepth colorDepth;
if (useColorMode()) { if (_UseColorMode()) {
#if COLOR_DEPTH == 8 #if COLOR_DEPTH == 8
colorDepth = PCL6Writer::k8Bit; colorDepth = PCL6Writer::k8Bit;
#elif COLOR_DEPTH == 1 #elif COLOR_DEPTH == 1
@@ -316,14 +311,14 @@ PCL6Driver::startRasterGraphics(int x, int y, int width, int height,
void void
PCL6Driver::endRasterGraphics() PCL6Driver::_EndRasterGraphics()
{ {
fWriter->EndImage(); fWriter->EndImage();
} }
void void
PCL6Driver::rasterGraphics(const uchar* buffer, int bufferSize, int dataSize, PCL6Driver::_RasterGraphics(const uchar* buffer, int bufferSize, int dataSize,
int rowSize, int height, int compressionMethod) int rowSize, int height, int compressionMethod)
{ {
// write bitmap byte size // write bitmap byte size
@@ -365,10 +360,10 @@ PCL6Driver::rasterGraphics(const uchar* buffer, int bufferSize, int dataSize,
bool bool
PCL6Driver::endPage(int) PCL6Driver::EndPage(int)
{ {
try { try {
fWriter->EndPage(getJobData()->getCopies()); fWriter->EndPage(GetJobData()->getCopies());
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -378,7 +373,7 @@ PCL6Driver::endPage(int)
void void
PCL6Driver::jobEnd() PCL6Driver::_JobEnd()
{ {
fWriter->CloseDataSource(); fWriter->CloseDataSource();
fWriter->EndSession(); fWriter->EndSession();
@@ -390,36 +385,36 @@ PCL6Driver::jobEnd()
void void
PCL6Driver::move(int x, int y) PCL6Driver::_Move(int x, int y)
{ {
fWriter->SetCursor(x, y); fWriter->SetCursor(x, y);
} }
bool bool
PCL6Driver::supportsRLECompression() PCL6Driver::_SupportsRLECompression()
{ {
return getJobData()->getColor() != JobData::kColorCompressionDisabled; return GetJobData()->getColor() != JobData::kColorCompressionDisabled;
} }
bool bool
PCL6Driver::supportsDeltaRowCompression() PCL6Driver::_SupportsDeltaRowCompression()
{ {
return getProtocolClass() >= PCL6Writer::kProtocolClass2_1 return GetProtocolClass() >= PCL6Writer::kProtocolClass2_1
&& getJobData()->getColor() != JobData::kColorCompressionDisabled; && GetJobData()->getColor() != JobData::kColorCompressionDisabled;
} }
bool bool
PCL6Driver::useColorMode() PCL6Driver::_UseColorMode()
{ {
return getJobData()->getColor() != JobData::kMonochrome; return GetJobData()->getColor() != JobData::kMonochrome;
} }
PCL6Writer::MediaSize PCL6Writer::MediaSize
PCL6Driver::mediaSize(JobData::Paper paper) PCL6Driver::_MediaSize(JobData::Paper paper)
{ {
switch (paper) { switch (paper) {
case JobData::kLetter: case JobData::kLetter:
@@ -466,7 +461,7 @@ PCL6Driver::mediaSize(JobData::Paper paper)
PCL6Writer::MediaSource PCL6Writer::MediaSource
PCL6Driver::mediaSource(JobData::PaperSource source) PCL6Driver::_MediaSource(JobData::PaperSource source)
{ {
switch (source) { switch (source) {
case JobData::kAuto: case JobData::kAuto:
+20 -20
View File
@@ -18,35 +18,35 @@ class Halftone;
class PCL6Driver : public GraphicsDriver, public PCL6WriterStream class PCL6Driver : public GraphicsDriver, public PCL6WriterStream
{ {
public: public:
PCL6Driver(BMessage* msg, PrinterData* printer_data, PCL6Driver(BMessage* message, PrinterData* printerData,
const PrinterCap* printer_cap); const PrinterCap* printerCap);
void write(const uint8* data, uint32 size); void Write(const uint8* data, uint32 size);
protected: protected:
virtual bool startDoc(); virtual bool StartDocument();
virtual bool startPage(int page); virtual bool StartPage(int page);
virtual bool nextBand(BBitmap* bitmap, BPoint* offset); virtual bool NextBand(BBitmap* bitmap, BPoint* offset);
virtual bool endPage(int page); virtual bool EndPage(int page);
virtual bool endDoc(bool success); virtual bool EndDocument(bool success);
private: private:
bool supportsRLECompression(); bool _SupportsRLECompression();
bool supportsDeltaRowCompression(); bool _SupportsDeltaRowCompression();
bool useColorMode(); bool _UseColorMode();
PCL6Writer::MediaSize mediaSize(JobData::Paper paper); PCL6Writer::MediaSize _MediaSize(JobData::Paper paper);
PCL6Writer::MediaSource mediaSource(JobData::PaperSource source); PCL6Writer::MediaSource _MediaSource(JobData::PaperSource source);
void move(int x, int y); void _Move(int x, int y);
void jobStart(); void _JobStart();
void writeBitmap(const uchar* buffer, int outSize, int rowSize, void _WriteBitmap(const uchar* buffer, int outSize, int rowSize,
int x, int y, int width, int height, int deltaRowSize); int x, int y, int width, int height, int deltaRowSize);
void startRasterGraphics(int x, int y, int width, int height, void _StartRasterGraphics(int x, int y, int width, int height,
PCL6Writer::Compression compressionMethod); PCL6Writer::Compression compressionMethod);
void endRasterGraphics(); void _EndRasterGraphics();
void rasterGraphics(const uchar* buffer, int bufferSize, void _RasterGraphics(const uchar* buffer, int bufferSize,
int dataSize, int rowSize, int height, int dataSize, int rowSize, int height,
int compression_method); int compression_method);
void jobEnd(); void _JobEnd();
PCL6Writer* fWriter; PCL6Writer* fWriter;
PCL6Writer::MediaSide fMediaSide; // side if in duplex mode PCL6Writer::MediaSide fMediaSide; // side if in duplex mode
@@ -46,7 +46,7 @@ void
PCL6Writer::Flush() PCL6Writer::Flush()
{ {
if (fIndex > 0) { if (fIndex > 0) {
fStream->write(fBuffer, fIndex); fStream->Write(fBuffer, fIndex);
fIndex = 0; fIndex = 0;
} }
} }
+1 -1
View File
@@ -17,7 +17,7 @@ class PCL6Driver;
class PCL6WriterStream { class PCL6WriterStream {
public: public:
virtual ~PCL6WriterStream() {} virtual ~PCL6WriterStream() {}
virtual void write(const uint8* data, uint32 size) = 0; virtual void Write(const uint8* data, uint32 size) = 0;
}; };
+97 -103
View File
@@ -29,28 +29,23 @@
#include "UIDriver.h" #include "UIDriver.h"
#include "ValidRect.h" #include "ValidRect.h"
#if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE))
using namespace std;
#else
#define std
#endif
PSDriver::PSDriver(BMessage* message, PrinterData* printerData,
PSDriver::PSDriver(BMessage* msg, PrinterData* printer_data, const PrinterCap* printerCap)
const PrinterCap* printer_cap)
: :
GraphicsDriver(msg, printer_data, printer_cap) GraphicsDriver(message, printerData, printerCap),
fPrintedPages(0),
fCompressionMethod(0),
fHalftone(NULL),
fFilterIO(NULL)
{ {
fPrintedPages = 0;
fHalftone = NULL;
fFilterIO = NULL;
} }
void void
PSDriver::StartFilterIfNeeded() PSDriver::_StartFilterIfNeeded()
{ {
const PSData* data = dynamic_cast<const PSData*>(getPrinterData()); const PSData* data = dynamic_cast<const PSData*>(GetPrinterData());
PPDParser parser(BPath(data->fPPD.String())); PPDParser parser(BPath(data->fPPD.String()));
if (parser.InitCheck() == B_OK) { if (parser.InitCheck() == B_OK) {
BString param = parser.GetParameter("FoomaticRIPCommandLine"); BString param = parser.GetParameter("FoomaticRIPCommandLine");
@@ -72,20 +67,20 @@ PSDriver::StartFilterIfNeeded()
void void
PSDriver::FlushFilterIfNeeded() PSDriver::_FlushFilterIfNeeded()
{ {
if (fFilterIO) { if (fFilterIO) {
char buffer[1024]; char buffer[1024];
ssize_t len; ssize_t len;
while ((len = fFilterIO->Read(buffer, sizeof(buffer))) > 0) while ((len = fFilterIO->Read(buffer, sizeof(buffer))) > 0)
writeSpoolData(buffer, len); WriteSpoolData(buffer, len);
} }
} }
void void
PSDriver::writePSString(const char* format, ...) PSDriver::_WritePSString(const char* format, ...)
{ {
char str[256]; char str[256];
va_list ap; va_list ap;
@@ -95,32 +90,32 @@ PSDriver::writePSString(const char* format, ...)
if (fFilterIO) if (fFilterIO)
fFilterIO->Write(str, strlen(str)); fFilterIO->Write(str, strlen(str));
else else
writeSpoolData(str, strlen(str)); WriteSpoolData(str, strlen(str));
va_end(ap); va_end(ap);
} }
void void
PSDriver::writePSData(const void* data, size_t size) PSDriver::_WritePSData(const void* data, size_t size)
{ {
if (fFilterIO) if (fFilterIO)
fFilterIO->Write(data, size); fFilterIO->Write(data, size);
else else
writeSpoolData(data, size); WriteSpoolData(data, size);
} }
bool bool
PSDriver::startDoc() PSDriver::StartDocument()
{ {
try { try {
StartFilterIfNeeded(); _StartFilterIfNeeded();
jobStart(); _JobStart();
fHalftone = new Halftone(getJobData()->getSurfaceType(), fHalftone = new Halftone(GetJobData()->getSurfaceType(),
getJobData()->getGamma(), getJobData()->getInkDensity(), GetJobData()->getGamma(), GetJobData()->getInkDensity(),
getJobData()->getDitherType()); GetJobData()->getDitherType());
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -130,25 +125,25 @@ PSDriver::startDoc()
bool bool
PSDriver::startPage(int page) PSDriver::StartPage(int page)
{ {
page ++; page ++;
writePSString("%%%%Page: %d %d\n", page, page); _WritePSString("%%%%Page: %d %d\n", page, page);
writePSString("gsave\n"); _WritePSString("gsave\n");
setupCTM(); _SetupCTM();
return true; return true;
} }
bool bool
PSDriver::endPage(int) PSDriver::EndPage(int)
{ {
try { try {
fPrintedPages ++; fPrintedPages ++;
writePSString("grestore\n"); _WritePSString("grestore\n");
writePSString("showpage\n"); _WritePSString("showpage\n");
FlushFilterIfNeeded(); _FlushFilterIfNeeded();
return true; return true;
} }
@@ -159,37 +154,38 @@ PSDriver::endPage(int)
void void
PSDriver::setupCTM() PSDriver::_SetupCTM()
{ {
const float leftMargin = getJobData()->getPrintableRect().left; const float leftMargin = GetJobData()->getPrintableRect().left;
const float topMargin = getJobData()->getPrintableRect().top; const float topMargin = GetJobData()->getPrintableRect().top;
if (getJobData()->getOrientation() == JobData::kPortrait) { if (GetJobData()->getOrientation() == JobData::kPortrait) {
// move origin from bottom left to top left // move origin from bottom left to top left
// and set margin // and set margin
writePSString("%f %f translate\n", leftMargin, _WritePSString("%f %f translate\n", leftMargin,
getJobData()->getPaperRect().Height()-topMargin); GetJobData()->getPaperRect().Height()-topMargin);
} else { } else {
// landscape: // landscape:
// move origin from bottom left to margin top and left // move origin from bottom left to margin top and left
// and rotate page contents // and rotate page contents
writePSString("%f %f translate\n", topMargin, leftMargin); _WritePSString("%f %f translate\n", topMargin, leftMargin);
writePSString("90 rotate\n"); _WritePSString("90 rotate\n");
} }
// y values increase from top to bottom // y values increase from top to bottom
// units of measure is dpi // units of measure is dpi
writePSString("72 %d div 72 -%d div scale\n", getJobData()->getXres(), _WritePSString("72 %d div 72 -%d div scale\n", GetJobData()->getXres(),
getJobData()->getYres()); GetJobData()->getYres());
} }
bool bool
PSDriver::endDoc(bool) PSDriver::EndDocument(bool)
{ {
try { try {
if (fHalftone) { if (fHalftone) {
delete fHalftone; delete fHalftone;
fHalftone = NULL;
} }
jobEnd(); _JobEnd();
return true; return true;
} }
catch (TransportException& err) { catch (TransportException& err) {
@@ -198,8 +194,8 @@ PSDriver::endDoc(bool)
} }
inline uchar static inline uchar
hex_digit(uchar value) ToHexDigit(uchar value)
{ {
if (value <= 9) return '0' + value; if (value <= 9) return '0' + value;
else return 'a' + (value - 10); else return 'a' + (value - 10);
@@ -207,7 +203,7 @@ hex_digit(uchar value)
bool bool
PSDriver::nextBand(BBitmap* bitmap, BPoint* offset) PSDriver::NextBand(BBitmap* bitmap, BPoint* offset)
{ {
DBGMSG(("> nextBand\n")); DBGMSG(("> nextBand\n"));
@@ -225,7 +221,7 @@ PSDriver::nextBand(BBitmap* bitmap, BPoint* offset)
int x = (int)offset->x; int x = (int)offset->x;
int y = (int)offset->y; int y = (int)offset->y;
int page_height = getPageHeight(); int page_height = GetPageHeight();
if (y + height > page_height) { if (y + height > page_height) {
height = page_height - y; height = page_height - y;
@@ -245,7 +241,7 @@ PSDriver::nextBand(BBitmap* bitmap, BPoint* offset)
x = rc.left; x = rc.left;
y += rc.top; y += rc.top;
bool color = getJobData()->getColor() == JobData::kColor; bool color = GetJobData()->getColor() == JobData::kColor;
int width = rc.right - rc.left + 1; int width = rc.right - rc.left + 1;
int widthByte = (width + 7) / 8; int widthByte = (width + 7) / 8;
// byte boundary // byte boundary
@@ -281,19 +277,19 @@ PSDriver::nextBand(BBitmap* bitmap, BPoint* offset)
DBGMSG(("move\n")); DBGMSG(("move\n"));
int size = color ? width * 3 : in_size; int size = color ? width * 3 : in_size;
startRasterGraphics(x, y, width, height, size); _StartRasterGraphics(x, y, width, height, size);
for (int i = rc.top; i <= rc.bottom; i++) { for (int i = rc.top; i <= rc.bottom; i++) {
if (color) { if (color) {
uchar* out = out_buffer; uchar* out = out_buffer;
uchar* in = ptr; uchar* in = ptr;
for (int w = width; w > 0; w --) { for (int w = width; w > 0; w --) {
*out++ = hex_digit((in[2]) >> 4); *out++ = ToHexDigit((in[2]) >> 4);
*out++ = hex_digit((in[2]) & 15); *out++ = ToHexDigit((in[2]) & 15);
*out++ = hex_digit((in[1]) >> 4); *out++ = ToHexDigit((in[1]) >> 4);
*out++ = hex_digit((in[1]) & 15); *out++ = ToHexDigit((in[1]) & 15);
*out++ = hex_digit((in[0]) >> 4); *out++ = ToHexDigit((in[0]) >> 4);
*out++ = hex_digit((in[0]) & 15); *out++ = ToHexDigit((in[0]) & 15);
in += 4; in += 4;
} }
} else { } else {
@@ -304,8 +300,8 @@ PSDriver::nextBand(BBitmap* bitmap, BPoint* offset)
for (int w = in_size; w > 0; w --, in ++) { for (int w = in_size; w > 0; w --, in ++) {
*in = ~*in; // invert pixels *in = ~*in; // invert pixels
*out++ = hex_digit((*in) >> 4); *out++ = ToHexDigit((*in) >> 4);
*out++ = hex_digit((*in) & 15); *out++ = ToHexDigit((*in) & 15);
} }
} }
@@ -315,7 +311,7 @@ PSDriver::nextBand(BBitmap* bitmap, BPoint* offset)
compressed_size = out_size; compressed_size = out_size;
} }
rasterGraphics( _RasterGraphics(
compression_method, compression_method,
buffer, buffer,
compressed_size); compressed_size);
@@ -324,7 +320,7 @@ PSDriver::nextBand(BBitmap* bitmap, BPoint* offset)
y++; y++;
} }
endRasterGraphics(); _EndRasterGraphics();
} else } else
DBGMSG(("band bitmap is clean.\n")); DBGMSG(("band bitmap is clean.\n"));
@@ -347,79 +343,77 @@ PSDriver::nextBand(BBitmap* bitmap, BPoint* offset)
void void
PSDriver::jobStart() PSDriver::_JobStart()
{ {
// PostScript header // PostScript header
writePSString("%%!PS-Adobe-3.0\n"); _WritePSString("%%!PS-Adobe-3.0\n");
writePSString("%%%%LanguageLevel: 1\n"); _WritePSString("%%%%LanguageLevel: 1\n");
writePSString("%%%%Title: %s\n", _WritePSString("%%%%Title: %s\n",
getSpoolMetaData()->getDescription().c_str()); GetSpoolMetaData()->getDescription().c_str());
writePSString("%%%%Creator: %s\n", _WritePSString("%%%%Creator: %s\n",
getSpoolMetaData()->getMimeType().c_str()); GetSpoolMetaData()->getMimeType().c_str());
writePSString("%%%%CreationDate: %s", _WritePSString("%%%%CreationDate: %s",
getSpoolMetaData()->getCreationTime().c_str()); GetSpoolMetaData()->getCreationTime().c_str());
writePSString("%%%%DocumentMedia: Plain %d %d white 0 ( )\n", _WritePSString("%%%%DocumentMedia: Plain %d %d white 0 ( )\n",
getJobData()->getPaperRect().IntegerWidth(), GetJobData()->getPaperRect().IntegerWidth(),
getJobData()->getPaperRect().IntegerHeight()); GetJobData()->getPaperRect().IntegerHeight());
writePSString("%%%%Pages: (atend)\n"); _WritePSString("%%%%Pages: (atend)\n");
writePSString("%%%%EndComments\n"); _WritePSString("%%%%EndComments\n");
writePSString("%%%%BeginDefaults\n"); _WritePSString("%%%%BeginDefaults\n");
writePSString("%%%%PageMedia: Plain\n"); _WritePSString("%%%%PageMedia: Plain\n");
writePSString("%%%%EndDefaults\n"); _WritePSString("%%%%EndDefaults\n");
} }
void void
PSDriver::startRasterGraphics(int x, int y, int width, int height, PSDriver::_StartRasterGraphics(int x, int y, int width, int height,
int widthByte) int widthByte)
{ {
bool color = getJobData()->getColor() == JobData::kColor; bool color = GetJobData()->getColor() == JobData::kColor;
fCompressionMethod = -1; fCompressionMethod = -1;
writePSString("gsave\n"); _WritePSString("gsave\n");
writePSString("/s %d string def\n", widthByte); _WritePSString("/s %d string def\n", widthByte);
writePSString("%d %d translate\n", x, y); _WritePSString("%d %d translate\n", x, y);
writePSString("%d %d scale\n", width, height); _WritePSString("%d %d scale\n", width, height);
if (color) if (color)
writePSString("%d %d 8\n", width, height); // 8 bpp _WritePSString("%d %d 8\n", width, height); // 8 bpp
else else
writePSString("%d %d 1\n", width, height); // 1 bpp _WritePSString("%d %d 1\n", width, height); // 1 bpp
writePSString("[%d 0 0 %d 0 0]\n", width, height); _WritePSString("[%d 0 0 %d 0 0]\n", width, height);
writePSString("{ currentfile s readhexstring pop }\n"); _WritePSString("{ currentfile s readhexstring pop }\n");
if (color) { if (color) {
writePSString("false 3\n"); // single data source, 3 color components _WritePSString("false 3\n"); // single data source, 3 color components
writePSString("colorimage\n"); _WritePSString("colorimage\n");
} else } else
writePSString("image\n\n"); _WritePSString("image\n\n");
} }
void void
PSDriver::endRasterGraphics() PSDriver::_EndRasterGraphics()
{ {
writePSString("grestore\n"); _WritePSString("grestore\n");
} }
void void
PSDriver::rasterGraphics( PSDriver::_RasterGraphics(int compression_method, const uchar* buffer,
int compression_method,
const uchar* buffer,
int size) int size)
{ {
if (fCompressionMethod != compression_method) { if (fCompressionMethod != compression_method) {
fCompressionMethod = compression_method; fCompressionMethod = compression_method;
} }
writePSData(buffer, size); _WritePSData(buffer, size);
writePSString("\n"); _WritePSString("\n");
} }
void void
PSDriver::jobEnd() PSDriver::_JobEnd()
{ {
writePSString("%%%%Pages: %d\n", fPrintedPages); _WritePSString("%%%%Pages: %d\n", fPrintedPages);
writePSString("%%%%EOF\n"); _WritePSString("%%%%EOF\n");
FlushFilterIfNeeded(); _FlushFilterIfNeeded();
} }
+17 -17
View File
@@ -15,30 +15,30 @@ class Halftone;
class PSDriver : public GraphicsDriver { class PSDriver : public GraphicsDriver {
public: public:
PSDriver(BMessage* msg, PrinterData* printer_data, PSDriver(BMessage* message, PrinterData* printerData,
const PrinterCap* printer_cap); const PrinterCap* printerCap);
protected: protected:
virtual bool startDoc(); virtual bool StartDocument();
virtual bool startPage(int page); virtual bool StartPage(int page);
virtual bool nextBand(BBitmap* bitmap, BPoint* offset); virtual bool NextBand(BBitmap* bitmap, BPoint* offset);
virtual bool endPage(int page); virtual bool EndPage(int page);
virtual bool endDoc(bool success); virtual bool EndDocument(bool success);
private: private:
void setupCTM(); void _SetupCTM();
void jobStart(); void _JobStart();
void startRasterGraphics(int x, int y, int width, void _StartRasterGraphics(int x, int y, int width,
int height, int widthByte); int height, int widthByte);
void endRasterGraphics(); void _EndRasterGraphics();
void rasterGraphics(int compression_method, void _RasterGraphics(int compression_method,
const uchar* buffer, int size); const uchar* buffer, int size);
void jobEnd(); void _JobEnd();
void StartFilterIfNeeded(); void _StartFilterIfNeeded();
void FlushFilterIfNeeded(); void _FlushFilterIfNeeded();
void writePSString(const char* format, ...); void _WritePSString(const char* format, ...);
void writePSData(const void* data, size_t size); void _WritePSData(const void* data, size_t size);
int fPrintedPages; int fPrintedPages;
int fCompressionMethod; int fCompressionMethod;
+216 -146
View File
@@ -36,36 +36,53 @@ using namespace std;
// Measure printJob() time. Either true or false. // Measure printJob() time. Either true or false.
#define MEASURE_PRINT_JOB_TIME false #define MEASURE_PRINT_JOB_TIME false
enum { enum {
kMaxMemorySize = (4 *1024 *1024) kMaxMemorySize = 4 * 1024 * 1024
}; };
GraphicsDriver::GraphicsDriver(BMessage *msg, PrinterData *printer_data, const PrinterCap *printer_cap)
: fMsg(msg) GraphicsDriver::GraphicsDriver(BMessage* message, PrinterData* printerData,
, fPrinterData(printer_data) const PrinterCap* printerCap)
, fPrinterCap(printer_cap) :
fFlags(0),
fMessage(message),
fView(NULL),
fBitmap(NULL),
fTransport(NULL),
fOrgJobData(NULL),
fRealJobData(NULL),
fPrinterData(printerData),
fPrinterCap(printerCap),
fSpoolMetaData(NULL),
fPageWidth(0),
fPageHeight(0),
fBandWidth(0),
fBandHeight(0),
fPixelDepth(0),
fBandCount(0),
fInternalCopies(0),
fPageCount(0),
fStatusWindow(NULL)
{ {
fView = NULL;
fBitmap = NULL;
fTransport = NULL;
fOrgJobData = NULL;
fRealJobData = NULL;
fSpoolMetaData = NULL;
} }
GraphicsDriver::~GraphicsDriver() GraphicsDriver::~GraphicsDriver()
{ {
} }
static BRect RotateRect(BRect rect) static BRect
RotateRect(BRect rect)
{ {
BRect rotated(rect.top, rect.left, rect.bottom, rect.right); BRect rotated(rect.top, rect.left, rect.bottom, rect.right);
return rotated; return rotated;
} }
bool bool
GraphicsDriver::setupData(BFile *spoolFile) GraphicsDriver::_SetupData(BFile* spoolFile)
{ {
if (fOrgJobData != NULL) { if (fOrgJobData != NULL) {
// already initialized // already initialized
@@ -103,10 +120,15 @@ GraphicsDriver::setupData(BFile *spoolFile)
case 8: case 8:
case 32: case 32:
case 128: case 128:
fRealJobData->setPrintableRect(RotateRect(fOrgJobData->getPrintableRect())); fRealJobData->setPrintableRect(
fRealJobData->setScaledPrintableRect(RotateRect(fOrgJobData->getScaledPrintableRect())); RotateRect(fOrgJobData->getPrintableRect()));
fRealJobData->setPhysicalRect(RotateRect(fOrgJobData->getPhysicalRect())); fRealJobData->setScaledPrintableRect(
fRealJobData->setScaledPhysicalRect(RotateRect(fOrgJobData->getScaledPhysicalRect())); RotateRect(fOrgJobData->getScaledPrintableRect()));
fRealJobData->setPhysicalRect(
RotateRect(fOrgJobData->getPhysicalRect()));
fRealJobData->setScaledPhysicalRect(
RotateRect(fOrgJobData->getScaledPhysicalRect()));
if (JobData::kPortrait == fOrgJobData->getOrientation()) if (JobData::kPortrait == fOrgJobData->getOrientation())
fRealJobData->setOrientation(JobData::kLandscape); fRealJobData->setOrientation(JobData::kLandscape);
else else
@@ -125,8 +147,9 @@ GraphicsDriver::setupData(BFile *spoolFile)
return true; return true;
} }
void void
GraphicsDriver::cleanupData() GraphicsDriver::_CleanupData()
{ {
delete fRealJobData; delete fRealJobData;
delete fOrgJobData; delete fOrgJobData;
@@ -136,13 +159,16 @@ GraphicsDriver::cleanupData()
fSpoolMetaData = NULL; fSpoolMetaData = NULL;
} }
void void
GraphicsDriver::setupBitmap() GraphicsDriver::_SetupBitmap()
{ {
fPixelDepth = color_space2pixel_depth(fOrgJobData->getSurfaceType()); fPixelDepth = color_space2pixel_depth(fOrgJobData->getSurfaceType());
fPageWidth = (fRealJobData->getPhysicalRect().IntegerWidth() * fOrgJobData->getXres() + 71) / 72; fPageWidth = (fRealJobData->getPhysicalRect().IntegerWidth()
fPageHeight = (fRealJobData->getPhysicalRect().IntegerHeight() * fOrgJobData->getYres() + 71) / 72; * fOrgJobData->getXres() + 71) / 72;
fPageHeight = (fRealJobData->getPhysicalRect().IntegerHeight()
* fOrgJobData->getYres() + 71) / 72;
int widthByte = (fPageWidth * fPixelDepth + 7) / 8; int widthByte = (fPageWidth * fPixelDepth + 7) / 8;
int size = widthByte * fPageHeight; int size = widthByte * fPageHeight;
@@ -156,7 +182,8 @@ GraphicsDriver::setupBitmap()
fBandHeight = fPageHeight; fBandHeight = fPageHeight;
} else { } else {
fBandCount = (size + kMaxMemorySize - 1) / kMaxMemorySize; fBandCount = (size + kMaxMemorySize - 1) / kMaxMemorySize;
if ((JobData::kLandscape == fRealJobData->getOrientation()) && (fFlags & kGDFRotateBandBitmap)) { if ((JobData::kLandscape == fRealJobData->getOrientation())
&& (fFlags & kGDFRotateBandBitmap)) {
fBandWidth = (fPageWidth + fBandCount - 1) / fBandCount; fBandWidth = (fPageWidth + fBandCount - 1) / fBandCount;
fBandHeight = fPageHeight; fBandHeight = fPageHeight;
} else { } else {
@@ -179,16 +206,18 @@ GraphicsDriver::setupBitmap()
fBitmap->AddChild(fView); fBitmap->AddChild(fView);
} }
void void
GraphicsDriver::cleanupBitmap() GraphicsDriver::_CleanupBitmap()
{ {
delete fBitmap; delete fBitmap;
fBitmap = NULL; fBitmap = NULL;
fView = NULL; fView = NULL;
} }
BPoint BPoint
GraphicsDriver::getScale(int32 nup, BRect physicalRect, float scaling) GraphicsDriver::GetScale(int32 nup, BRect physicalRect, float scaling)
{ {
float width; float width;
float height; float height;
@@ -271,9 +300,11 @@ GraphicsDriver::getScale(int32 nup, BRect physicalRect, float scaling)
return scale; return scale;
} }
BPoint BPoint
GraphicsDriver::getOffset(int32 nup, int index, JobData::Orientation orientation, GraphicsDriver::GetOffset(int32 nup, int index,
const BPoint *scale, BRect scaledPhysicalRect, BRect scaledPrintableRect, JobData::Orientation orientation, const BPoint* scale,
BRect scaledPhysicalRect, BRect scaledPrintableRect,
BRect physicalRect) BRect physicalRect)
{ {
BPoint offset; BPoint offset;
@@ -368,9 +399,10 @@ GraphicsDriver::getOffset(int32 nup, int index, JobData::Orientation orientation
return offset; return offset;
} }
// print the specified pages on a physical page // print the specified pages on a physical page
bool bool
GraphicsDriver::printPage(PageDataList *pages) GraphicsDriver::_PrintPage(PageDataList* pages)
{ {
BPoint offset; BPoint offset;
offset.x = 0.0f; offset.x = 0.0f;
@@ -387,23 +419,34 @@ GraphicsDriver::printPage(PageDataList *pages)
fView->ConstrainClippingRegion(NULL); fView->ConstrainClippingRegion(NULL);
fView->FillRect(fView->Bounds()); fView->FillRect(fView->Bounds());
BPoint scale = getScale(fOrgJobData->getNup(), fOrgJobData->getPhysicalRect(), fOrgJobData->getScaling()); BPoint scale = GetScale(fOrgJobData->getNup(),
float real_scale = min(scale.x, scale.y) * fOrgJobData->getXres() / 72.0f; fOrgJobData->getPhysicalRect(), fOrgJobData->getScaling());
float real_scale = min(scale.x, scale.y) * fOrgJobData->getXres()
/ 72.0f;
fView->SetScale(real_scale); fView->SetScale(real_scale);
float x = offset.x / real_scale; float x = offset.x / real_scale;
float y = offset.y / real_scale; float y = offset.y / real_scale;
int page_index = 0; int page_index = 0;
for (PageDataList::iterator it = pages->begin(); it != pages->end(); it++) { for (PageDataList::iterator it = pages->begin(); it != pages->end();
BPoint left_top(getOffset(fOrgJobData->getNup(), page_index++, fOrgJobData->getOrientation(), &scale, fOrgJobData->getScaledPhysicalRect(), fOrgJobData->getScaledPrintableRect(), fOrgJobData->getPhysicalRect())); it++) {
BPoint left_top(GetOffset(fOrgJobData->getNup(), page_index++,
fOrgJobData->getOrientation(), &scale,
fOrgJobData->getScaledPhysicalRect(),
fOrgJobData->getScaledPrintableRect(),
fOrgJobData->getPhysicalRect()));
left_top.x -= x; left_top.x -= x;
left_top.y -= y; left_top.y -= y;
BRect clip(fOrgJobData->getScaledPrintableRect()); BRect clip(fOrgJobData->getScaledPrintableRect());
clip.OffsetTo(left_top); clip.OffsetTo(left_top);
BRegion *region = new BRegion(); BRegion *region = new BRegion();
region->Set(clip); region->Set(clip);
fView->ConstrainClippingRegion(region); fView->ConstrainClippingRegion(region);
delete region; delete region;
if ((*it)->startEnum()) { if ((*it)->startEnum()) {
bool more; bool more;
do { do {
@@ -416,39 +459,42 @@ GraphicsDriver::printPage(PageDataList *pages)
} while (more); } while (more);
} }
} }
if (!nextBand(fBitmap, &offset)) {
if (!NextBand(fBitmap, &offset))
return false; return false;
}
} while (offset.x >= 0.0f && offset.y >= 0.0f); } while (offset.x >= 0.0f && offset.y >= 0.0f);
return true; return true;
} }
bool bool
GraphicsDriver::collectPages(SpoolData *spool_data, PageDataList *pages) GraphicsDriver::_CollectPages(SpoolData* spoolData, PageDataList* pages)
{ {
// collect the pages to be printed on the physical page // collect the pages to be printed on the physical page
PageData *page_data; PageData *page_data;
int nup = fOrgJobData->getNup(); int nup = fOrgJobData->getNup();
bool more; bool more;
do { do {
more = spool_data->enumObject(&page_data); more = spoolData->enumObject(&page_data);
if (pages != NULL) { if (pages != NULL)
pages->push_back(page_data); pages->push_back(page_data);
}
} while (more && --nup); } while (more && --nup);
return more; return more;
} }
bool
GraphicsDriver::skipPages(SpoolData *spool_data)
{
return collectPages(spool_data, NULL);
}
bool bool
GraphicsDriver::printDocument(SpoolData *spool_data) GraphicsDriver::_SkipPages(SpoolData* spoolData)
{
return _CollectPages(spoolData, NULL);
}
bool
GraphicsDriver::_PrintDocument(SpoolData* spoolData)
{ {
bool more; bool more;
bool success; bool success;
@@ -460,41 +506,41 @@ GraphicsDriver::printDocument(SpoolData *spool_data)
success = true; success = true;
page_index = 0; page_index = 0;
if (fPrinterCap->isSupport(PrinterCap::kCopyCommand)) { if (fPrinterCap->isSupport(PrinterCap::kCopyCommand))
// let the printer perform the copy operation // let the printer perform the copy operation
copies = 1; copies = 1;
} else { else
// send the page multiple times to the printer // send the page multiple times to the printer
copies = fRealJobData->getCopies(); copies = fRealJobData->getCopies();
}
fStatusWindow -> SetPageCopies(copies); // inform fStatusWindow about number of copies fStatusWindow -> SetPageCopies(copies);
// inform fStatusWindow about number of copies
// printing of even/odd numbered pages only is valid in simplex mode // printing of even/odd numbered pages only is valid in simplex mode
bool simplex = fRealJobData->getPrintStyle() == JobData::kSimplex; bool simplex = fRealJobData->getPrintStyle() == JobData::kSimplex;
if (spool_data->startEnum()) { if (spoolData->startEnum()) {
do { do {
DBGMSG(("page index = %d\n", page_index)); DBGMSG(("page index = %d\n", page_index));
if (simplex && if (simplex
fRealJobData->getPageSelection() == JobData::kEvenNumberedPages) { && fRealJobData->getPageSelection()
== JobData::kEvenNumberedPages)
// skip odd numbered page // skip odd numbered page
more = skipPages(spool_data); more = _SkipPages(spoolData);
}
if (!more) { if (!more)
// end reached // end reached
break; break;
}
PageDataList pages; PageDataList pages;
more = collectPages(spool_data, &pages); more = _CollectPages(spoolData, &pages);
if (more && simplex && if (more && simplex
fRealJobData->getPageSelection() == JobData::kOddNumberedPages) { && fRealJobData->getPageSelection()
== JobData::kOddNumberedPages)
// skip even numbered page // skip even numbered page
more = skipPages(spool_data); more = _SkipPages(spoolData);
}
// print each physical page "copies" of times // print each physical page "copies" of times
for (copy = 0; success && copy < copies; copy ++) { for (copy = 0; success && copy < copies; copy ++) {
@@ -503,17 +549,17 @@ GraphicsDriver::printDocument(SpoolData *spool_data)
if (fStatusWindow->UpdateStatusBar(page_index, copy)) if (fStatusWindow->UpdateStatusBar(page_index, copy))
return false; return false;
success = startPage(page_index); success = StartPage(page_index);
if (!success) if (!success)
break; break;
// print the pages on the physical page // print the pages on the physical page
fView->Window()->Lock(); fView->Window()->Lock();
success = printPage(&pages); success = _PrintPage(&pages);
fView->Window()->Unlock(); fView->Window()->Unlock();
if (success) { if (success) {
success = endPage(page_index); success = EndPage(page_index);
} }
} }
@@ -525,31 +571,34 @@ GraphicsDriver::printDocument(SpoolData *spool_data)
if (success if (success
&& fPrinterCap->isSupport(PrinterCap::kPrintStyle) && fPrinterCap->isSupport(PrinterCap::kPrintStyle)
&& (fOrgJobData->getPrintStyle() != JobData::kSimplex) && (fOrgJobData->getPrintStyle() != JobData::kSimplex)
&& (((page_index + fOrgJobData->getNup() - 1) / fOrgJobData->getNup()) % 2)) && (((page_index + fOrgJobData->getNup() - 1) / fOrgJobData->getNup())
{ % 2)) {
// append an empty page on the back side of the page in duplex or booklet mode // append an empty page on the back side of the page in duplex or
// booklet mode
success = success =
startPage(page_index) && StartPage(page_index) &&
printPage(NULL) && _PrintPage(NULL) &&
endPage(page_index); EndPage(page_index);
} }
#endif #endif
return success; return success;
} }
const JobData* const JobData*
GraphicsDriver::getJobData(BFile *spoolFile) GraphicsDriver::GetJobData(BFile* spoolFile)
{ {
setupData(spoolFile); _SetupData(spoolFile);
return fOrgJobData; return fOrgJobData;
} }
bool bool
GraphicsDriver::printJob(BFile *spoolFile) GraphicsDriver::PrintJob(BFile* spoolFile)
{ {
bool success = true; bool success = true;
if (!setupData(spoolFile)) { if (!_SetupData(spoolFile)) {
// silently exit if there is nothing to print // silently exit if there is nothing to print
return true; return true;
} }
@@ -560,9 +609,10 @@ GraphicsDriver::printJob(BFile *spoolFile)
success = false; success = false;
} else if (!fTransport->is_print_to_file_canceled()) { } else if (!fTransport->is_print_to_file_canceled()) {
BStopWatch stopWatch("printJob", !MEASURE_PRINT_JOB_TIME); BStopWatch stopWatch("printJob", !MEASURE_PRINT_JOB_TIME);
setupBitmap(); _SetupBitmap();
SpoolData spool_data(spoolFile, fPageCount, fOrgJobData->getNup(), fOrgJobData->getReverse()); SpoolData spoolData(spoolFile, fPageCount, fOrgJobData->getNup(),
success = startDoc(); fOrgJobData->getReverse());
success = StartDocument();
if (success) { if (success) {
fStatusWindow = new StatusWindow( fStatusWindow = new StatusWindow(
fRealJobData->getPageSelection() == JobData::kOddNumberedPages, fRealJobData->getPageSelection() == JobData::kOddNumberedPages,
@@ -572,27 +622,26 @@ GraphicsDriver::printJob(BFile *spoolFile)
fInternalCopies,fRealJobData->getNup()); fInternalCopies,fRealJobData->getNup());
while (fInternalCopies--) { while (fInternalCopies--) {
success = printDocument(&spool_data); success = _PrintDocument(&spoolData);
if (success == false) { if (success == false) {
break; break;
} }
} }
endDoc(success); EndDocument(success);
fStatusWindow->Lock(); fStatusWindow->Lock();
fStatusWindow->Quit(); fStatusWindow->Quit();
} }
cleanupBitmap(); _CleanupBitmap();
cleanupData(); _CleanupData();
} }
if (success == false) { if (success == false) {
BAlert *alert; BAlert *alert;
if (fTransport->check_abort()) { if (fTransport->check_abort())
alert = new BAlert("", fTransport->last_error().c_str(), "OK"); alert = new BAlert("", fTransport->last_error().c_str(), "OK");
} else { else
alert = new BAlert("", "Printer not responding.", "OK"); alert = new BAlert("", "Printer not responding.", "OK");
}
alert->Go(); alert->Go();
} }
@@ -602,83 +651,97 @@ GraphicsDriver::printJob(BFile *spoolFile)
return success; return success;
} }
BMessage *
GraphicsDriver::takeJob(BFile* spoolFile, uint32 flags) BMessage*
GraphicsDriver::TakeJob(BFile* spoolFile, uint32 flags)
{ {
fFlags = flags; fFlags = flags;
BMessage *msg; BMessage *msg;
if (printJob(spoolFile)) { if (PrintJob(spoolFile))
msg = new BMessage('okok'); msg = new BMessage('okok');
} else { else
msg = new BMessage('baad'); msg = new BMessage('baad');
}
return msg; return msg;
} }
bool bool
GraphicsDriver::startDoc() GraphicsDriver::StartDocument()
{ {
return true; return true;
} }
bool bool
GraphicsDriver::startPage(int) GraphicsDriver::StartPage(int)
{ {
return true; return true;
} }
bool bool
GraphicsDriver::nextBand(BBitmap *, BPoint *) GraphicsDriver::NextBand(BBitmap*, BPoint*)
{ {
return true; return true;
} }
bool bool
GraphicsDriver::endPage(int) GraphicsDriver::EndPage(int)
{ {
return true; return true;
} }
bool bool
GraphicsDriver::endDoc(bool) GraphicsDriver::EndDocument(bool)
{ {
return true; return true;
} }
void
GraphicsDriver::writeSpoolData(const void *buffer, size_t size) throw(TransportException)
{
if (fTransport) {
fTransport->write(buffer, size);
}
}
void
GraphicsDriver::writeSpoolString(const char *format, ...) throw(TransportException)
{
if (fTransport) {
char buffer[256];
va_list ap;
va_start(ap, format);
vsprintf(buffer, format, ap);
fTransport->write(buffer, strlen(buffer));
va_end(ap);
}
}
void
GraphicsDriver::writeSpoolChar(char c) throw(TransportException)
{
if (fTransport) {
fTransport->write(&c, 1);
}
}
void void
GraphicsDriver::rgb32_to_rgb24(void* src, void* dst, int width) { GraphicsDriver::WriteSpoolData(const void* buffer, size_t size)
throw (TransportException)
{
if (fTransport == NULL)
return
fTransport->write(buffer, size);
}
void
GraphicsDriver::WriteSpoolString(const char* format, ...)
throw (TransportException)
{
if (fTransport == NULL)
return;
char buffer[256];
va_list ap;
va_start(ap, format);
vsprintf(buffer, format, ap);
fTransport->write(buffer, strlen(buffer));
va_end(ap);
}
void
GraphicsDriver::WriteSpoolChar(char c)
throw (TransportException)
{
if (fTransport == NULL)
return;
fTransport->write(&c, 1);
}
void
GraphicsDriver::_ConvertRGB32ToRGB24(const void* src, void* dst, int width) {
uint8* d = (uint8*)dst; uint8* d = (uint8*)dst;
rgb_color* s = (rgb_color*)src; const rgb_color* s = static_cast<const rgb_color*>(src);
for (int i = width; i > 0; i --) { for (int i = width; i > 0; i --) {
*d ++ = s->red; *d ++ = s->red;
*d ++ = s->green; *d ++ = s->green;
@@ -687,10 +750,11 @@ GraphicsDriver::rgb32_to_rgb24(void* src, void* dst, int width) {
} }
} }
void void
GraphicsDriver::cmap8_to_rgb24(void* src, void* dst, int width) { GraphicsDriver::_ConvertCMAP8ToRGB24(const void* src, void* dst, int width) {
uint8* d = (uint8*)dst; uint8* d = (uint8*)dst;
uint8* s = (uint8*)src; const uint8* s = static_cast<const uint8*>(src);
const color_map* cmap = system_colors(); const color_map* cmap = system_colors();
for (int i = width; i > 0; i --) { for (int i = width; i > 0; i --) {
const rgb_color* rgb = &cmap->color_list[*s]; const rgb_color* rgb = &cmap->color_list[*s];
@@ -701,51 +765,57 @@ GraphicsDriver::cmap8_to_rgb24(void* src, void* dst, int width) {
} }
} }
void void
GraphicsDriver::convert_to_rgb24(void* src, void* dst, int width, color_space cs) { GraphicsDriver::ConvertToRGB24(const void* src, void* dst, int width,
if (cs == B_RGB32) rgb32_to_rgb24(src, dst, width); color_space cs) {
else if (cs == B_CMAP8) cmap8_to_rgb24(src, dst, width); if (cs == B_RGB32)
_ConvertRGB32ToRGB24(src, dst, width);
else if (cs == B_CMAP8)
_ConvertCMAP8ToRGB24(src, dst, width);
else { else {
DBGMSG(("color_space %d not supported", cs)); DBGMSG(("color_space %d not supported", cs));
} }
} }
uint8 uint8
GraphicsDriver::gray(uint8 r, uint8 g, uint8 b) { GraphicsDriver::_ConvertToGray(uint8 r, uint8 g, uint8 b) {
if (r == g && g == b) { if (r == g && g == b)
return r; return r;
} else { else
return (r * 3 + g * 6 + b) / 10; return (r * 3 + g * 6 + b) / 10;
}
} }
void void
GraphicsDriver::rgb32_to_gray(void* src, void* dst, int width) { GraphicsDriver::_ConvertRGB32ToGray(const void* src, void* dst, int width) {
uint8* d = (uint8*)dst; uint8* d = (uint8*)dst;
rgb_color* s = (rgb_color*)src; const rgb_color* s = static_cast<const rgb_color*>(src);
for (int i = width; i > 0; i --) { for (int i = width; i > 0; i--, s++, d++)
*d ++ = gray(s->red, s->green, s->blue); *d = _ConvertToGray(s->red, s->green, s->blue);
s++;
}
} }
void void
GraphicsDriver::cmap8_to_gray(void* src, void* dst, int width) { GraphicsDriver::_ConvertCMAP8ToGray(const void* src, void* dst, int width) {
uint8* d = (uint8*)dst; uint8* d = (uint8*)dst;
uint8* s = (uint8*)src; const uint8* s = static_cast<const uint8*>(src);
const color_map* cmap = system_colors(); const color_map* cmap = system_colors();
for (int i = width; i > 0; i --) { for (int i = width; i > 0; i--, s++, d++) {
const rgb_color* rgb = &cmap->color_list[*s]; const rgb_color* rgb = &cmap->color_list[*s];
*d ++ = gray(rgb->red, rgb->green, rgb->blue); *d = _ConvertToGray(rgb->red, rgb->green, rgb->blue);
s ++;
} }
} }
void void
GraphicsDriver::convert_to_gray(void* src, void* dst, int width, color_space cs) { GraphicsDriver::ConvertToGray(const void* src, void* dst, int width,
if (cs == B_RGB32) rgb32_to_gray(src, dst, width); color_space cs) {
else if (cs == B_CMAP8) cmap8_to_gray(src, dst, width); if (cs == B_RGB32)
_ConvertRGB32ToGray(src, dst, width);
else if (cs == B_CMAP8)
_ConvertCMAP8ToGray(src, dst, width);
else { else {
DBGMSG(("color_space %d not supported", cs)); DBGMSG(("color_space %d not supported", cs));
} }
+1 -1
View File
@@ -680,7 +680,7 @@ void PreviewView::_DrawPage(BRect rect)
} }
printRect.OffsetBy(_ContentRect().LeftTop()); printRect.OffsetBy(_ContentRect().LeftTop());
BPoint scalingXY = GraphicsDriver::getScale(fNumberOfPagesPerPage, printRect, 100.0); BPoint scalingXY = GraphicsDriver::GetScale(fNumberOfPagesPerPage, printRect, 100.0);
float scaling = min_c(scalingXY.x, scalingXY.y); float scaling = min_c(scalingXY.x, scalingXY.y);
printRect = ScaleDown(printRect, _ZoomFactor() * scaling); printRect = ScaleDown(printRect, _ZoomFactor() * scaling);
+7 -6
View File
@@ -30,10 +30,11 @@
// Implementation of PrinterDriver // Implementation of PrinterDriver
PrinterDriver::PrinterDriver(BNode* spoolFolder) PrinterDriver::PrinterDriver(BNode* spoolFolder)
: fSpoolFolder(spoolFolder) :
, fPrinterData(NULL) fSpoolFolder(spoolFolder),
, fPrinterCap(NULL) fPrinterData(NULL),
, fGraphicsDriver(NULL) fPrinterCap(NULL),
fGraphicsDriver(NULL)
{ {
} }
@@ -152,7 +153,7 @@ PrinterDriver::TakeJob(BFile* printJob, BMessage* settings)
DUMP_BNODE(fSpoolFolder); DUMP_BNODE(fSpoolFolder);
fGraphicsDriver = InstantiateGraphicsDriver(settings, fPrinterData, fPrinterCap); fGraphicsDriver = InstantiateGraphicsDriver(settings, fPrinterData, fPrinterCap);
const JobData* jobData = fGraphicsDriver->getJobData(printJob); const JobData* jobData = fGraphicsDriver->GetJobData(printJob);
if (jobData != NULL && jobData->getShowPreview()) { if (jobData != NULL && jobData->getShowPreview()) {
off_t offset = printJob->Position(); off_t offset = printJob->Position();
PreviewWindow *preview = new PreviewWindow(printJob, true); PreviewWindow *preview = new PreviewWindow(printJob, true);
@@ -161,7 +162,7 @@ PrinterDriver::TakeJob(BFile* printJob, BMessage* settings)
} }
printJob->Seek(offset, SEEK_SET); printJob->Seek(offset, SEEK_SET);
} }
BMessage *result = fGraphicsDriver->takeJob(printJob); BMessage *result = fGraphicsDriver->TakeJob(printJob);
DUMP_BMESSAGE(result); DUMP_BMESSAGE(result);
DBGMSG(("<%s: take_job\n", GetDriverName())); DBGMSG(("<%s: take_job\n", GetDriverName()));