diff options
author | Muhammet Kara <muhammet.kara@collabora.com> | 2019-01-18 14:07:56 +0300 |
---|---|---|
committer | Muhammet Kara <muhammet.kara@collabora.com> | 2019-01-19 08:21:09 +0100 |
commit | 189f4d3b3ee5807e1140b6c417a3b2687dfdd2a3 (patch) | |
tree | 427e41a98175e4d210de9a81ea298fc304ecf158 /sfx2 | |
parent | 16fffbe869785dffeda9ae0d9f7c18a6559a2093 (diff) |
Redaction: Adjust offset for multiple Calc pages
* Add an enum and some methods to DocumentToGraphicRenderer
to differentiate between the doc/module types:
isWriter(), isCalc(), isImpress()
* Put some checks for module/doc type
* The result seems ok for a Calc document of multiple sheets
with hundreds of pages
Change-Id: Idf3e1966d4239df30a48a947a95c9085c25ee1bb
Reviewed-on: https://gerrit.libreoffice.org/66605
Tested-by: Jenkins
Reviewed-by: Muhammet Kara <muhammet.kara@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/doc/objserv.cxx | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index ff6755257000..defa5ea0e483 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -549,7 +549,16 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) uno::Reference< lang::XComponent > xSourceDoc( xModel ); - DocumentToGraphicRenderer aRenderer(xSourceDoc, /*bSelectionOnly=*/false); + DocumentToGraphicRenderer aRenderer(xSourceDoc, false); + + bool bIsWriter = aRenderer.isWriter(); + bool bIsCalc = aRenderer.isCalc(); + + if (!bIsWriter && !bIsCalc) + { + SAL_WARN( "sfx.doc", "Redaction is supported only for Writer and Calc! (for now...)"); + return; + } sal_Int32 nPages = aRenderer.getPageCount(); @@ -559,7 +568,9 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) { ::Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(nPage); ::Point aLogicPos; - ::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage, &aLogicPos); + ::Point aCalcPageLogicPos; + ::Size aCalcPageContentSize; + ::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage, &aLogicPos, &aCalcPageLogicPos, &aCalcPageContentSize); // FIXME: This is a temporary hack. Need to figure out a proper way to derive this scale factor. ::Size aTargetSize(aDocumentSizePixel.Width() * 1.23, aDocumentSizePixel.Height() * 1.23); @@ -572,9 +583,21 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) MapMode aMapMode; aMapMode.SetMapUnit(MapUnit::Map100thMM); // FIXME: This is a temporary hack. Need to figure out a proper way to derive these magic numbers. - aMapMode.SetOrigin(::Point(-(aLogicPos.getX() - 512) * 1.53, -((aLogicPos.getY() - 501)* 1.53 + (nPage-1)*740 ))); + if (bIsWriter) + aMapMode.SetOrigin(::Point(-(aLogicPos.getX() - 512) * 1.53, -((aLogicPos.getY() - 501)* 1.53 + (nPage-1)*740 ))); + else if (bIsCalc) + rGDIMetaFile.Scale(0.566, 0.566); + rGDIMetaFile.SetPrefMapMode(aMapMode); - rGDIMetaFile.SetPrefSize(aLogic); + + if (bIsCalc) + { + double aWidthRatio = static_cast<double>(aCalcPageContentSize.Width()) / aLogic.Width(); + // FIXME: Get rid of these magic numbers. Also watch for floating point rounding errors + rGDIMetaFile.Move(-2400 + aCalcPageLogicPos.X() * (aWidthRatio - 0.0887), -3300 + aCalcPageLogicPos.Y() * 0.64175); + } + + rGDIMetaFile.SetPrefSize( bIsCalc ? aCalcPageContentSize : aLogic ); aMetaFiles.push_back(rGDIMetaFile); } @@ -608,6 +631,11 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) xShape->setSize(awt::Size(rGDIMetaFile.GetPrefSize().Width(),rGDIMetaFile.GetPrefSize().Height()) ); xPage->add(xShape); + + // Shapes from Calc have the size of the content instead of the whole standard page (like A4) + // so it needs positioning on the draw page + if (bIsCalc) + xShape->setPosition(awt::Point(1000,1000)); } // Remove the extra page at the beginning |