76aab81
From 834c9363f67198e33880c2ee7bdd136b5558599d Mon Sep 17 00:00:00 2001
76aab81
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
76aab81
Date: Thu, 1 May 2014 17:10:21 +0100
76aab81
Subject: [PATCH] Resolves: fdo#78128 go back to using an interim metafile
76aab81
76aab81
this time we know that the other varient of "Move" doesn't
76aab81
handle pixel drawing stuff like the dpi-using one does.
76aab81
76aab81
and the move values have to be in 100TH_MM_MAP and
76aab81
with the true numbers of the write page size
76aab81
76aab81
Change-Id: I15fdb78797d8744702bec649024fedbf3e39b342
76aab81
---
76aab81
 sw/source/core/view/vprint.cxx | 68 +++++++++++++++++++++++++++++-------------
76aab81
 1 file changed, 48 insertions(+), 20 deletions(-)
76aab81
76aab81
diff --git a/sw/source/core/view/vprint.cxx b/sw/source/core/view/vprint.cxx
76aab81
index c9c7e42..6bc53e8 100644
76aab81
--- a/sw/source/core/view/vprint.cxx
76aab81
+++ b/sw/source/core/view/vprint.cxx
76aab81
@@ -455,6 +455,28 @@ sal_Bool SwViewShell::PrintOrPDFExport(
76aab81
     // output device is now provided by a call from outside the Writer)
76aab81
     pOutDev->Push();
76aab81
 
76aab81
+    // fdo#36815 for comments in margins print to a metafile
76aab81
+    // and then scale that metafile down so that the comments
76aab81
+    // will fit on the real page, and replay that scaled
76aab81
+    // output to the real outputdevice
76aab81
+    GDIMetaFile *pOrigRecorder(NULL);
76aab81
+    GDIMetaFile *pMetaFile(NULL);
76aab81
+    sal_Int16 nPostItMode = rPrintData.GetPrintPostIts();
76aab81
+    if (nPostItMode == POSTITS_INMARGINS)
76aab81
+    {
76aab81
+        //get and disable the existing recorder
76aab81
+        pOrigRecorder = pOutDev->GetConnectMetaFile();
76aab81
+        pOutDev->SetConnectMetaFile(NULL);
76aab81
+        // turn off output to the device
76aab81
+        pOutDev->EnableOutput(false);
76aab81
+        // just record the rendering commands to the metafile
76aab81
+        // instead
76aab81
+        pMetaFile = new GDIMetaFile;
76aab81
+        pMetaFile->SetPrefSize(pOutDev->GetOutputSize());
76aab81
+        pMetaFile->SetPrefMapMode(pOutDev->GetMapMode());
76aab81
+        pMetaFile->Record(pOutDev);
76aab81
+    }
76aab81
+
76aab81
     // Print/PDF export for (multi-)selection has already generated a
76aab81
     // temporary document with the selected text.
76aab81
     // (see XRenderable implementation in unotxdoc.cxx)
76aab81
@@ -470,8 +492,6 @@ sal_Bool SwViewShell::PrintOrPDFExport(
76aab81
         pDrawView->SetBufferedOverlayAllowed( false );
76aab81
     }
76aab81
 
76aab81
-    sal_Int16 nPostItMode = rPrintData.GetPrintPostIts();
76aab81
-
76aab81
     {   // additional scope so that the CurrShell is reset before destroying the shell
76aab81
 
76aab81
         SET_CURR_SHELL( pShell );
76aab81
@@ -519,6 +539,32 @@ sal_Bool SwViewShell::PrintOrPDFExport(
76aab81
             pPostItManager->CalcRects();
76aab81
             pPostItManager->LayoutPostIts();
76aab81
             pPostItManager->DrawNotesForPage(pOutDev, nPage-1);
76aab81
+
76aab81
+            //Stop recording now
76aab81
+            pMetaFile->Stop();
76aab81
+            pMetaFile->WindStart();
76aab81
+            //Enable output to the device again
76aab81
+            pOutDev->EnableOutput(true);
76aab81
+            //Restore the original recorder
76aab81
+            pOutDev->SetConnectMetaFile(pOrigRecorder);
76aab81
+
76aab81
+            //Now scale the recorded page down so the notes
76aab81
+            //will fit in the final page
76aab81
+            double fScale = 0.75;
76aab81
+            long nOrigHeight = pStPage->Frm().Height();
76aab81
+            long nNewHeight = nOrigHeight*fScale;
76aab81
+            long nShiftY = (nOrigHeight-nNewHeight)/2;
76aab81
+            pMetaFile->Scale( fScale, fScale );
76aab81
+            pMetaFile->WindStart();
76aab81
+            //Move the scaled page down to center it
76aab81
+            //the other variant of Move does not map pixels
76aab81
+            //back to the logical units correctly
cda87c9
+            pMetaFile->Move(0, TWIP_TO_MM100(nShiftY), pOutDev->ImplGetDPIX(), pOutDev->ImplGetDPIY());
76aab81
+            pMetaFile->WindStart();
76aab81
+
76aab81
+            //play back the scaled page
76aab81
+            pMetaFile->Play(pOutDev);
76aab81
+            delete pMetaFile;
76aab81
         }
76aab81
     }
76aab81
 
76aab81
@@ -528,24 +574,6 @@ sal_Bool SwViewShell::PrintOrPDFExport(
76aab81
     // output device is now provided by a call from outside the Writer)
76aab81
     pOutDev->Pop();
76aab81
 
76aab81
-    // fdo#36815 for comments in margins get the metafile we are printing to
76aab81
-    // and then scale and vertically center that metafile down so that the
76aab81
-    // comments will fit on the real page
76aab81
-    GDIMetaFile *pRecorder = pOutDev->GetConnectMetaFile();
76aab81
-    if (nPostItMode == POSTITS_INMARGINS && pRecorder)
76aab81
-    {
76aab81
-        pRecorder->Stop();
76aab81
-        pRecorder->WindStart();
76aab81
-        double fScale = 0.75;
76aab81
-        long nOrigHeight = pOutDev->GetOutputSize().Height();
76aab81
-        long nNewHeight = nOrigHeight*fScale;
76aab81
-        long nShiftY = (nOrigHeight-nNewHeight)/2;
76aab81
-        pRecorder->Scale(fScale, fScale);
76aab81
-        pRecorder->WindStart();
76aab81
-        pRecorder->Move(0, nShiftY, pOutDev->ImplGetDPIX(), pOutDev->ImplGetDPIY());
76aab81
-        pRecorder->WindStart();
76aab81
-    }
76aab81
-
76aab81
     return sal_True;
76aab81
 }
76aab81
 
76aab81
-- 
76aab81
1.9.0
76aab81