sfx2/inc/SfxRedactionHelper.hxx | 5 +-- sfx2/source/doc/SfxRedactionHelper.cxx | 52 +++++++++++++++------------------ sfx2/source/doc/objserv.cxx | 7 +--- 3 files changed, 28 insertions(+), 36 deletions(-)
New commits: commit dd3f2fee98a77739d2036119303520e6cf3e5934 Author: Muhammet Kara <[email protected]> AuthorDate: Fri May 3 22:07:59 2019 +0300 Commit: Muhammet Kara <[email protected]> CommitDate: Wed May 8 13:26:53 2019 +0200 tdf#125135: Standardize content placement for redaction Correct the position & size by roundtrip conversion from/to wmf as a temporary solution. Simplify a bit. Change-Id: I6515571bb85134a4c48f00397c7554d190633575 Reviewed-on: https://gerrit.libreoffice.org/71860 Tested-by: Jenkins Reviewed-by: Muhammet Kara <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/71932 Tested-by: Muhammet Kara <[email protected]> diff --git a/sfx2/inc/SfxRedactionHelper.hxx b/sfx2/inc/SfxRedactionHelper.hxx index 1cd653650557..8b1bdd57e247 100644 --- a/sfx2/inc/SfxRedactionHelper.hxx +++ b/sfx2/inc/SfxRedactionHelper.hxx @@ -49,15 +49,14 @@ public: * */ static void getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMetaFiles, std::vector<::Size>& aPageSizes, const sal_Int32& nPages, - DocumentToGraphicRenderer& aRenderer, bool bIsWriter, - bool bIsCalc); + DocumentToGraphicRenderer& aRenderer); /* * Creates one shape and one draw page for each gdimetafile, * and inserts the shapes into the newly created draw pages. * */ static void addPagesToDraw(uno::Reference<XComponent>& xComponent, const sal_Int32& nPages, const std::vector<GDIMetaFile>& aMetaFiles, - const std::vector<::Size>& aPageSizes, bool bIsCalc); + const std::vector<::Size>& aPageSizes); /* * Makes the Redaction toolbar visible to the user. * Meant to be called after converting a document to a Draw doc diff --git a/sfx2/source/doc/SfxRedactionHelper.cxx b/sfx2/source/doc/SfxRedactionHelper.cxx index 5edc4123cbb7..f31e6eb2d73b 100644 --- a/sfx2/source/doc/SfxRedactionHelper.cxx +++ b/sfx2/source/doc/SfxRedactionHelper.cxx @@ -27,6 +27,9 @@ #include <vcl/gdimtf.hxx> #include <vcl/graph.hxx> +#include <vcl/wmf.hxx> +#include <vcl/gdimetafiletools.hxx> + using namespace ::com::sun::star; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::uno; @@ -60,11 +63,24 @@ OUString SfxRedactionHelper::getStringParam(const SfxRequest& rReq, const sal_uI return sStringParam; } +namespace +{ +void fixMetaFile(GDIMetaFile& tmpMtf) +{ + SvMemoryStream aDestStrm(65535, 65535); + ConvertGDIMetaFileToWMF(tmpMtf, aDestStrm, nullptr, false); + aDestStrm.Seek(0); + + tmpMtf.Clear(); + + ReadWindowMetafile(aDestStrm, tmpMtf); +} +} + void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMetaFiles, std::vector<::Size>& aPageSizes, const sal_Int32& nPages, - DocumentToGraphicRenderer& aRenderer, - bool bIsWriter, bool bIsCalc) + DocumentToGraphicRenderer& aRenderer) { for (sal_Int32 nPage = 1; nPage <= nPages; ++nPage) { @@ -74,37 +90,22 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMeta ::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); aPageSizes.push_back(aLogic); - Graphic aGraphic - = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aTargetSize, COL_TRANSPARENT); + Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aDocumentSizePixel, + COL_TRANSPARENT); auto& rGDIMetaFile = const_cast<GDIMetaFile&>(aGraphic.GetGDIMetaFile()); // Set preferred map unit and size on the metafile, so the Shape size // will be correct in MM. MapMode aMapMode; aMapMode.SetMapUnit(MapUnit::Map100thMM); - // FIXME: This is a temporary hack. Need to figure out a proper way to derive these magic numbers. - 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); + fixMetaFile(rGDIMetaFile); aMetaFiles.push_back(rGDIMetaFile); } @@ -113,7 +114,7 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMeta void SfxRedactionHelper::addPagesToDraw(uno::Reference<XComponent>& xComponent, const sal_Int32& nPages, const std::vector<GDIMetaFile>& aMetaFiles, - const std::vector<::Size>& aPageSizes, bool bIsCalc) + const std::vector<::Size>& aPageSizes) { // Access the draw pages uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY); @@ -145,16 +146,11 @@ void SfxRedactionHelper::addPagesToDraw(uno::Reference<XComponent>& xComponent, xShapeProperySet->setPropertyValue("MoveProtect", uno::Any(true)); xShapeProperySet->setPropertyValue("SizeProtect", uno::Any(true)); - // Set size and position + // Set size 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 diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 8d1dc78c0ff8..1523f43a1724 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -541,15 +541,12 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) DocumentToGraphicRenderer aRenderer(xSourceDoc, false); - bool bIsWriter = aRenderer.isWriter(); - bool bIsCalc = aRenderer.isCalc(); - sal_Int32 nPages = aRenderer.getPageCount(); std::vector< GDIMetaFile > aMetaFiles; std::vector< ::Size > aPageSizes; // Convert the pages of the document to gdimetafiles - SfxRedactionHelper::getPageMetaFilesFromDoc(aMetaFiles, aPageSizes, nPages, aRenderer, bIsWriter, bIsCalc); + SfxRedactionHelper::getPageMetaFilesFromDoc(aMetaFiles, aPageSizes, nPages, aRenderer); // Create an empty Draw component. uno::Reference<frame::XDesktop2> xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext()); @@ -557,7 +554,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) uno::Reference<lang::XComponent> xComponent = xComponentLoader->loadComponentFromURL("private:factory/sdraw", "_default", 0, {}); // Add the doc pages to the new draw document - SfxRedactionHelper::addPagesToDraw(xComponent, nPages, aMetaFiles, aPageSizes, bIsCalc); + SfxRedactionHelper::addPagesToDraw(xComponent, nPages, aMetaFiles, aPageSizes); // Show the Redaction toolbar SfxViewFrame* pViewFrame = SfxViewFrame::Current(); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
