[Libreoffice-commits] core.git: 2 commits - vcl/inc vcl/source

Tomaž Vajngerl quikee at gmail.com
Sun Mar 3 11:58:13 PST 2013


 vcl/inc/printdlg.hxx           |    5 ++
 vcl/source/window/printdlg.cxx |   93 ++++++++++++++++++++++-------------------
 2 files changed, 57 insertions(+), 41 deletions(-)

New commits:
commit 9058681a8d4f52db18f094994b231e719e9bb6eb
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Sun Mar 3 20:49:18 2013 +0100

    Better quality previews in print dialog.
    
    Make a fixed size bitmap of the current document for preview in
    print dialog. The bitmap is scaled when the dialog is resized, which
    is faster and better quality as it uses "BEST" scaling method for
    resizing the bitmap.
    
    Change-Id: I3be0bec30a7f2cd594c56d23fe2b39221aff807c

diff --git a/vcl/inc/printdlg.hxx b/vcl/inc/printdlg.hxx
index d57218e..296d5b8 100644
--- a/vcl/inc/printdlg.hxx
+++ b/vcl/inc/printdlg.hxx
@@ -45,16 +45,21 @@ namespace vcl
     public:
         class PrintPreviewWindow : public Window
         {
+            static const sal_Int32 PREVIEW_BITMAP_WIDTH;
+
             GDIMetaFile         maMtf;
             Size                maOrigSize;
             Size                maPreviewSize;
             VirtualDevice       maPageVDev;
+            Bitmap              maPreviewBitmap;
             rtl::OUString       maReplacementString;
             rtl::OUString       maToolTipString;
             bool                mbGreyscale;
             FixedLine           maHorzDim;
             FixedLine           maVertDim;
 
+            void preparePreviewBitmap();
+
         public:
             PrintPreviewWindow( Window* pParent );
             virtual ~PrintPreviewWindow();
diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx
index 7562a16..bfceb7e 100644
--- a/vcl/source/window/printdlg.cxx
+++ b/vcl/source/window/printdlg.cxx
@@ -84,6 +84,8 @@ PrintDialog::PrintPreviewWindow::~PrintPreviewWindow()
 {
 }
 
+const sal_Int32 PrintDialog::PrintPreviewWindow::PREVIEW_BITMAP_WIDTH = 1600;
+
 void PrintDialog::PrintPreviewWindow::DataChanged( const DataChangedEvent& i_rDCEvt )
 {
     // react on settings changed
@@ -133,13 +135,11 @@ void PrintDialog::PrintPreviewWindow::Resize()
     // quality of the preview, e.g. when its height approaches the number of text lines
     // find a good scaling factor
     Size aPreviewMMSize( maPageVDev.PixelToLogic( aScaledSize, MapMode( MAP_100TH_MM ) ) );
-    double fZoom = double(maOrigSize.Height())/double(aPreviewMMSize.Height());
-    while( fZoom > 10 )
-    {
-        aScaledSize.Width() *= 2;
-        aScaledSize.Height() *= 2;
-        fZoom /= 2.0;
-    }
+
+    double aAspectRatio = aScaledSize.Height() / (double) aScaledSize.Width();
+
+    aScaledSize.Width()  = PREVIEW_BITMAP_WIDTH;
+    aScaledSize.Height() = PREVIEW_BITMAP_WIDTH * aAspectRatio;
 
     maPageVDev.SetOutputSizePixel( aScaledSize, sal_False );
 
@@ -175,47 +175,9 @@ void PrintDialog::PrintPreviewWindow::Paint( const Rectangle& )
     }
     else
     {
-        GDIMetaFile aMtf( maMtf );
-
-        const Size aVDevSize( maPageVDev.GetOutputSizePixel() );
-        const Size aLogicSize( maPageVDev.PixelToLogic( aVDevSize, MapMode( MAP_100TH_MM ) ) );
-        Size aOrigSize( maOrigSize );
-        if( aOrigSize.Width() < 1 )
-            aOrigSize.Width() = aLogicSize.Width();
-        if( aOrigSize.Height() < 1 )
-            aOrigSize.Height() = aLogicSize.Height();
-        double fScale = double(aLogicSize.Width())/double(aOrigSize.Width());
-
-
-        maPageVDev.Erase();
-        maPageVDev.Push();
-        maPageVDev.SetMapMode( MAP_100TH_MM );
-        sal_uLong nOldDrawMode = maPageVDev.GetDrawMode();
-        if( mbGreyscale )
-            maPageVDev.SetDrawMode( maPageVDev.GetDrawMode() |
-                                    ( DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_GRAYTEXT |
-                                      DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT ) );
-        aMtf.WindStart();
-        aMtf.Scale( fScale, fScale );
-        aMtf.WindStart();
-
-        const sal_uInt16 nOriginalAA(maPageVDev.GetAntialiasing());
-        maPageVDev.SetAntialiasing(nOriginalAA | ANTIALIASING_ENABLE_B2DDRAW);
-
-        aMtf.Play( &maPageVDev, Point( 0, 0 ), aLogicSize );
-        maPageVDev.Pop();
-
-        maPageVDev.SetAntialiasing(nOriginalAA);
-
-        SetMapMode( MAP_PIXEL );
-        maPageVDev.SetMapMode( MAP_PIXEL );
-
-        // use lanzcos scaling
-        Bitmap aContent(maPageVDev.GetBitmap(Point(0, 0), aVDevSize));
-        aContent.Scale(maPreviewSize, BMP_SCALE_BEST);
-        DrawBitmap(aOffset, aContent);
-
-        maPageVDev.SetDrawMode( nOldDrawMode );
+        Bitmap aPreviewBitmap(maPreviewBitmap);
+        aPreviewBitmap.Scale(maPreviewSize, BMP_SCALE_BEST);
+        DrawBitmap(aOffset, aPreviewBitmap);
     }
 
     Rectangle aFrameRect( aOffset + Point( -1, -1 ),
@@ -236,10 +198,6 @@ void PrintDialog::PrintPreviewWindow::Command( const CommandEvent& rEvt )
                 pDlg->previewForward();
             else if( pWheelData->GetDelta() < 0 )
                 pDlg->previewBackward();
-            /*
-            else
-                huh ?
-            */
         }
     }
 }
@@ -291,9 +249,51 @@ void PrintDialog::PrintPreviewWindow::setPreview( const GDIMetaFile& i_rNewPrevi
     maVertDim.SetText( aBuf.makeStringAndClear() );
 
     Resize();
+    preparePreviewBitmap();
     Invalidate();
 }
 
+void PrintDialog::PrintPreviewWindow::preparePreviewBitmap()
+{
+    GDIMetaFile aMtf( maMtf );
+
+    Size aVDevSize( maPageVDev.GetOutputSizePixel() );
+    const Size aLogicSize( maPageVDev.PixelToLogic( aVDevSize, MapMode( MAP_100TH_MM ) ) );
+    Size aOrigSize( maOrigSize );
+    if( aOrigSize.Width() < 1 )
+        aOrigSize.Width() = aLogicSize.Width();
+    if( aOrigSize.Height() < 1 )
+        aOrigSize.Height() = aLogicSize.Height();
+    double fScale = double(aLogicSize.Width())/double(aOrigSize.Width());
+
+
+    maPageVDev.Erase();
+    maPageVDev.Push();
+    maPageVDev.SetMapMode( MAP_100TH_MM );
+    sal_uLong nOldDrawMode = maPageVDev.GetDrawMode();
+    if( mbGreyscale )
+        maPageVDev.SetDrawMode( maPageVDev.GetDrawMode() |
+                                ( DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_GRAYTEXT |
+                                  DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT ) );
+    aMtf.WindStart();
+    aMtf.Scale( fScale, fScale );
+    aMtf.WindStart();
+
+    const sal_uInt16 nOriginalAA(maPageVDev.GetAntialiasing());
+    maPageVDev.SetAntialiasing(nOriginalAA | ANTIALIASING_ENABLE_B2DDRAW);
+    aMtf.Play( &maPageVDev, Point( 0, 0 ), aLogicSize );
+    maPageVDev.SetAntialiasing(nOriginalAA);
+
+    maPageVDev.Pop();
+
+    SetMapMode( MAP_PIXEL );
+    maPageVDev.SetMapMode( MAP_PIXEL );
+
+    maPreviewBitmap = Bitmap(maPageVDev.GetBitmap(Point(0, 0), aVDevSize));
+
+    maPageVDev.SetDrawMode( nOldDrawMode );
+}
+
 PrintDialog::ShowNupOrderWindow::ShowNupOrderWindow( Window* i_pParent )
     : Window( i_pParent, WB_NOBORDER )
     , mnOrderMode( 0 )
commit dca9978fdbd96f0b23b3e52431bf074d259ceec1
Author: Armin Le Grand <alg at apache.org>
Date:   Sun Mar 3 20:21:48 2013 +0100

    121687# better preview
    
    Change-Id: I7beca0f3d809e5a2ab3d8ef6c73b970010a47eaf

diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx
index e226f78..7562a16 100644
--- a/vcl/source/window/printdlg.cxx
+++ b/vcl/source/window/printdlg.cxx
@@ -177,7 +177,7 @@ void PrintDialog::PrintPreviewWindow::Paint( const Rectangle& )
     {
         GDIMetaFile aMtf( maMtf );
 
-        Size aVDevSize( maPageVDev.GetOutputSizePixel() );
+        const Size aVDevSize( maPageVDev.GetOutputSizePixel() );
         const Size aLogicSize( maPageVDev.PixelToLogic( aVDevSize, MapMode( MAP_100TH_MM ) ) );
         Size aOrigSize( maOrigSize );
         if( aOrigSize.Width() < 1 )
@@ -198,12 +198,23 @@ void PrintDialog::PrintPreviewWindow::Paint( const Rectangle& )
         aMtf.WindStart();
         aMtf.Scale( fScale, fScale );
         aMtf.WindStart();
+
+        const sal_uInt16 nOriginalAA(maPageVDev.GetAntialiasing());
+        maPageVDev.SetAntialiasing(nOriginalAA | ANTIALIASING_ENABLE_B2DDRAW);
+
         aMtf.Play( &maPageVDev, Point( 0, 0 ), aLogicSize );
         maPageVDev.Pop();
 
+        maPageVDev.SetAntialiasing(nOriginalAA);
+
         SetMapMode( MAP_PIXEL );
         maPageVDev.SetMapMode( MAP_PIXEL );
-        DrawOutDev( aOffset, maPreviewSize, Point( 0, 0 ), aVDevSize, maPageVDev );
+
+        // use lanzcos scaling
+        Bitmap aContent(maPageVDev.GetBitmap(Point(0, 0), aVDevSize));
+        aContent.Scale(maPreviewSize, BMP_SCALE_BEST);
+        DrawBitmap(aOffset, aContent);
+
         maPageVDev.SetDrawMode( nOldDrawMode );
     }
 


More information about the Libreoffice-commits mailing list