From b13a0d5d32fda5e092f79b919e829bfbc573e4d0 Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Fri, 10 Dec 2010 10:47:19 +0000 Subject: [PATCH] * Bug fixed: WriteSpoolData didn't pass data to transport add-on because ";" was missing after "return" statement. * Removed unused getter methods from class GraphicsDriver. * Implemented page rotation (closes #6965) in landscape. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39800 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/libs/print/libprint/GraphicsDriver.h | 46 +++-------- headers/libs/print/libprint/PrinterCap.h | 5 +- src/libs/print/libprint/GraphicsDriver.cpp | 86 +++++++++++++++++--- 3 files changed, 91 insertions(+), 46 deletions(-) diff --git a/headers/libs/print/libprint/GraphicsDriver.h b/headers/libs/print/libprint/GraphicsDriver.h index ba21d47d6d..de84ada53e 100644 --- a/headers/libs/print/libprint/GraphicsDriver.h +++ b/headers/libs/print/libprint/GraphicsDriver.h @@ -22,11 +22,6 @@ class PrinterData; class PrinterCap; -enum { - kGDFRotateBandBitmap = 1 -}; - - class GraphicsDriver { public: GraphicsDriver(BMessage* message, PrinterData* printerData, @@ -34,7 +29,7 @@ public: virtual ~GraphicsDriver(); const JobData* GetJobData(BFile* spoolFile); - BMessage* TakeJob(BFile* spoolFile, uint32 flags = 0); + BMessage* TakeJob(BFile* spoolFile); static BPoint GetScale(int32 nup, BRect physicalRect, float scaling); static BPoint GetOffset(int32 nup, int index, JobData::Orientation orientation, const BPoint* scale, @@ -70,11 +65,7 @@ protected: const SpoolMetaData* GetSpoolMetaData() const; int GetProtocolClass() const; - int GetPageWidth() const; int GetPageHeight() const; - int GetBandWidth() const; - int GetBandHeight() const; - int GetPixelDepth() const; private: bool _SetupData(BFile* file); @@ -82,20 +73,25 @@ private: void _CleanupData(); void _CleanupBitmap(); bool _PrintPage(PageDataList* pages); + bool _PrintBand(BBitmap* band, BPoint* offset); + void _RotateInto(BBitmap* target, const BBitmap* source); bool _CollectPages(SpoolData* spoolData, PageDataList* pages); bool _SkipPages(SpoolData* spoolData); bool _PrintDocument(SpoolData* spoolData); - bool PrintJob(BFile* file); + bool _PrintJob(BFile* file); + + bool _NeedRotateBitmapBand() const; + static void _ConvertRGB32ToRGB24(const void* src, void* dst, int width); static void _ConvertCMAP8ToRGB24(const void* src, void* dst, int width); static uint8 _ConvertToGray(uint8 r, uint8 g, uint8 b); static void _ConvertRGB32ToGray(const void* src, void* dst, int width); static void _ConvertCMAP8ToGray(const void* src, void* dst, int width); - uint32 fFlags; BMessage* fMessage; BView* fView; BBitmap* fBitmap; + BBitmap* fRotatedBitmap; Transport* fTransport; JobData* fOrgJobData; JobData* fRealJobData; @@ -153,31 +149,11 @@ GraphicsDriver::GetProtocolClass() const inline int -GraphicsDriver::GetPageWidth() const +GraphicsDriver::GetPageHeight() const { + if (!_NeedRotateBitmapBand()) + return fPageHeight; return fPageWidth; } - -inline int -GraphicsDriver::GetPageHeight() const -{ - return fPageHeight; -} - - -inline int -GraphicsDriver::GetBandWidth() const -{ - return fBandWidth; -} - - -inline int -GraphicsDriver::GetBandHeight() const -{ - return fBandHeight; -} - - #endif /* __GRAPHICSDRIVER_H */ diff --git a/headers/libs/print/libprint/PrinterCap.h b/headers/libs/print/libprint/PrinterCap.h index 22abecd951..a2d8d84caa 100644 --- a/headers/libs/print/libprint/PrinterCap.h +++ b/headers/libs/print/libprint/PrinterCap.h @@ -200,10 +200,13 @@ public: kDriverSpecificCapabilities, // Static boolean settings follow. - // For them isSupport() has to be implemented only. + // For them Supports() has to be implemented only. kCopyCommand, // supports printer page copy command? kHalftone, // needs the printer driver the configuration // for class Halftone? + kCanRotatePageInLandscape, + // can the printer driver rotate the page + // printing in landscape // The driver specific generic capabilities start here kDriverSpecificCapabilitiesBegin = 100 diff --git a/src/libs/print/libprint/GraphicsDriver.cpp b/src/libs/print/libprint/GraphicsDriver.cpp index 97c9a70f70..8340b8a29b 100644 --- a/src/libs/print/libprint/GraphicsDriver.cpp +++ b/src/libs/print/libprint/GraphicsDriver.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -45,10 +46,10 @@ enum { GraphicsDriver::GraphicsDriver(BMessage* message, PrinterData* printerData, const PrinterCap* printerCap) : - fFlags(0), fMessage(message), fView(NULL), fBitmap(NULL), + fRotatedBitmap(NULL), fTransport(NULL), fOrgJobData(NULL), fRealJobData(NULL), @@ -182,8 +183,7 @@ GraphicsDriver::_SetupBitmap() fBandHeight = fPageHeight; } else { fBandCount = (size + kMaxMemorySize - 1) / kMaxMemorySize; - if ((JobData::kLandscape == fRealJobData->GetOrientation()) - && (fFlags & kGDFRotateBandBitmap)) { + if (_NeedRotateBitmapBand()) { fBandWidth = (fPageWidth + fBandCount - 1) / fBandCount; fBandHeight = fPageHeight; } else { @@ -204,6 +204,12 @@ GraphicsDriver::_SetupBitmap() fBitmap = new BBitmap(rect, fOrgJobData->GetSurfaceType(), true); fView = new BView(rect, "", B_FOLLOW_ALL, B_WILL_DRAW); fBitmap->AddChild(fView); + + if (_NeedRotateBitmapBand()) { + BRect rotatedRect(0, 0, rect.bottom, rect.right); + fRotatedBitmap = new BBitmap(rotatedRect, fOrgJobData->GetSurfaceType(), + false); + } } @@ -213,6 +219,9 @@ GraphicsDriver::_CleanupBitmap() delete fBitmap; fBitmap = NULL; fView = NULL; + + delete fRotatedBitmap; + fRotatedBitmap = NULL; } @@ -460,7 +469,7 @@ GraphicsDriver::_PrintPage(PageDataList* pages) } } - if (!NextBand(fBitmap, &offset)) + if (!_PrintBand(fBitmap, &offset)) return false; } while (offset.x >= 0.0f && offset.y >= 0.0f); @@ -469,6 +478,57 @@ GraphicsDriver::_PrintPage(PageDataList* pages) } +bool +GraphicsDriver::_PrintBand(BBitmap* band, BPoint* offset) +{ + if (!_NeedRotateBitmapBand()) + return NextBand(band, offset); + + _RotateInto(fRotatedBitmap, band); + + BPoint rotatedOffset(offset->y, offset->x); + bool success = NextBand(fRotatedBitmap, &rotatedOffset); + offset->x = rotatedOffset.y; + offset->y = rotatedOffset.x; + + return success; +} + + +void +GraphicsDriver::_RotateInto(BBitmap* target, const BBitmap* source) +{ + ASSERT(target->ColorSpace() == B_RGB32); + ASSERT(source->ColorSpace() == B_RGB32); + ASSERT(target->Bounds().IntegerWidth() == source->Bounds().IntegerHeight()); + ASSERT(target->Bounds().IntegerHeight() == source->Bounds().IntegerWidth()); + + const int32 width = source->Bounds().IntegerWidth() + 1; + const int32 height = source->Bounds().IntegerHeight() + 1; + + const int32 sourceBPR = source->BytesPerRow(); + const int32 targetBPR = target->BytesPerRow(); + + const uint8_t* sourceBits = + reinterpret_cast(source->Bits()); + uint8_t* targetBits = static_cast(target->Bits()); + + for (int32 y = 0; y < height; y ++) { + for (int32 x = 0; x < width; x ++) { + const uint32_t* sourcePixel = + reinterpret_cast(sourceBits + sourceBPR * y + + sizeof(uint32_t) * x); + + int32 targetX = (height - y - 1); + int32 targetY = x; + uint32_t* targetPixel = + reinterpret_cast(targetBits + targetBPR * targetY + + sizeof(uint32_t) * targetX); + *targetPixel = *sourcePixel; + } + } +} + bool GraphicsDriver::_CollectPages(SpoolData* spoolData, PageDataList* pages) { @@ -595,7 +655,7 @@ GraphicsDriver::GetJobData(BFile* spoolFile) bool -GraphicsDriver::PrintJob(BFile* spoolFile) +GraphicsDriver::_PrintJob(BFile* spoolFile) { bool success = true; if (!_SetupData(spoolFile)) { @@ -653,11 +713,10 @@ GraphicsDriver::PrintJob(BFile* spoolFile) BMessage* -GraphicsDriver::TakeJob(BFile* spoolFile, uint32 flags) +GraphicsDriver::TakeJob(BFile* spoolFile) { - fFlags = flags; BMessage *msg; - if (PrintJob(spoolFile)) + if (_PrintJob(spoolFile)) msg = new BMessage('okok'); else msg = new BMessage('baad'); @@ -705,8 +764,7 @@ GraphicsDriver::WriteSpoolData(const void* buffer, size_t size) throw (TransportException) { if (fTransport == NULL) - return - + return; fTransport->Write(buffer, size); } @@ -738,6 +796,14 @@ GraphicsDriver::WriteSpoolChar(char c) } +bool +GraphicsDriver::_NeedRotateBitmapBand() const +{ + return JobData::kLandscape == fRealJobData->GetOrientation() + && !fPrinterCap->Supports(PrinterCap::kCanRotatePageInLandscape); +} + + void GraphicsDriver::_ConvertRGB32ToRGB24(const void* src, void* dst, int width) { uint8* d = (uint8*)dst;