[haiku-commits] r39800 - in haiku/trunk: headers/libs/print/libprint src/libs/print/libprint

  • From: michael.w.pfeiffer@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 10 Dec 2010 11:47:20 +0100 (CET)

Author: laplace
Date: 2010-12-10 11:47:19 +0100 (Fri, 10 Dec 2010)
New Revision: 39800
Changeset: http://dev.haiku-os.org/changeset/39800
Ticket: http://dev.haiku-os.org/ticket/6965

Modified:
   haiku/trunk/headers/libs/print/libprint/GraphicsDriver.h
   haiku/trunk/headers/libs/print/libprint/PrinterCap.h
   haiku/trunk/src/libs/print/libprint/GraphicsDriver.cpp
Log:
* 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.


Modified: haiku/trunk/headers/libs/print/libprint/GraphicsDriver.h
===================================================================
--- haiku/trunk/headers/libs/print/libprint/GraphicsDriver.h    2010-12-10 
08:35:35 UTC (rev 39799)
+++ haiku/trunk/headers/libs/print/libprint/GraphicsDriver.h    2010-12-10 
10:47:19 UTC (rev 39800)
@@ -22,11 +22,6 @@
 class PrinterCap;
 
 
-enum {
-       kGDFRotateBandBitmap = 1
-};
-
-
 class GraphicsDriver {
 public:
                                GraphicsDriver(BMessage* message, PrinterData* 
printerData,
@@ -34,7 +29,7 @@
        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 @@
                        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 @@
                        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 @@
 
 
 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 */

Modified: haiku/trunk/headers/libs/print/libprint/PrinterCap.h
===================================================================
--- haiku/trunk/headers/libs/print/libprint/PrinterCap.h        2010-12-10 
08:35:35 UTC (rev 39799)
+++ haiku/trunk/headers/libs/print/libprint/PrinterCap.h        2010-12-10 
10:47:19 UTC (rev 39800)
@@ -200,10 +200,13 @@
                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

Modified: haiku/trunk/src/libs/print/libprint/GraphicsDriver.cpp
===================================================================
--- haiku/trunk/src/libs/print/libprint/GraphicsDriver.cpp      2010-12-10 
08:35:35 UTC (rev 39799)
+++ haiku/trunk/src/libs/print/libprint/GraphicsDriver.cpp      2010-12-10 
10:47:19 UTC (rev 39800)
@@ -9,6 +9,7 @@
 
 #include <Alert.h>
 #include <Bitmap.h>
+#include <Debug.h>
 #include <Message.h>
 #include <PrintJob.h>
 #include <Region.h>
@@ -45,10 +46,10 @@
 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 @@
                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 @@
        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 @@
        delete fBitmap;
        fBitmap = NULL;
        fView   = NULL;
+
+       delete fRotatedBitmap;
+       fRotatedBitmap = NULL;
 }
 
 
@@ -460,7 +469,7 @@
                        }
                }
 
-               if (!NextBand(fBitmap, &offset))
+               if (!_PrintBand(fBitmap, &offset))
                        return false;
 
        } while (offset.x >= 0.0f && offset.y >= 0.0f);
@@ -469,6 +478,57 @@
 }
 
 
+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<const uint8_t*>(source->Bits());
+       uint8_t* targetBits = static_cast<uint8_t*>(target->Bits());
+
+       for (int32 y = 0; y < height; y ++) {
+               for (int32 x = 0; x < width; x ++) {
+                       const uint32_t* sourcePixel =
+                               reinterpret_cast<const uint32_t*>(sourceBits + 
sourceBPR * y
+                                       + sizeof(uint32_t) * x);
+
+                       int32 targetX = (height - y - 1);
+                       int32 targetY = x;
+                       uint32_t* targetPixel =
+                               reinterpret_cast<uint32_t*>(targetBits + 
targetBPR * targetY
+                                       + sizeof(uint32_t) * targetX);
+                       *targetPixel = *sourcePixel;
+               }
+       }
+}
+
 bool 
 GraphicsDriver::_CollectPages(SpoolData* spoolData, PageDataList* pages)
 {
@@ -595,7 +655,7 @@
 
 
 bool 
-GraphicsDriver::PrintJob(BFile* spoolFile)
+GraphicsDriver::_PrintJob(BFile* spoolFile)
 {
        bool success = true;
        if (!_SetupData(spoolFile)) {
@@ -653,11 +713,10 @@
 
 
 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 @@
        throw (TransportException)
 {
        if (fTransport == NULL)
-               return
-
+               return;
        fTransport->Write(buffer, size);
 }
 
@@ -738,6 +796,14 @@
 }
 
 
+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;


Other related posts:

  • » [haiku-commits] r39800 - in haiku/trunk: headers/libs/print/libprint src/libs/print/libprint - michael . w . pfeiffer