cbd1934
From 9fd97266ce7dbeac33c93b6dace69d64c02d222c Mon Sep 17 00:00:00 2001
cbd1934
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
cbd1934
Date: Wed, 23 Apr 2014 15:22:13 +0100
cbd1934
Subject: [PATCH] Related: fdo#36815 center scaled comment page vertically
cbd1934
cbd1934
so comments at the top of the page don't get clipped
cbd1934
off the true printable area
cbd1934
cbd1934
Change-Id: Icb796c901372437b276e7ce4e31c08e0bf2ec250
cbd1934
---
cbd1934
 sw/source/core/view/vprint.cxx | 56 +++++++++++++++---------------------------
cbd1934
 1 file changed, 20 insertions(+), 36 deletions(-)
cbd1934
cbd1934
diff --git a/sw/source/core/view/vprint.cxx b/sw/source/core/view/vprint.cxx
cbd1934
index b680e52..0022fff 100644
cbd1934
--- a/sw/source/core/view/vprint.cxx
cbd1934
+++ b/sw/source/core/view/vprint.cxx
cbd1934
@@ -455,26 +455,6 @@ sal_Bool SwViewShell::PrintOrPDFExport(
cbd1934
     // output device is now provided by a call from outside the Writer)
cbd1934
     pOutDev->Push();
cbd1934
 
cbd1934
-    // fdo#36815 for comments in margins print to a metafile
cbd1934
-    // and then scale that metafile down so that the comments
cbd1934
-    // will fit on the real page, and replay that scaled
cbd1934
-    // output to the real outputdevice
cbd1934
-    GDIMetaFile *pOrigRecorder(NULL);
cbd1934
-    GDIMetaFile *pMetaFile(NULL);
cbd1934
-    sal_Int16 nPostItMode = rPrintData.GetPrintPostIts();
cbd1934
-    if (nPostItMode == POSTITS_INMARGINS)
cbd1934
-    {
cbd1934
-        //get and disable the existing recorder
cbd1934
-        pOrigRecorder = pOutDev->GetConnectMetaFile();
cbd1934
-        pOutDev->SetConnectMetaFile(NULL);
cbd1934
-        // turn off output to the device
cbd1934
-        pOutDev->EnableOutput(false);
cbd1934
-        // just record the rendering commands to the metafile
cbd1934
-        // instead
cbd1934
-        pMetaFile = new GDIMetaFile;
cbd1934
-        pMetaFile->Record(pOutDev);
cbd1934
-    }
cbd1934
-
cbd1934
     // Print/PDF export for (multi-)selection has already generated a
cbd1934
     // temporary document with the selected text.
cbd1934
     // (see XRenderable implementation in unotxdoc.cxx)
cbd1934
@@ -490,6 +470,8 @@ sal_Bool SwViewShell::PrintOrPDFExport(
cbd1934
         pDrawView->SetBufferedOverlayAllowed( false );
cbd1934
     }
cbd1934
 
cbd1934
+    sal_Int16 nPostItMode = rPrintData.GetPrintPostIts();
cbd1934
+
cbd1934
     {   // additional scope so that the CurrShell is reset before destroying the shell
cbd1934
 
cbd1934
         SET_CURR_SHELL( pShell );
cbd1934
@@ -537,22 +519,6 @@ sal_Bool SwViewShell::PrintOrPDFExport(
cbd1934
             pPostItManager->CalcRects();
cbd1934
             pPostItManager->LayoutPostIts();
cbd1934
             pPostItManager->DrawNotesForPage(pOutDev, nPage-1);
cbd1934
-
cbd1934
-            //Now scale the recorded page down so the notes
cbd1934
-            //will fit in the final page
cbd1934
-            pMetaFile->Stop();
cbd1934
-            pMetaFile->WindStart();
cbd1934
-            double fScale = 0.75;
cbd1934
-            pMetaFile->Scale( fScale, fScale );
cbd1934
-            pMetaFile->WindStart();
cbd1934
-
cbd1934
-            //Enable output the the device again
cbd1934
-            pOutDev->EnableOutput(true);
cbd1934
-            //Restore the original recorder
cbd1934
-            pOutDev->SetConnectMetaFile(pOrigRecorder);
cbd1934
-            //play back the scaled page
cbd1934
-            pMetaFile->Play(pOutDev);
cbd1934
-            delete pMetaFile;
cbd1934
         }
cbd1934
     }
cbd1934
 
cbd1934
@@ -562,6 +528,24 @@ sal_Bool SwViewShell::PrintOrPDFExport(
cbd1934
     // output device is now provided by a call from outside the Writer)
cbd1934
     pOutDev->Pop();
cbd1934
 
cbd1934
+    // fdo#36815 for comments in margins get the metafile we are printing to
cbd1934
+    // and then scale and vertically center that metafile down so that the
cbd1934
+    // comments will fit on the real page
cbd1934
+    GDIMetaFile *pRecorder = pOutDev->GetConnectMetaFile();
cbd1934
+    if (nPostItMode == POSTITS_INMARGINS && pRecorder)
cbd1934
+    {
cbd1934
+        pRecorder->Stop();
cbd1934
+        pRecorder->WindStart();
cbd1934
+        double fScale = 0.75;
cbd1934
+        long nOrigHeight = pOutDev->GetOutputSize().Height();
cbd1934
+        long nNewHeight = nOrigHeight*fScale;
cbd1934
+        long nShiftY = (nOrigHeight-nNewHeight)/2;
cbd1934
+        pRecorder->Scale(fScale, fScale);
cbd1934
+        pRecorder->WindStart();
cbd1934
+        pRecorder->Move(0, nShiftY, pOutDev->ImplGetDPIX(), pOutDev->ImplGetDPIY());
cbd1934
+        pRecorder->WindStart();
cbd1934
+    }
cbd1934
+
cbd1934
     return sal_True;
cbd1934
 }
cbd1934
 
cbd1934
-- 
cbd1934
1.9.0
cbd1934