diff --git a/src/add-ons/print/drivers/canon_lips/lips3/Compress3.cpp b/src/add-ons/print/drivers/canon_lips/lips3/Compress3.cpp index 50cbfce004..a171b808dc 100644 --- a/src/add-ons/print/drivers/canon_lips/lips3/Compress3.cpp +++ b/src/add-ons/print/drivers/canon_lips/lips3/Compress3.cpp @@ -3,7 +3,8 @@ * Copyright 1999-2000 Y.Takagi. All Rights Reserved. */ -//#define DBG_CON_STREAM + +// #define DBG_CON_STREAM #ifdef DBG_CON_STREAM #include @@ -14,15 +15,17 @@ using namespace std; #define PACK_TYPE 2 -int compress3(unsigned char *pOut, unsigned char *pIn, int n) + +int +compress3(unsigned char* pOut, unsigned char* pIn, int n) { int count; int count_byte; - unsigned char *pBase; - unsigned char *pLast; + unsigned char* pBase; + unsigned char* pLast; unsigned char keep; - count = 0; + count = 0; count_byte = 0; keep = ~(*pIn); @@ -56,32 +59,32 @@ int compress3(unsigned char *pOut, unsigned char *pIn, int n) *pOut++ = keep; *pOut++ = count - PACK_TYPE; count_byte += 2; - } else { + } else count_byte = n; - } } return count_byte; } + #ifdef DBG_CON_STREAM -int main(int argc, char **argv) + +int +main(int argc, char **argv) { - if (argc < 2) { + if (argc < 2) return -1; - } ifstream ifs(*++argv, ios::binary | ios::nocreate); - if (!ifs) { + if (!ifs) return -1; - } ifs.seekg(0, ios::end); long size = ifs.tellg(); ifs.seekg(0, ios::beg); - unsigned char *pIn = new unsigned char[size]; - unsigned char *pOut = new unsigned char[size * 3]; + unsigned char* pIn = new unsigned char[size]; + unsigned char* pOut = new unsigned char[size * 3]; ifs.read(pIn, size); @@ -94,4 +97,5 @@ int main(int argc, char **argv) delete [] pOut; } + #endif diff --git a/src/add-ons/print/drivers/canon_lips/lips3/Compress3.h b/src/add-ons/print/drivers/canon_lips/lips3/Compress3.h index 64a9b79352..326bfb690e 100644 --- a/src/add-ons/print/drivers/canon_lips/lips3/Compress3.h +++ b/src/add-ons/print/drivers/canon_lips/lips3/Compress3.h @@ -2,10 +2,11 @@ * Compress3.h * Copyright 1999-2000 Y.Takagi. All Rights Reserved. */ - #ifndef __COMPRESS3_H #define __COMPRESS3_H -int compress3(unsigned char *out, unsigned char *in, int bytes); -#endif /* __COMPRESS3_H */ +int compress3(unsigned char* out, unsigned char* in, int bytes); + + +#endif /* __COMPRESS3_H */ diff --git a/src/add-ons/print/drivers/canon_lips/lips3/Lips3.cpp b/src/add-ons/print/drivers/canon_lips/lips3/Lips3.cpp index 0b43d29808..26b5e26aec 100644 --- a/src/add-ons/print/drivers/canon_lips/lips3/Lips3.cpp +++ b/src/add-ons/print/drivers/canon_lips/lips3/Lips3.cpp @@ -3,19 +3,24 @@ * Copyright 1999-2000 Y.Takagi. All Rights Reserved. */ + +#include "Lips3.h" + +#include + #include #include #include -#include -#include "Lips3.h" -#include "UIDriver.h" + #include "Compress3.h" -#include "JobData.h" -#include "PrinterData.h" -#include "Lips3Cap.h" -#include "Halftone.h" -#include "ValidRect.h" #include "DbgMsg.h" +#include "Halftone.h" +#include "JobData.h" +#include "Lips3Cap.h" +#include "PrinterData.h" +#include "UIDriver.h" +#include "ValidRect.h" + #if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE)) using namespace std; @@ -23,13 +28,18 @@ using namespace std; #define std #endif -LIPS3Driver::LIPS3Driver(BMessage *msg, PrinterData *printer_data, const PrinterCap *printer_cap) - : GraphicsDriver(msg, printer_data, printer_cap) + +LIPS3Driver::LIPS3Driver(BMessage *msg, PrinterData *printer_data, + const PrinterCap *printer_cap) + : + GraphicsDriver(msg, printer_data, printer_cap) { fHalftone = NULL; } -bool LIPS3Driver::startDoc() + +bool +LIPS3Driver::startDoc() { try { beginTextMode(); @@ -41,15 +51,19 @@ bool LIPS3Driver::startDoc() paperFeedMode(); disableAutoFF(); setNumberOfCopies(); - fHalftone = new Halftone(getJobData()->getSurfaceType(), getJobData()->getGamma(), getJobData()->getInkDensity(), getJobData()->getDitherType()); + fHalftone = new Halftone(getJobData()->getSurfaceType(), + getJobData()->getGamma(), getJobData()->getInkDensity(), + getJobData()->getDitherType()); return true; } - catch (TransportException &err) { + catch (TransportException& err) { return false; } } -bool LIPS3Driver::startPage(int) + +bool +LIPS3Driver::startPage(int) { try { fCurrentX = 0; @@ -57,23 +71,27 @@ bool LIPS3Driver::startPage(int) memorizedPosition(); return true; } - catch (TransportException &err) { + catch (TransportException& err) { return false; } } -bool LIPS3Driver::endPage(int) + +bool +LIPS3Driver::endPage(int) { try { formFeed(); return true; } - catch (TransportException &err) { + catch (TransportException& err) { return false; } } -bool LIPS3Driver::endDoc(bool) + +bool +LIPS3Driver::endDoc(bool) { try { if (fHalftone) { @@ -82,12 +100,14 @@ bool LIPS3Driver::endDoc(bool) jobEnd(); return true; } - catch (TransportException &err) { + catch (TransportException& err) { return false; } } -bool LIPS3Driver::nextBand(BBitmap *bitmap, BPoint *offset) + +bool +LIPS3Driver::nextBand(BBitmap* bitmap, BPoint* offset) { DBGMSG(("> nextBand\n")); @@ -95,9 +115,9 @@ bool LIPS3Driver::nextBand(BBitmap *bitmap, BPoint *offset) BRect bounds = bitmap->Bounds(); RECT rc; - rc.left = (int)bounds.left; - rc.top = (int)bounds.top; - rc.right = (int)bounds.right; + rc.left = (int)bounds.left; + rc.top = (int)bounds.top; + rc.right = (int)bounds.right; rc.bottom = (int)bounds.bottom; int height = rc.bottom - rc.top + 1; @@ -107,9 +127,8 @@ bool LIPS3Driver::nextBand(BBitmap *bitmap, BPoint *offset) int page_height = getPageHeight(); - if (y + height > page_height) { + if (y + height > page_height) height = page_height - y; - } rc.bottom = height - 1; @@ -126,11 +145,12 @@ bool LIPS3Driver::nextBand(BBitmap *bitmap, BPoint *offset) y += rc.top; int width = rc.right - rc.left + 1; - int widthByte = (width + 7) / 8; /* byte boundary */ - int height = rc.bottom - rc.top + 1; - int in_size = widthByte * height; - int out_size = (in_size * 6 + 4) / 5; - int delta = bitmap->BytesPerRow(); + int widthByte = (width + 7) / 8; + // byte boundary + int height = rc.bottom - rc.top + 1; + int in_size = widthByte * height; + int out_size = (in_size * 6 + 4) / 5; + int delta = bitmap->BytesPerRow(); DBGMSG(("width = %d\n", width)); DBGMSG(("widthByte = %d\n", widthByte)); @@ -138,23 +158,24 @@ bool LIPS3Driver::nextBand(BBitmap *bitmap, BPoint *offset) DBGMSG(("in_size = %d\n", in_size)); DBGMSG(("out_size = %d\n", out_size)); DBGMSG(("delta = %d\n", delta)); - DBGMSG(("renderobj->get_pixel_depth() = %d\n", fHalftone->getPixelDepth())); + DBGMSG(("renderobj->get_pixel_depth() = %d\n", + fHalftone->getPixelDepth())); - uchar *ptr = (uchar *)bitmap->Bits() + uchar* ptr = static_cast(bitmap->Bits()) + rc.top * delta + (rc.left * fHalftone->getPixelDepth()) / 8; int compression_method; int compressed_size; - const uchar *buffer; + const uchar* buffer; - uchar *in_buffer = new uchar[in_size]; - uchar *out_buffer = new uchar[out_size]; + uchar* in_buffer = new uchar[in_size]; + uchar* out_buffer = new uchar[out_size]; auto_ptr _in_buffer (in_buffer); auto_ptr _out_buffer(out_buffer); - uchar *ptr2 = (uchar *)in_buffer; + uchar* ptr2 = static_cast(in_buffer); DBGMSG(("move\n")); @@ -170,10 +191,12 @@ bool LIPS3Driver::nextBand(BBitmap *bitmap, BPoint *offset) compressed_size = compress3(out_buffer, in_buffer, in_size); if (compressed_size < in_size) { - compression_method = 9; /* compress3 */ + compression_method = 9; + // compress3 buffer = out_buffer; } else if (compressed_size > out_size) { - BAlert *alert = new BAlert("memory overrun!!!", "warning", "OK"); + BAlert* alert = new BAlert("memory overrun!!!", "warning", + "OK"); alert->Go(); return false; } else { @@ -194,53 +217,63 @@ bool LIPS3Driver::nextBand(BBitmap *bitmap, BPoint *offset) compression_method, buffer); - } else { + } else DBGMSG(("band bitmap is clean.\n")); - } if (y >= page_height) { offset->x = -1.0; offset->y = -1.0; - } else { + } else offset->y += height; - } DBGMSG(("< nextBand\n")); return true; } - catch (TransportException &err) { - BAlert *alert = new BAlert("", err.what(), "OK"); + catch (TransportException& err) { + BAlert* alert = new BAlert("", err.what(), "OK"); alert->Go(); return false; } } -void LIPS3Driver::beginTextMode() + +void +LIPS3Driver::beginTextMode() { writeSpoolString("\033%%@"); } -void LIPS3Driver::jobStart() + +void +LIPS3Driver::jobStart() { writeSpoolString("\033P31;300;1J\033\\"); } -void LIPS3Driver::softReset() + +void +LIPS3Driver::softReset() { writeSpoolString("\033<"); } -void LIPS3Driver::sizeUnitMode() + +void +LIPS3Driver::sizeUnitMode() { writeSpoolString("\033[11h"); } -void LIPS3Driver::selectSizeUnit() + +void +LIPS3Driver::selectSizeUnit() { writeSpoolString("\033[7 I"); } -void LIPS3Driver::selectPageFormat() + +void +LIPS3Driver::selectPageFormat() { int i; int width = 0; @@ -301,14 +334,15 @@ void LIPS3Driver::selectPageFormat() if (JobData::kLandscape == getJobData()->getOrientation()) i++; - if (i < 80) { + if (i < 80) writeSpoolString("\033[%d;;p", i); - } else { + else writeSpoolString("\033[%d;%d;%dp", i, height, width); - } } -void LIPS3Driver::paperFeedMode() + +void +LIPS3Driver::paperFeedMode() { // 0 auto // -------------- @@ -328,92 +362,103 @@ void LIPS3Driver::paperFeedMode() int i; switch (getJobData()->getPaperSource()) { - case JobData::kManual: - i = 1; - break; - case JobData::kLower: - i = 2; - break; - case JobData::kUpper: - i = 3; - break; - case JobData::kAuto: - default: - i = 0; - break; + case JobData::kManual: + i = 1; + break; + case JobData::kLower: + i = 2; + break; + case JobData::kUpper: + i = 3; + break; + case JobData::kAuto: + default: + i = 0; + break; } writeSpoolString("\033[%dq", i); } -void LIPS3Driver::disableAutoFF() + +void +LIPS3Driver::disableAutoFF() { writeSpoolString("\033[?2h"); } -void LIPS3Driver::setNumberOfCopies() + +void +LIPS3Driver::setNumberOfCopies() { writeSpoolString("\033[%ldv", getJobData()->getCopies()); } -void LIPS3Driver::memorizedPosition() + +void +LIPS3Driver::memorizedPosition() { writeSpoolString("\033[0;1;0x"); } -void LIPS3Driver::moveAbsoluteHorizontal(int x) + +void +LIPS3Driver::moveAbsoluteHorizontal(int x) { writeSpoolString("\033[%d`", x); } -void LIPS3Driver::carriageReturn() + +void +LIPS3Driver::carriageReturn() { writeSpoolChar('\x0d'); } -void LIPS3Driver::moveDown(int dy) + +void +LIPS3Driver::moveDown(int dy) { writeSpoolString("\033[%de", dy); } -void LIPS3Driver::rasterGraphics( - int compression_size, - int widthbyte, - int height, - int compression_method, - const uchar *buffer) + +void +LIPS3Driver::rasterGraphics( int compression_size, int widthbyte, int height, + int compression_method, const uchar *buffer) { // 0 RAW // 9 compress-3 - writeSpoolString( - "\033[%d;%d;%d;%d;%d.r", - compression_size, - widthbyte, - getJobData()->getXres(), - compression_method, - height); + writeSpoolString("\033[%d;%d;%d;%d;%d.r", compression_size, widthbyte, + getJobData()->getXres(), compression_method, height); writeSpoolData(buffer, compression_size); } -void LIPS3Driver::formFeed() + +void +LIPS3Driver::formFeed() { writeSpoolChar('\014'); } -void LIPS3Driver::jobEnd() + +void +LIPS3Driver::jobEnd() { writeSpoolString("\033P0J\033\\"); } -void LIPS3Driver::move(int x, int y) + +void +LIPS3Driver::move(int x, int y) { if (fCurrentX != x) { - if (x) { + if (x) moveAbsoluteHorizontal(x); - } else { + else carriageReturn(); - } + fCurrentX = x; } if (fCurrentY != y) { diff --git a/src/add-ons/print/drivers/canon_lips/lips3/Lips3.h b/src/add-ons/print/drivers/canon_lips/lips3/Lips3.h index 5f7e0a6e88..521ea8a853 100644 --- a/src/add-ons/print/drivers/canon_lips/lips3/Lips3.h +++ b/src/add-ons/print/drivers/canon_lips/lips3/Lips3.h @@ -2,52 +2,55 @@ * Lips3.h * Copyright 1999-2000 Y.Takagi. All Rights Reserved. */ - #ifndef __LIPS3_H #define __LIPS3_H + #include "GraphicsDriver.h" + class Halftone; + class LIPS3Driver : public GraphicsDriver { public: - LIPS3Driver(BMessage *msg, PrinterData *printer_data, const PrinterCap *printer_cap); + LIPS3Driver(BMessage* msg, PrinterData* printer_data, + const PrinterCap* printer_cap); protected: - virtual bool startDoc(); - virtual bool startPage(int page); - virtual bool nextBand(BBitmap *bitmap, BPoint *offset); - virtual bool endPage(int page); - virtual bool endDoc(bool success); + virtual bool startDoc(); + virtual bool startPage(int page); + virtual bool nextBand(BBitmap *bitmap, BPoint *offset); + virtual bool endPage(int page); + virtual bool endDoc(bool success); private: - void move(int x, int y); - void beginTextMode(); - void jobStart(); - void softReset(); - void sizeUnitMode(); - void selectSizeUnit(); - void paperFeedMode(); - void selectPageFormat(); - void disableAutoFF(); - void setNumberOfCopies(); - void memorizedPosition(); - void moveAbsoluteHorizontal(int x); - void carriageReturn(); - void moveDown(int dy); - void rasterGraphics( - int size, - int widthbyte, - int height, - int compression_method, - const uchar *buffer); - void formFeed(); - void jobEnd(); + void move(int x, int y); + void beginTextMode(); + void jobStart(); + void softReset(); + void sizeUnitMode(); + void selectSizeUnit(); + void paperFeedMode(); + void selectPageFormat(); + void disableAutoFF(); + void setNumberOfCopies(); + void memorizedPosition(); + void moveAbsoluteHorizontal(int x); + void carriageReturn(); + void moveDown(int dy); + void rasterGraphics( + int size, + int widthbyte, + int height, + int compression_method, + const uchar* buffer); + void formFeed(); + void jobEnd(); - int fCurrentX; - int fCurrentY; - Halftone *fHalftone; + int fCurrentX; + int fCurrentY; + Halftone* fHalftone; }; -#endif /* __LIPS3_H */ +#endif // __LIPS3_H diff --git a/src/add-ons/print/drivers/canon_lips/lips3/Lips3Cap.cpp b/src/add-ons/print/drivers/canon_lips/lips3/Lips3Cap.cpp index ef51dc1b9a..d0967b7b09 100644 --- a/src/add-ons/print/drivers/canon_lips/lips3/Lips3Cap.cpp +++ b/src/add-ons/print/drivers/canon_lips/lips3/Lips3Cap.cpp @@ -3,11 +3,13 @@ * Copyright 1999-2000 Y.Takagi. All Rights Reserved. */ -#include "PrinterData.h" #include "Lips3Cap.h" +#include "PrinterData.h" + #define TO72DPI(a) (a * 72.0f / 600.0f) + const PaperCap a3( "A3", false, @@ -71,7 +73,7 @@ const PaperSourceCap lower("Lower", false, JobData::kLower); const ResolutionCap dpi300("300dpi", true, 300, 300); -const PaperCap *papers[] = { +const PaperCap* papers[] = { &a4, &a3, &a5, @@ -81,31 +83,35 @@ const PaperCap *papers[] = { &legal }; -const PaperSourceCap *papersources[] = { +const PaperSourceCap* papersources[] = { &autobin, &manual, &upper, &lower }; -const ResolutionCap *resolutions[] = { +const ResolutionCap* resolutions[] = { &dpi300 }; const ColorCap color("Color", false, JobData::kColor); const ColorCap monochrome("Shades of Gray", true, JobData::kMonochrome); -const ColorCap *colors[] = { +const ColorCap* colors[] = { &color, &monochrome }; -Lips3Cap::Lips3Cap(const PrinterData *printer_data) - : PrinterCap(printer_data) + +Lips3Cap::Lips3Cap(const PrinterData* printer_data) + : + PrinterCap(printer_data) { } -int Lips3Cap::countCap(CapID capid) const + +int +Lips3Cap::countCap(CapID capid) const { switch (capid) { case kPaper: @@ -121,7 +127,9 @@ int Lips3Cap::countCap(CapID capid) const } } -const BaseCap **Lips3Cap::enumCap(CapID capid) const + +const +BaseCap **Lips3Cap::enumCap(CapID capid) const { switch (capid) { case kPaper: @@ -137,7 +145,9 @@ const BaseCap **Lips3Cap::enumCap(CapID capid) const } } -bool Lips3Cap::isSupport(CapID capid) const + +bool +Lips3Cap::isSupport(CapID capid) const { switch (capid) { case kPaper: diff --git a/src/add-ons/print/drivers/canon_lips/lips3/Lips3Cap.h b/src/add-ons/print/drivers/canon_lips/lips3/Lips3Cap.h index 95fd40cac2..8e2fb97e52 100644 --- a/src/add-ons/print/drivers/canon_lips/lips3/Lips3Cap.h +++ b/src/add-ons/print/drivers/canon_lips/lips3/Lips3Cap.h @@ -2,18 +2,19 @@ * Lips3Cap.h * Copyright 1999-2000 Y.Takagi. All Rights Reserved. */ - #ifndef __LIPS3CAP_H #define __LIPS3CAP_H + #include "PrinterCap.h" + class Lips3Cap : public PrinterCap { public: - Lips3Cap(const PrinterData *printer_data); - virtual int countCap(CapID) const; - virtual bool isSupport(CapID) const; - virtual const BaseCap **enumCap(CapID) const; + Lips3Cap(const PrinterData* printer_data); + virtual int countCap(CapID) const; + virtual bool isSupport(CapID) const; + virtual const BaseCap **enumCap(CapID) const; }; -#endif /* __LIPS3CAP_H */ +#endif // __LIPS3CAP_H diff --git a/src/add-ons/print/drivers/canon_lips/lips3/Lips3Entry.cpp b/src/add-ons/print/drivers/canon_lips/lips3/Lips3Entry.cpp index ab839b3a16..3f034d486a 100644 --- a/src/add-ons/print/drivers/canon_lips/lips3/Lips3Entry.cpp +++ b/src/add-ons/print/drivers/canon_lips/lips3/Lips3Entry.cpp @@ -3,10 +3,12 @@ * Copyright 1999-2000 Y.Takagi. All Rights Reserved. */ + #include "Lips3.h" #include "Lips3Cap.h" #include "PrinterDriver.h" + class Lips3PrinterDriver : public PrinterDriver { public: @@ -22,7 +24,7 @@ public: return "Canon LIPS3 compatible"; } - const char* GetVersion() const + const char* GetVersion() const { return "0.9.4"; } @@ -37,14 +39,15 @@ public: return new Lips3Cap(printerData); } - GraphicsDriver* InstantiateGraphicsDriver(BMessage* settings, PrinterData* printerData, PrinterCap* printerCap) + GraphicsDriver* InstantiateGraphicsDriver(BMessage* settings, + PrinterData* printerData, PrinterCap* printerCap) { return new LIPS3Driver(settings, printerData, printerCap); } }; + PrinterDriver* instantiate_printer_driver(BNode* printerFolder) { return new Lips3PrinterDriver(printerFolder); } -