Style cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37366 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Wim van der Meer
2010-07-03 08:11:37 +00:00
parent a6cd1edfaa
commit 6b176bef5b
5 changed files with 169 additions and 126 deletions
+88 -60
View File
@@ -4,19 +4,24 @@
* Copyright 2003 Michael Pfeiffer. * Copyright 2003 Michael Pfeiffer.
*/ */
#include "PCL5.h"
#include <memory>
#include <Alert.h> #include <Alert.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <File.h> #include <File.h>
#include <memory>
#include "PCL5.h"
#include "UIDriver.h"
#include "JobData.h"
#include "PrinterData.h"
#include "PCL5Cap.h"
#include "PackBits.h"
#include "Halftone.h"
#include "ValidRect.h"
#include "DbgMsg.h" #include "DbgMsg.h"
#include "Halftone.h"
#include "JobData.h"
#include "PackBits.h"
#include "PCL5Cap.h"
#include "PrinterData.h"
#include "UIDriver.h"
#include "ValidRect.h"
#if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE)) #if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE))
using namespace std; using namespace std;
@@ -24,41 +29,54 @@ using namespace std;
#define std #define std
#endif #endif
PCL5Driver::PCL5Driver(BMessage *msg, PrinterData *printer_data, const PrinterCap *printer_cap)
: GraphicsDriver(msg, printer_data, printer_cap) PCL5Driver::PCL5Driver(BMessage* msg, PrinterData* printer_data,
const PrinterCap* printer_cap)
:
GraphicsDriver(msg, printer_data, printer_cap)
{ {
fHalftone = NULL; fHalftone = NULL;
} }
bool PCL5Driver::startDoc()
bool
PCL5Driver::startDoc()
{ {
try { try {
jobStart(); jobStart();
fHalftone = new Halftone(getJobData()->getSurfaceType(), getJobData()->getGamma(), getJobData()->getInkDensity(), getJobData()->getDitherType()); fHalftone = new Halftone(getJobData()->getSurfaceType(),
getJobData()->getGamma(), getJobData()->getInkDensity(),
getJobData()->getDitherType());
return true; return true;
} }
catch (TransportException &err) { catch (TransportException& err) {
return false; return false;
} }
} }
bool PCL5Driver::startPage(int)
bool
PCL5Driver::startPage(int)
{ {
return true; return true;
} }
bool PCL5Driver::endPage(int)
bool
PCL5Driver::endPage(int)
{ {
try { try {
writeSpoolChar('\014'); writeSpoolChar('\014');
return true; return true;
} }
catch (TransportException &err) { catch (TransportException& err) {
return false; return false;
} }
} }
bool PCL5Driver::endDoc(bool)
bool
PCL5Driver::endDoc(bool)
{ {
try { try {
if (fHalftone) { if (fHalftone) {
@@ -67,12 +85,14 @@ bool PCL5Driver::endDoc(bool)
jobEnd(); jobEnd();
return true; return true;
} }
catch (TransportException &err) { catch (TransportException& err) {
return false; return false;
} }
} }
bool PCL5Driver::nextBand(BBitmap *bitmap, BPoint *offset)
bool
PCL5Driver::nextBand(BBitmap* bitmap, BPoint* offset)
{ {
DBGMSG(("> nextBand\n")); DBGMSG(("> nextBand\n"));
@@ -80,9 +100,9 @@ bool PCL5Driver::nextBand(BBitmap *bitmap, BPoint *offset)
BRect bounds = bitmap->Bounds(); BRect bounds = bitmap->Bounds();
RECT rc; RECT rc;
rc.left = (int)bounds.left; rc.left = (int)bounds.left;
rc.top = (int)bounds.top; rc.top = (int)bounds.top;
rc.right = (int)bounds.right; rc.right = (int)bounds.right;
rc.bottom = (int)bounds.bottom; rc.bottom = (int)bounds.bottom;
int height = rc.bottom - rc.top + 1; int height = rc.bottom - rc.top + 1;
@@ -92,9 +112,8 @@ bool PCL5Driver::nextBand(BBitmap *bitmap, BPoint *offset)
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;
}
rc.bottom = height - 1; rc.bottom = height - 1;
@@ -111,11 +130,12 @@ bool PCL5Driver::nextBand(BBitmap *bitmap, BPoint *offset)
y += rc.top; y += rc.top;
int width = rc.right - rc.left + 1; int width = rc.right - rc.left + 1;
int widthByte = (width + 7) / 8; /* byte boundary */ int widthByte = (width + 7) / 8;
int height = rc.bottom - rc.top + 1; // byte boundary
int in_size = widthByte; int height = rc.bottom - rc.top + 1;
int out_size = (widthByte * 6 + 4) / 5; int in_size = widthByte;
int delta = bitmap->BytesPerRow(); int out_size = (widthByte * 6 + 4) / 5;
int delta = bitmap->BytesPerRow();
DBGMSG(("width = %d\n", width)); DBGMSG(("width = %d\n", width));
DBGMSG(("widthByte = %d\n", widthByte)); DBGMSG(("widthByte = %d\n", widthByte));
@@ -125,16 +145,16 @@ bool PCL5Driver::nextBand(BBitmap *bitmap, BPoint *offset)
DBGMSG(("delta = %d\n", delta)); 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<uchar*>(bitmap->Bits())
+ rc.top * delta + rc.top * delta
+ (rc.left * fHalftone->getPixelDepth()) / 8; + (rc.left * fHalftone->getPixelDepth()) / 8;
int compression_method; int compression_method;
int compressed_size; int compressed_size;
const uchar *buffer; const uchar* buffer;
uchar *in_buffer = new uchar[in_size]; uchar* in_buffer = new uchar[in_size];
uchar *out_buffer = new uchar[out_size]; uchar* out_buffer = new uchar[out_size];
auto_ptr<uchar> _in_buffer (in_buffer); auto_ptr<uchar> _in_buffer (in_buffer);
auto_ptr<uchar> _out_buffer(out_buffer); auto_ptr<uchar> _out_buffer(out_buffer);
@@ -160,7 +180,8 @@ bool PCL5Driver::nextBand(BBitmap *bitmap, BPoint *offset)
compressed_size = pack_bits(out_buffer, in_buffer, in_size); compressed_size = pack_bits(out_buffer, in_buffer, in_size);
if (compressed_size + bytesToEnterCompressionMethod(2) < in_size + bytesToEnterCompressionMethod(0)) { if (compressed_size + bytesToEnterCompressionMethod(2)
< in_size + bytesToEnterCompressionMethod(0)) {
compression_method = 2; // back bits compression_method = 2; // back bits
buffer = out_buffer; buffer = out_buffer;
} else { } else {
@@ -183,28 +204,28 @@ bool PCL5Driver::nextBand(BBitmap *bitmap, BPoint *offset)
endRasterGraphics(); endRasterGraphics();
} else { } else
DBGMSG(("band bitmap is clean.\n")); DBGMSG(("band bitmap is clean.\n"));
}
if (y >= page_height) { if (y >= page_height) {
offset->x = -1.0; offset->x = -1.0;
offset->y = -1.0; offset->y = -1.0;
} else { } else
offset->y += height; offset->y += height;
}
DBGMSG(("< nextBand\n")); DBGMSG(("< nextBand\n"));
return true; return true;
} }
catch (TransportException &err) { catch (TransportException& err) {
BAlert *alert = new BAlert("", err.what(), "OK"); BAlert* alert = new BAlert("", err.what(), "OK");
alert->Go(); alert->Go();
return false; return false;
} }
} }
void PCL5Driver::jobStart()
void
PCL5Driver::jobStart()
{ {
const bool color = getJobData()->getColor() == JobData::kColor; const bool color = getJobData()->getColor() == JobData::kColor;
// enter PCL5 // enter PCL5
@@ -233,7 +254,9 @@ void PCL5Driver::jobStart()
// writeSpoolString("\033&l%ldL", getJobData()->getCopies()); // writeSpoolString("\033&l%ldL", getJobData()->getCopies());
} }
void PCL5Driver::startRasterGraphics(int width, int height)
void
PCL5Driver::startRasterGraphics(int width, int height)
{ {
// width // width
writeSpoolString("\033*r%dS", width); writeSpoolString("\033*r%dS", width);
@@ -244,47 +267,52 @@ void PCL5Driver::startRasterGraphics(int width, int height)
fCompressionMethod = -1; fCompressionMethod = -1;
} }
void PCL5Driver::endRasterGraphics()
void
PCL5Driver::endRasterGraphics()
{ {
writeSpoolString("\033*rB"); writeSpoolString("\033*rB");
} }
void PCL5Driver::rasterGraphics(
int compression_method, void
const uchar *buffer, PCL5Driver::rasterGraphics(int compression_method, const uchar* buffer,
int size, int size, bool lastPlane)
bool lastPlane)
{ {
if (fCompressionMethod != compression_method) { if (fCompressionMethod != compression_method) {
writeSpoolString("\033*b%dM", compression_method); writeSpoolString("\033*b%dM", compression_method);
fCompressionMethod = compression_method; fCompressionMethod = compression_method;
} }
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 PCL5Driver::jobEnd()
void
PCL5Driver::jobEnd()
{ {
writeSpoolString("\033&l1T"); writeSpoolString("\033&l1T");
writeSpoolString("\033E"); writeSpoolString("\033E");
} }
void PCL5Driver::move(int x, int y)
void
PCL5Driver::move(int x, int y)
{ {
writeSpoolString("\033*p%dx%dY", x, y+75); writeSpoolString("\033*p%dx%dY", x, y + 75);
} }
int PCL5Driver::bytesToEnterCompressionMethod(int compression_method)
int
PCL5Driver::bytesToEnterCompressionMethod(int compression_method)
{ {
if (fCompressionMethod == compression_method) { if (fCompressionMethod == compression_method)
return 0; return 0;
} else { else
return 5; return 5;
}
} }
+21 -21
View File
@@ -2,40 +2,40 @@
* PCL5.h * PCL5.h
* Copyright 1999-2000 Y.Takagi. All Rights Reserved. * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
*/ */
#ifndef __PCL5_H #ifndef __PCL5_H
#define __PCL5_H #define __PCL5_H
#include "GraphicsDriver.h" #include "GraphicsDriver.h"
class Halftone; class Halftone;
class PCL5Driver : public GraphicsDriver { class PCL5Driver : public GraphicsDriver {
public: public:
PCL5Driver(BMessage *msg, PrinterData *printer_data, const PrinterCap *printer_cap); PCL5Driver(BMessage* msg, PrinterData* printer_data,
const PrinterCap* printer_cap);
protected: protected:
virtual bool startDoc(); virtual bool startDoc();
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 endDoc(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( void rasterGraphics(int compression_method,
int compression_method, const uchar* buffer, int size, bool lastPlane);
const uchar *buffer, void jobEnd();
int size, int bytesToEnterCompressionMethod(int compression_method);
bool lastPlane);
void jobEnd();
int bytesToEnterCompressionMethod(int compression_method);
int fCompressionMethod; int fCompressionMethod;
Halftone *fHalftone; Halftone* fHalftone;
}; };
#endif /* __PCL5_H */ #endif // __PCL5_H
+47 -37
View File
@@ -3,9 +3,11 @@
* Copyright 1999-2000 Y.Takagi. All Rights Reserved. * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
*/ */
#include "PrinterData.h"
#include "PCL5Cap.h" #include "PCL5Cap.h"
#include "PrinterData.h"
#define TO72DPI(a) (a * 72.0f / 600.0f) #define TO72DPI(a) (a * 72.0f / 600.0f)
const PaperCap a3( const PaperCap a3(
@@ -70,7 +72,7 @@ const ResolutionCap dpi300("300dpi", true, 300, 300);
const ResolutionCap dpi600("600dpi", false, 600, 600); const ResolutionCap dpi600("600dpi", false, 600, 600);
const ResolutionCap dpi1200("1200dpi", false, 1200, 1200); const ResolutionCap dpi1200("1200dpi", false, 1200, 1200);
const PaperCap *papers[] = { const PaperCap* papers[] = {
&a4, &a4,
&a3, &a3,
&a5, &a5,
@@ -80,11 +82,11 @@ const PaperCap *papers[] = {
&legal &legal
}; };
const PaperSourceCap *papersources[] = { const PaperSourceCap* papersources[] = {
&autobin, &autobin,
}; };
const ResolutionCap *resolutions[] = { const ResolutionCap* resolutions[] = {
&dpi300, &dpi300,
&dpi600, &dpi600,
&dpi1200, &dpi1200,
@@ -93,57 +95,65 @@ const ResolutionCap *resolutions[] = {
const ColorCap color("Color", false, JobData::kColor); const ColorCap color("Color", false, JobData::kColor);
const ColorCap monochrome("Shades of Gray", true, JobData::kMonochrome); const ColorCap monochrome("Shades of Gray", true, JobData::kMonochrome);
const ColorCap *colors[] = { const ColorCap* colors[] = {
&color, &color,
&monochrome &monochrome
}; };
PCL5Cap::PCL5Cap(const PrinterData *printer_data)
: PrinterCap(printer_data) PCL5Cap::PCL5Cap(const PrinterData* printer_data)
:
PrinterCap(printer_data)
{ {
} }
int PCL5Cap::countCap(CapID capid) const
int
PCL5Cap::countCap(CapID capid) const
{ {
switch (capid) { switch (capid) {
case kPaper: case kPaper:
return sizeof(papers) / sizeof(papers[0]); return sizeof(papers) / sizeof(papers[0]);
case kPaperSource: case kPaperSource:
return sizeof(papersources) / sizeof(papersources[0]); return sizeof(papersources) / sizeof(papersources[0]);
case kResolution: case kResolution:
return sizeof(resolutions) / sizeof(resolutions[0]); return sizeof(resolutions) / sizeof(resolutions[0]);
case kColor: case kColor:
return sizeof(colors) / sizeof(colors[0]); return sizeof(colors) / sizeof(colors[0]);
default: default:
return 0; return 0;
} }
} }
const BaseCap **PCL5Cap::enumCap(CapID capid) const
const BaseCap**
PCL5Cap::enumCap(CapID capid) const
{ {
switch (capid) { switch (capid) {
case kPaper: case kPaper:
return (const BaseCap **)papers; return (const BaseCap **)papers;
case kPaperSource: case kPaperSource:
return (const BaseCap **)papersources; return (const BaseCap **)papersources;
case kResolution: case kResolution:
return (const BaseCap **)resolutions; return (const BaseCap **)resolutions;
case kColor: case kColor:
return (const BaseCap **)colors; return (const BaseCap **)colors;
default: default:
return NULL; return NULL;
} }
} }
bool PCL5Cap::isSupport(CapID capid) const
bool
PCL5Cap::isSupport(CapID capid) const
{ {
switch (capid) { switch (capid) {
case kPaper: case kPaper:
case kPaperSource: case kPaperSource:
case kResolution: case kResolution:
case kColor: case kColor:
return true; return true;
default: default:
return false; return false;
} }
} }
+7 -6
View File
@@ -2,18 +2,19 @@
* PCL5Cap.h * PCL5Cap.h
* Copyright 1999-2000 Y.Takagi. All Rights Reserved. * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
*/ */
#ifndef __PCL5CAP_H #ifndef __PCL5CAP_H
#define __PCL5CAP_H #define __PCL5CAP_H
#include "PrinterCap.h" #include "PrinterCap.h"
class PCL5Cap : public PrinterCap { class PCL5Cap : public PrinterCap {
public: public:
PCL5Cap(const PrinterData *printer_data); PCL5Cap(const PrinterData* printer_data);
virtual int countCap(CapID) const; virtual int countCap(CapID) const;
virtual bool isSupport(CapID) const; virtual bool isSupport(CapID) const;
virtual const BaseCap **enumCap(CapID) const; virtual const BaseCap **enumCap(CapID) const;
}; };
#endif /* __PCL5CAP_H */ #endif // __PCL5CAP_H
+6 -2
View File
@@ -4,10 +4,12 @@
* Copyright 2003 Michael Pfeiffer. * Copyright 2003 Michael Pfeiffer.
*/ */
#include "PCL5.h" #include "PCL5.h"
#include "PCL5Cap.h" #include "PCL5Cap.h"
#include "PrinterDriver.h" #include "PrinterDriver.h"
class PCL5PrinterDriver : public PrinterDriver class PCL5PrinterDriver : public PrinterDriver
{ {
public: public:
@@ -23,7 +25,7 @@ public:
return "PCL5 compatible"; return "PCL5 compatible";
} }
const char* GetVersion() const const char* GetVersion() const
{ {
return "1.0"; return "1.0";
} }
@@ -38,12 +40,14 @@ public:
return new PCL5Cap(printerData); return new PCL5Cap(printerData);
} }
GraphicsDriver* InstantiateGraphicsDriver(BMessage* settings, PrinterData* printerData, PrinterCap* printerCap) GraphicsDriver* InstantiateGraphicsDriver(BMessage* settings,
PrinterData* printerData, PrinterCap* printerCap)
{ {
return new PCL5Driver(settings, printerData, printerCap); return new PCL5Driver(settings, printerData, printerCap);
} }
}; };
PrinterDriver* instantiate_printer_driver(BNode* printerFolder) PrinterDriver* instantiate_printer_driver(BNode* printerFolder)
{ {
return new PCL5PrinterDriver(printerFolder); return new PCL5PrinterDriver(printerFolder);