summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-05-14 18:02:23 +0200
committerMiklos Vajna <vmiklos@collabora.com>2020-05-14 21:46:03 +0200
commitc68b458514b35cae70c9a6630e06f46a867aa3b9 (patch)
tree16b9317fb4eace91a5ad000be1dc05fb09b56305 /sw/source
parentda10ce7452554a6c2ea6f664a3f87b8125369d06 (diff)
DOCX export: fix interaction between the crop and the wrap polygon of image
If the wrap polygon is influenced by crop at import time, we need to do the opposite at export time. Do this for RTF and DOCX, where there is matching import code in writerfilter/, leave DOC alone for now. Test this by changing testFdo76803 into an export test, then seeing how the first point's Y position fails and fixing up the exporter, so we get back the old good value. Change-Id: Ieef18aad3c76f7945c7348201b07bcb27a4cd48d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94246 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/filter/ww8/docxsdrexport.cxx3
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.cxx4
-rw-r--r--sw/source/filter/ww8/writerhelper.cxx24
-rw-r--r--sw/source/filter/ww8/writerhelper.hxx2
-rw-r--r--sw/source/filter/ww8/wrtw8esh.cxx2
5 files changed, 29 insertions, 6 deletions
diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx
index 2ae2ab3bd748..e0cf42586727 100644
--- a/sw/source/filter/ww8/docxsdrexport.cxx
+++ b/sw/source/filter/ww8/docxsdrexport.cxx
@@ -781,7 +781,8 @@ void DocxSdrExport::startDMLAnchorInline(const SwFrameFormat* pFrameFormat, cons
"bothSides");
m_pImpl->getSerializer()->startElementNS(XML_wp, XML_wrapPolygon, XML_edited, "0");
- tools::Polygon aPoly = sw::util::CorrectWordWrapPolygonForExport(*pPolyPoly, pNd);
+ tools::Polygon aPoly = sw::util::CorrectWordWrapPolygonForExport(
+ *pPolyPoly, pNd, /*bCorrectCrop=*/true);
for (sal_uInt16 i = 0; i < aPoly.GetSize(); ++i)
m_pImpl->getSerializer()->singleElementNS(
XML_wp, (i == 0 ? XML_start : XML_lineTo), XML_x,
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index bfbb71a23f84..10d38a569e92 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -4226,8 +4226,8 @@ void RtfAttributeOutput::FlyFrameGraphic(const SwFlyFrameFormat* pFlyFrameFormat
const tools::PolyPolygon* pPolyPoly = pNd->HasContour();
if (pPolyPoly && pPolyPoly->Count())
{
- tools::Polygon aPoly
- = sw::util::CorrectWordWrapPolygonForExport(*pPolyPoly, pNd);
+ tools::Polygon aPoly = sw::util::CorrectWordWrapPolygonForExport(
+ *pPolyPoly, pNd, /*bCorrectCrop=*/true);
OStringBuffer aVerticies;
for (sal_uInt16 i = 0; i < aPoly.GetSize(); ++i)
aVerticies.append(";(")
diff --git a/sw/source/filter/ww8/writerhelper.cxx b/sw/source/filter/ww8/writerhelper.cxx
index 9da717b81fe1..e52fa5412dc7 100644
--- a/sw/source/filter/ww8/writerhelper.cxx
+++ b/sw/source/filter/ww8/writerhelper.cxx
@@ -54,6 +54,7 @@
#include <IDocumentStylePoolAccess.hxx>
#include <IDocumentMarkAccess.hxx>
#include <IMark.hxx>
+#include <grfatr.hxx>
using namespace com::sun::star;
@@ -645,10 +646,31 @@ namespace sw
}
}
- tools::Polygon CorrectWordWrapPolygonForExport(const tools::PolyPolygon& rPolyPoly, const SwNoTextNode* pNd)
+ tools::Polygon CorrectWordWrapPolygonForExport(const tools::PolyPolygon& rPolyPoly, const SwNoTextNode* pNd, bool bCorrectCrop)
{
tools::Polygon aPoly(PolygonFromPolyPolygon(rPolyPoly));
const Size &rOrigSize = pNd->GetGraphic().GetPrefSize();
+
+ const SwAttrSet* pAttrSet = pNd->GetpSwAttrSet();
+ if (bCorrectCrop && pAttrSet)
+ {
+ if (pAttrSet->HasItem(RES_GRFATR_CROPGRF))
+ {
+ // Word's wrap polygon deals with a canvas which has the size of the already
+ // cropped graphic, do the opposite of correctCrop() in writerfilter/.
+ const SwCropGrf& rCrop = pAttrSet->GetCropGrf();
+ sal_Int32 nCropLeft = convertTwipToMm100(rCrop.GetLeft());
+ sal_Int32 nCropRight = convertTwipToMm100(rCrop.GetRight());
+ sal_Int32 nCropTop = convertTwipToMm100(rCrop.GetTop());
+ sal_Int32 nCropBottom = convertTwipToMm100(rCrop.GetBottom());
+ aPoly.Move(-nCropLeft, -nCropTop);
+
+ Fraction aScaleX(rOrigSize.getWidth(), rOrigSize.getWidth() - nCropLeft - nCropRight);
+ Fraction aScaleY(rOrigSize.getHeight(), rOrigSize.getHeight() - nCropTop - nCropBottom);
+ aPoly.Scale(double(aScaleX), double(aScaleY));
+ }
+ }
+
Fraction aMapPolyX(ww::nWrap100Percent, rOrigSize.Width());
Fraction aMapPolyY(ww::nWrap100Percent, rOrigSize.Height());
aPoly.Scale(double(aMapPolyX), double(aMapPolyY));
diff --git a/sw/source/filter/ww8/writerhelper.hxx b/sw/source/filter/ww8/writerhelper.hxx
index 9049b37f4616..f9d186ec58df 100644
--- a/sw/source/filter/ww8/writerhelper.hxx
+++ b/sw/source/filter/ww8/writerhelper.hxx
@@ -608,7 +608,7 @@ namespace sw
tools::Polygon PolygonFromPolyPolygon(const tools::PolyPolygon &rPolyPoly);
/// Undo all scaling / move tricks of the wrap polygon done during import.
- tools::Polygon CorrectWordWrapPolygonForExport(const tools::PolyPolygon& rPolyPoly, const SwNoTextNode* pNd);
+ tools::Polygon CorrectWordWrapPolygonForExport(const tools::PolyPolygon& rPolyPoly, const SwNoTextNode* pNd, bool bCorrectCrop);
/** Make setting a drawing object's layer in a Writer document easy
diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx
index 9966e0899edb..0c4e6c9d2692 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -2105,7 +2105,7 @@ sal_Int32 SwEscherEx::WriteFlyFrameAttr(const SwFrameFormat& rFormat, MSO_SPT eS
const tools::PolyPolygon *pPolyPoly = pNd->HasContour();
if (pPolyPoly && pPolyPoly->Count())
{
- tools::Polygon aPoly = CorrectWordWrapPolygonForExport(*pPolyPoly, pNd);
+ tools::Polygon aPoly = CorrectWordWrapPolygonForExport(*pPolyPoly, pNd, /*bCorrectCrop=*/false);
SvMemoryStream aPolyDump;
aPolyDump.SetEndian(SvStreamEndian::LITTLE);