Style cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37365 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Wim van der Meer
2010-07-03 07:49:30 +00:00
parent 24874466dc
commit a6cd1edfaa
7 changed files with 318 additions and 254 deletions
@@ -39,12 +39,8 @@ private:
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 rasterGraphics(int size, int widthbyte, int height,
int compression_method, const uchar* buffer);
void formFeed();
void jobEnd();
@@ -3,13 +3,13 @@
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
*/
#include "Lips3Cap.h"
#include "PrinterData.h"
#define TO72DPI(a) (a * 72.0f / 600.0f)
const PaperCap a3(
"A3",
false,
@@ -114,16 +114,16 @@ int
Lips3Cap::countCap(CapID capid) const
{
switch (capid) {
case kPaper:
return sizeof(papers) / sizeof(papers[0]);
case kPaperSource:
return sizeof(papersources) / sizeof(papersources[0]);
case kResolution:
return sizeof(resolutions) / sizeof(resolutions[0]);
case kColor:
return sizeof(colors) / sizeof(colors[0]);
default:
return 0;
case kPaper:
return sizeof(papers) / sizeof(papers[0]);
case kPaperSource:
return sizeof(papersources) / sizeof(papersources[0]);
case kResolution:
return sizeof(resolutions) / sizeof(resolutions[0]);
case kColor:
return sizeof(colors) / sizeof(colors[0]);
default:
return 0;
}
}
@@ -132,16 +132,16 @@ const
BaseCap **Lips3Cap::enumCap(CapID capid) const
{
switch (capid) {
case kPaper:
return (const BaseCap **)papers;
case kPaperSource:
return (const BaseCap **)papersources;
case kResolution:
return (const BaseCap **)resolutions;
case kColor:
return (const BaseCap **)colors;
default:
return NULL;
case kPaper:
return (const BaseCap **)papers;
case kPaperSource:
return (const BaseCap **)papersources;
case kResolution:
return (const BaseCap **)resolutions;
case kColor:
return (const BaseCap **)colors;
default:
return NULL;
}
}
@@ -150,13 +150,13 @@ bool
Lips3Cap::isSupport(CapID capid) const
{
switch (capid) {
case kPaper:
case kPaperSource:
case kResolution:
case kColor:
case kCopyCommand:
return true;
default:
return false;
case kPaper:
case kPaperSource:
case kResolution:
case kColor:
case kCopyCommand:
return true;
default:
return false;
}
}
@@ -3,18 +3,22 @@
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
*/
#include "Lips4Cap.h"
#include <memory>
#include <Alert.h>
#include <Bitmap.h>
#include <File.h>
#include <memory>
#include "DbgMsg.h"
#include "Halftone.h"
#include "JobData.h"
#include "Lips4.h"
#include "PackBits.h"
#include "JobData.h"
#include "PrinterData.h"
#include "Lips4Cap.h"
#include "Halftone.h"
#include "ValidRect.h"
#include "DbgMsg.h"
#if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE))
using namespace std;
@@ -22,13 +26,18 @@ using namespace std;
#define std
#endif
LIPS4Driver::LIPS4Driver(BMessage *msg, PrinterData *printer_data, const PrinterCap *printer_cap)
: GraphicsDriver(msg, printer_data, printer_cap)
LIPS4Driver::LIPS4Driver(BMessage* msg, PrinterData* printer_data,
const PrinterCap *printer_cap)
:
GraphicsDriver(msg, printer_data, printer_cap)
{
fHalftone = NULL;
}
bool LIPS4Driver::startDoc()
bool
LIPS4Driver::startDoc()
{
try {
beginTextMode();
@@ -43,15 +52,19 @@ bool LIPS4Driver::startDoc()
setNumberOfCopies();
sidePrintingControl();
setBindingMargin();
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 LIPS4Driver::startPage(int)
bool
LIPS4Driver::startPage(int)
{
try {
fCurrentX = 0;
@@ -59,37 +72,43 @@ bool LIPS4Driver::startPage(int)
memorizedPosition();
return true;
}
catch (TransportException &err) {
catch (TransportException& err) {
return false;
}
}
bool LIPS4Driver::endPage(int)
bool
LIPS4Driver::endPage(int)
{
try {
formFeed();
return true;
}
catch (TransportException &err) {
catch (TransportException& err) {
return false;
}
}
bool LIPS4Driver::endDoc(bool)
bool
LIPS4Driver::endDoc(bool)
{
try {
if (fHalftone) {
if (fHalftone)
delete fHalftone;
}
jobEnd();
return true;
}
catch (TransportException &err) {
catch (TransportException& err) {
return false;
}
}
bool LIPS4Driver::nextBand(BBitmap *bitmap, BPoint *offset)
bool
LIPS4Driver::nextBand(BBitmap* bitmap, BPoint* offset)
{
DBGMSG(("> nextBand\n"));
@@ -106,9 +125,9 @@ bool LIPS4Driver::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;
@@ -118,9 +137,8 @@ bool LIPS4Driver::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;
@@ -136,12 +154,12 @@ bool LIPS4Driver::nextBand(BBitmap *bitmap, BPoint *offset)
x = rc.left;
y += rc.top;
int width = rc.right - rc.left + 1;
int width = rc.right - rc.left + 1;
int widthByte = (width + 7) / 8;
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 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));
@@ -149,23 +167,24 @@ bool LIPS4Driver::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(("fHalftone_engine->get_pixel_depth() = %d\n", fHalftone->getPixelDepth()));
DBGMSG(("fHalftone_engine->get_pixel_depth() = %d\n",
fHalftone->getPixelDepth()));
uchar *ptr = (uchar *)bitmap->Bits()
uchar* ptr = static_cast<uchar*>(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<uchar> _in_buffer (in_buffer);
auto_ptr<uchar> _out_buffer(out_buffer);
uchar *ptr2 = (uchar *)in_buffer;
uchar* ptr2 = static_cast<uchar *>(in_buffer);
DBGMSG(("move\n"));
@@ -186,7 +205,7 @@ bool LIPS4Driver::nextBand(BBitmap *bitmap, BPoint *offset)
compression_method = 11;
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 {
@@ -207,38 +226,42 @@ bool LIPS4Driver::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 LIPS4Driver::beginTextMode()
void
LIPS4Driver::beginTextMode()
{
writeSpoolString("\033%%@");
}
void LIPS4Driver::jobStart()
void
LIPS4Driver::jobStart()
{
writeSpoolString("\033P41;%d;1J\033\\", getJobData()->getXres());
}
void LIPS4Driver::colorModeDeclaration()
void
LIPS4Driver::colorModeDeclaration()
{
// if (color)
// writeSpoolString("\033[1\"p");
@@ -246,22 +269,30 @@ void LIPS4Driver::colorModeDeclaration()
writeSpoolString("\033[0\"p");
}
void LIPS4Driver::softReset()
void
LIPS4Driver::softReset()
{
writeSpoolString("\033<");
}
void LIPS4Driver::sizeUnitMode()
void
LIPS4Driver::sizeUnitMode()
{
writeSpoolString("\033[11h");
}
void LIPS4Driver::selectSizeUnit()
void
LIPS4Driver::selectSizeUnit()
{
writeSpoolString("\033[?7;%d I", getJobData()->getXres());
}
void LIPS4Driver::paperFeedMode()
void
LIPS4Driver::paperFeedMode()
{
// 0 auto
// --------------
@@ -281,79 +312,81 @@ void LIPS4Driver::paperFeedMode()
int i;
switch (getJobData()->getPaperSource()) {
case JobData::kManual:
i = 10;
break;
case JobData::kUpper:
i = 11;
break;
case JobData::kMiddle:
i = 12;
break;
case JobData::kLower:
i = 13;
break;
case JobData::kAuto:
default:
i = 0;
break;
case JobData::kManual:
i = 10;
break;
case JobData::kUpper:
i = 11;
break;
case JobData::kMiddle:
i = 12;
break;
case JobData::kLower:
i = 13;
break;
case JobData::kAuto:
default:
i = 0;
break;
}
writeSpoolString("\033[%dq", i);
}
void LIPS4Driver::selectPageFormat()
void
LIPS4Driver::selectPageFormat()
{
int i;
switch (getJobData()->getPaper()) {
case JobData::kA3:
i = 12;
break;
case JobData::kA3:
i = 12;
break;
case JobData::kA4:
i = 14;
break;
case JobData::kA4:
i = 14;
break;
case JobData::kA5:
i = 16;
break;
case JobData::kA5:
i = 16;
break;
case JobData::kJapanesePostcard:
i = 18;
break;
case JobData::kJapanesePostcard:
i = 18;
break;
case JobData::kB4:
i = 24;
break;
case JobData::kB4:
i = 24;
break;
case JobData::kB5:
i = 26;
break;
case JobData::kB5:
i = 26;
break;
case JobData::kLetter:
i = 30;
break;
case JobData::kLetter:
i = 30;
break;
case JobData::kLegal:
i = 32;
break;
case JobData::kLegal:
i = 32;
break;
case JobData::kExecutive:
i = 40;
break;
case JobData::kExecutive:
i = 40;
break;
case JobData::kJEnvYou4:
i = 50;
break;
case JobData::kJEnvYou4:
i = 50;
break;
case JobData::kUser:
i = 90;
break;
case JobData::kUser:
i = 90;
break;
default:
i = 0;
break;
default:
i = 0;
break;
}
if (JobData::kLandscape == getJobData()->getOrientation())
@@ -362,17 +395,23 @@ void LIPS4Driver::selectPageFormat()
writeSpoolString("\033[%d;;p", i);
}
void LIPS4Driver::disableAutoFF()
void
LIPS4Driver::disableAutoFF()
{
writeSpoolString("\033[?2h");
}
void LIPS4Driver::setNumberOfCopies()
void
LIPS4Driver::setNumberOfCopies()
{
writeSpoolString("\033[%ldv", getJobData()->getCopies());
}
void LIPS4Driver::sidePrintingControl()
void
LIPS4Driver::sidePrintingControl()
{
if (getJobData()->getPrintStyle() == JobData::kSimplex)
writeSpoolString("\033[0#x");
@@ -380,7 +419,9 @@ void LIPS4Driver::sidePrintingControl()
writeSpoolString("\033[2;0#x");
}
void LIPS4Driver::setBindingMargin()
void
LIPS4Driver::setBindingMargin()
{
if (getJobData()->getPrintStyle() == JobData::kDuplex) {
int i;
@@ -402,32 +443,38 @@ void LIPS4Driver::setBindingMargin()
}
}
void LIPS4Driver::memorizedPosition()
void
LIPS4Driver::memorizedPosition()
{
writeSpoolString("\033[0;1;0x");
}
void LIPS4Driver::moveAbsoluteHorizontal(int x)
void
LIPS4Driver::moveAbsoluteHorizontal(int x)
{
writeSpoolString("\033[%ld`", x);
}
void LIPS4Driver::carriageReturn()
void
LIPS4Driver::carriageReturn()
{
writeSpoolChar('\x0d');
}
void LIPS4Driver::moveDown(int dy)
void
LIPS4Driver::moveDown(int dy)
{
writeSpoolString("\033[%lde", dy);
}
void LIPS4Driver::rasterGraphics(
int compression_size,
int widthbyte,
int height,
int compression_method,
const uchar *buffer)
void
LIPS4Driver::rasterGraphics(int compression_size, int widthbyte, int height,
int compression_method, const uchar* buffer)
{
// 0 RAW
// 10 RLE
@@ -444,17 +491,23 @@ void LIPS4Driver::rasterGraphics(
writeSpoolData(buffer, compression_size);
}
void LIPS4Driver::formFeed()
void
LIPS4Driver::formFeed()
{
writeSpoolChar('\014');
}
void LIPS4Driver::jobEnd()
void
LIPS4Driver::jobEnd()
{
writeSpoolString("\033P0J\033\\");
}
void LIPS4Driver::move(int x, int y)
void
LIPS4Driver::move(int x, int y)
{
if (fCurrentX != x) {
if (x) {
@@ -2,55 +2,53 @@
* Lips4.h
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
*/
#ifndef __LIPS4_H
#define __LIPS4_H
#include "GraphicsDriver.h"
class Halftone;
class LIPS4Driver : public GraphicsDriver {
public:
LIPS4Driver(BMessage *msg, PrinterData *printer_data, const PrinterCap *cap);
LIPS4Driver(BMessage *msg, PrinterData *printer_data, const PrinterCap *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 colorModeDeclaration();
void softReset();
void sizeUnitMode();
void selectSizeUnit();
void paperFeedMode();
void selectPageFormat();
void disableAutoFF();
void setNumberOfCopies();
void sidePrintingControl();
void setBindingMargin();
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 colorModeDeclaration();
void softReset();
void sizeUnitMode();
void selectSizeUnit();
void paperFeedMode();
void selectPageFormat();
void disableAutoFF();
void setNumberOfCopies();
void sidePrintingControl();
void setBindingMargin();
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 /* __LIPS4_H */
#endif // __LIPS4_H
@@ -3,6 +3,7 @@
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
*/
#include "Lips4Cap.h"
#define TO72DPI(a) (a * 72.0f / 600.0f)
@@ -105,12 +106,16 @@ const PrintStyleCap simplex("Simplex", true, JobData::kSimplex);
const PrintStyleCap duplex("Duplex", false, JobData::kDuplex);
const PrintStyleCap booklet("Booklet", false, JobData::kBooklet);
const BindingLocationCap longedge1("Long Edge (left)", true, JobData::kLongEdgeLeft);
const BindingLocationCap longedge2("Long Edge (right)", false, JobData::kLongEdgeRight);
const BindingLocationCap shortedge1("Short Edge (top)", false, JobData::kShortEdgeTop);
const BindingLocationCap shortedge2("Short Edge (bottom)", false, JobData::kShortEdgeBottom);
const BindingLocationCap longedge1("Long Edge (left)", true,
JobData::kLongEdgeLeft);
const BindingLocationCap longedge2("Long Edge (right)", false,
JobData::kLongEdgeRight);
const BindingLocationCap shortedge1("Short Edge (top)", false,
JobData::kShortEdgeTop);
const BindingLocationCap shortedge2("Short Edge (bottom)", false,
JobData::kShortEdgeBottom);
const PaperCap *papers[] = {
const PaperCap* papers[] = {
&a4,
&a3,
&a5,
@@ -124,7 +129,7 @@ const PaperCap *papers[] = {
&japanese_envelope_you4
};
const PaperSourceCap *papersources[] = {
const PaperSourceCap* papersources[] = {
&autobin,
&manual,
&upper,
@@ -132,13 +137,13 @@ const PaperSourceCap *papersources[] = {
&lower
};
const ResolutionCap *resolutions[] = {
const ResolutionCap* resolutions[] = {
&dpi1200,
&dpi600,
&dpi300
};
const PrintStyleCap *printstyles[] = {
const PrintStyleCap* printstyles[] = {
&simplex,
&duplex,
&booklet
@@ -154,64 +159,69 @@ const BindingLocationCap *bindinglocations[] = {
const ColorCap color("Color", false, JobData::kColor);
const ColorCap monochrome("Shades of Gray", true, JobData::kMonochrome);
const ColorCap *colors[] = {
const ColorCap* colors[] = {
&color,
&monochrome
};
int Lips4Cap::countCap(CapID capid) const
int
Lips4Cap::countCap(CapID capid) const
{
switch (capid) {
case kPaper:
return sizeof(papers) / sizeof(papers[0]);
case kPaperSource:
return sizeof(papersources) / sizeof(papersources[0]);
case kResolution:
return sizeof(resolutions) / sizeof(resolutions[0]);
case kPrintStyle:
return sizeof(printstyles) / sizeof(printstyles[0]);
case kBindingLocation:
return sizeof(bindinglocations) / sizeof(bindinglocations[0]);
case kColor:
return sizeof(colors) / sizeof(colors[0]);
default:
return 0;
case kPaper:
return sizeof(papers) / sizeof(papers[0]);
case kPaperSource:
return sizeof(papersources) / sizeof(papersources[0]);
case kResolution:
return sizeof(resolutions) / sizeof(resolutions[0]);
case kPrintStyle:
return sizeof(printstyles) / sizeof(printstyles[0]);
case kBindingLocation:
return sizeof(bindinglocations) / sizeof(bindinglocations[0]);
case kColor:
return sizeof(colors) / sizeof(colors[0]);
default:
return 0;
}
}
const BaseCap**
Lips4Cap::enumCap(CapID capid) const
{
switch (capid) {
case kPaper:
return (const BaseCap **)papers;
case kPaperSource:
return (const BaseCap **)papersources;
case kResolution:
return (const BaseCap **)resolutions;
case kPrintStyle:
return (const BaseCap **)printstyles;
case kBindingLocation:
return (const BaseCap **)bindinglocations;
case kColor:
return (const BaseCap **)colors;
default:
return NULL;
}
}
const BaseCap **Lips4Cap::enumCap(CapID capid) const
{
switch (capid) {
case kPaper:
return (const BaseCap **)papers;
case kPaperSource:
return (const BaseCap **)papersources;
case kResolution:
return (const BaseCap **)resolutions;
case kPrintStyle:
return (const BaseCap **)printstyles;
case kBindingLocation:
return (const BaseCap **)bindinglocations;
case kColor:
return (const BaseCap **)colors;
default:
return NULL;
}
}
bool Lips4Cap::isSupport(CapID capid) const
bool
Lips4Cap::isSupport(CapID capid) const
{
switch (capid) {
case kPaper:
case kPaperSource:
case kResolution:
case kPrintStyle:
case kBindingLocation:
case kColor:
case kCopyCommand:
return true;
default:
return false;
}
case kPaper:
case kPaperSource:
case kResolution:
case kPrintStyle:
case kBindingLocation:
case kColor:
case kCopyCommand:
return true;
default:
return false;
}
}
@@ -2,18 +2,20 @@
* Lips4Cap.h
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
*/
#ifndef __LIPS4CAP_H
#define __LIPS4CAP_H
#include "PrinterCap.h"
class Lips4Cap : public PrinterCap {
public:
Lips4Cap(const PrinterData *printer_data) : PrinterCap(printer_data) {}
virtual int countCap(CapID) const;
virtual bool isSupport(CapID) const;
virtual const BaseCap **enumCap(CapID) const;
Lips4Cap(const PrinterData* printer_data)
: PrinterCap(printer_data) {}
virtual int countCap(CapID) const;
virtual bool isSupport(CapID) const;
virtual const BaseCap** enumCap(CapID) const;
};
#endif /* __LIPS4CAP_H */
#endif // __LIPS4CAP_H
@@ -3,10 +3,12 @@
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
*/
#include "Lips4.h"
#include "Lips4Cap.h"
#include "PrinterDriver.h"
class Lips4PrinterDriver : public PrinterDriver
{
public:
@@ -22,7 +24,7 @@ public:
return "Canon LIPS4 compatible";
}
const char* GetVersion() const
const char* GetVersion() const
{
return "0.9.4";
}
@@ -37,13 +39,16 @@ public:
return new Lips4Cap(printerData);
}
GraphicsDriver* InstantiateGraphicsDriver(BMessage* settings, PrinterData* printerData, PrinterCap* printerCap)
GraphicsDriver* InstantiateGraphicsDriver(BMessage* settings,
PrinterData* printerData, PrinterCap* printerCap)
{
return new LIPS4Driver(settings, printerData, printerCap);
}
};
PrinterDriver* instantiate_printer_driver(BNode* printerFolder)
PrinterDriver*
instantiate_printer_driver(BNode* printerFolder)
{
return new Lips4PrinterDriver(printerFolder);
}