summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <quikee@gmail.com>2013-03-03 20:49:18 +0100
committerTomaž Vajngerl <quikee@gmail.com>2013-03-03 20:57:02 +0100
commit9058681a8d4f52db18f094994b231e719e9bb6eb (patch)
treeb89be90c3fd4899915d23b1ceb6429fbda51d2c0
parentdca9978fdbd96f0b23b3e52431bf074d259ceec1 (diff)
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
-rw-r--r--vcl/inc/printdlg.hxx5
-rw-r--r--vcl/source/window/printdlg.cxx104
2 files changed, 57 insertions, 52 deletions
diff --git a/vcl/inc/printdlg.hxx b/vcl/inc/printdlg.hxx
index d57218ebd2bb..296d5b89edea 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 7562a16880a5..bfceb7e7b168 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 )