Kaydet (Commit) 2ff22c0b authored tarafından Muhammet Kara's avatar Muhammet Kara

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: I59f32bd29750f9ac759800893583308f29b8aad5
Reviewed-on: https://gerrit.libreoffice.org/71860
Tested-by: Jenkins
Reviewed-by: 's avatarMuhammet Kara <muhammet.kara@collabora.com>
üst e2c2136d
...@@ -49,15 +49,14 @@ public: ...@@ -49,15 +49,14 @@ public:
* */ * */
static void getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMetaFiles, static void getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMetaFiles,
std::vector<::Size>& aPageSizes, const sal_Int32& nPages, std::vector<::Size>& aPageSizes, const sal_Int32& nPages,
DocumentToGraphicRenderer& aRenderer, bool bIsWriter, DocumentToGraphicRenderer& aRenderer);
bool bIsCalc);
/* /*
* Creates one shape and one draw page for each gdimetafile, * Creates one shape and one draw page for each gdimetafile,
* and inserts the shapes into the newly created draw pages. * and inserts the shapes into the newly created draw pages.
* */ * */
static void addPagesToDraw(uno::Reference<XComponent>& xComponent, const sal_Int32& nPages, static void addPagesToDraw(uno::Reference<XComponent>& xComponent, const sal_Int32& nPages,
const std::vector<GDIMetaFile>& aMetaFiles, 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. * Makes the Redaction toolbar visible to the user.
* Meant to be called after converting a document to a Draw doc * Meant to be called after converting a document to a Draw doc
......
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
#include <vcl/graph.hxx> #include <vcl/graph.hxx>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <vcl/wmf.hxx>
#include <vcl/gdimetafiletools.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::lang; using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
...@@ -61,11 +64,24 @@ OUString SfxRedactionHelper::getStringParam(const SfxRequest& rReq, const sal_uI ...@@ -61,11 +64,24 @@ OUString SfxRedactionHelper::getStringParam(const SfxRequest& rReq, const sal_uI
return sStringParam; 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, void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMetaFiles,
std::vector<::Size>& aPageSizes, std::vector<::Size>& aPageSizes,
const sal_Int32& nPages, const sal_Int32& nPages,
DocumentToGraphicRenderer& aRenderer, DocumentToGraphicRenderer& aRenderer)
bool bIsWriter, bool bIsCalc)
{ {
for (sal_Int32 nPage = 1; nPage <= nPages; ++nPage) for (sal_Int32 nPage = 1; nPage <= nPages; ++nPage)
{ {
...@@ -75,12 +91,10 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMeta ...@@ -75,12 +91,10 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMeta
::Size aCalcPageContentSize; ::Size aCalcPageContentSize;
::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage, &aLogicPos, &aCalcPageLogicPos, ::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage, &aLogicPos, &aCalcPageLogicPos,
&aCalcPageContentSize); &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); aPageSizes.push_back(aLogic);
Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aTargetSize, Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aDocumentSizePixel,
COL_TRANSPARENT, true); COL_TRANSPARENT, true);
auto& rGDIMetaFile = const_cast<GDIMetaFile&>(aGraphic.GetGDIMetaFile()); auto& rGDIMetaFile = const_cast<GDIMetaFile&>(aGraphic.GetGDIMetaFile());
...@@ -88,24 +102,11 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMeta ...@@ -88,24 +102,11 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMeta
// will be correct in MM. // will be correct in MM.
MapMode aMapMode; MapMode aMapMode;
aMapMode.SetMapUnit(MapUnit::Map100thMM); 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.SetPrefMapMode(aMapMode);
rGDIMetaFile.SetPrefSize(aLogic);
if (bIsCalc) fixMetaFile(rGDIMetaFile);
{
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); aMetaFiles.push_back(rGDIMetaFile);
} }
...@@ -114,7 +115,7 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMeta ...@@ -114,7 +115,7 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMeta
void SfxRedactionHelper::addPagesToDraw(uno::Reference<XComponent>& xComponent, void SfxRedactionHelper::addPagesToDraw(uno::Reference<XComponent>& xComponent,
const sal_Int32& nPages, const sal_Int32& nPages,
const std::vector<GDIMetaFile>& aMetaFiles, const std::vector<GDIMetaFile>& aMetaFiles,
const std::vector<::Size>& aPageSizes, bool bIsCalc) const std::vector<::Size>& aPageSizes)
{ {
// Access the draw pages // Access the draw pages
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY); uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY);
...@@ -146,16 +147,11 @@ void SfxRedactionHelper::addPagesToDraw(uno::Reference<XComponent>& xComponent, ...@@ -146,16 +147,11 @@ void SfxRedactionHelper::addPagesToDraw(uno::Reference<XComponent>& xComponent,
xShapeProperySet->setPropertyValue("MoveProtect", uno::Any(true)); xShapeProperySet->setPropertyValue("MoveProtect", uno::Any(true));
xShapeProperySet->setPropertyValue("SizeProtect", uno::Any(true)); xShapeProperySet->setPropertyValue("SizeProtect", uno::Any(true));
// Set size and position // Set size
xShape->setSize( xShape->setSize(
awt::Size(rGDIMetaFile.GetPrefSize().Width(), rGDIMetaFile.GetPrefSize().Height())); awt::Size(rGDIMetaFile.GetPrefSize().Width(), rGDIMetaFile.GetPrefSize().Height()));
xPage->add(xShape); 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 // Remove the extra page at the beginning
......
...@@ -556,15 +556,12 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) ...@@ -556,15 +556,12 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
DocumentToGraphicRenderer aRenderer(xSourceDoc, false); DocumentToGraphicRenderer aRenderer(xSourceDoc, false);
bool bIsWriter = aRenderer.isWriter();
bool bIsCalc = aRenderer.isCalc();
sal_Int32 nPages = aRenderer.getPageCount(); sal_Int32 nPages = aRenderer.getPageCount();
std::vector< GDIMetaFile > aMetaFiles; std::vector< GDIMetaFile > aMetaFiles;
std::vector< ::Size > aPageSizes; std::vector< ::Size > aPageSizes;
// Convert the pages of the document to gdimetafiles // 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. // Create an empty Draw component.
uno::Reference<frame::XDesktop2> xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext()); uno::Reference<frame::XDesktop2> xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext());
...@@ -572,7 +569,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) ...@@ -572,7 +569,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
uno::Reference<lang::XComponent> xComponent = xComponentLoader->loadComponentFromURL("private:factory/sdraw", "_default", 0, {}); uno::Reference<lang::XComponent> xComponent = xComponentLoader->loadComponentFromURL("private:factory/sdraw", "_default", 0, {});
// Add the doc pages to the new draw document // 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 // Show the Redaction toolbar
SfxViewFrame* pViewFrame = SfxViewFrame::Current(); SfxViewFrame* pViewFrame = SfxViewFrame::Current();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment