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