summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-05-14 18:02:23 +0200
committerMiklos Vajna <vmiklos@collabora.com>2020-05-18 17:00:06 +0200
commit2e8fde3485f07d48d61b6040961c394e2121720b (patch)
tree8e52e8609f8dca5a24d17b1961aadf0e6fcbc491
parent83526f667416731de462418ee12c76dfbd6385cf (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. Conflicts: sw/source/filter/ww8/docxsdrexport.cxx writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx (cherry picked from commit c68b458514b35cae70c9a6630e06f46a867aa3b9) Change-Id: Ieef18aad3c76f7945c7348201b07bcb27a4cd48d
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport.cxx28
-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
-rw-r--r--writerfilter/source/dmapper/WrapPolygonHandler.cxx3
7 files changed, 50 insertions, 16 deletions
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 513a5d64a7d4..fdcd8af60d0d 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -882,8 +882,13 @@ DECLARE_OOXMLIMPORT_TEST(testFdo75722dml, "fdo75722-dml.docx")
CPPUNIT_ASSERT_EQUAL(sal_Int64(3128), nRot);
}
-DECLARE_OOXMLIMPORT_TEST(testFdo76803, "fdo76803.docx")
+DECLARE_OOXMLEXPORT_TEST(testFdo76803, "fdo76803.docx")
{
+ if (!mbExported)
+ {
+ return;
+ }
+
// The ContourPolyPolygon was wrong
uno::Reference<beans::XPropertySet> xPropertySet(getShape(1), uno::UNO_QUERY);
@@ -898,16 +903,20 @@ DECLARE_OOXMLIMPORT_TEST(testFdo76803, "fdo76803.docx")
CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), aPolygon.count());
- CPPUNIT_ASSERT_EQUAL(double(-162), aPolygon.getB2DPoint(0).getX());
+ CPPUNIT_ASSERT_EQUAL(double(-149), aPolygon.getB2DPoint(0).getX());
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: -35
+ // - Actual : -67
+ // i.e. the cropping did not influence the wrap polygon during export.
CPPUNIT_ASSERT_EQUAL(double(-35), aPolygon.getB2DPoint(0).getY());
- CPPUNIT_ASSERT_EQUAL(double(-162), aPolygon.getB2DPoint(1).getX());
- CPPUNIT_ASSERT_EQUAL(double(3510), aPolygon.getB2DPoint(1).getY());
+ CPPUNIT_ASSERT_EQUAL(double(-149), aPolygon.getB2DPoint(1).getX());
+ CPPUNIT_ASSERT_EQUAL(double(3511), aPolygon.getB2DPoint(1).getY());
- CPPUNIT_ASSERT_EQUAL(double(16892), aPolygon.getB2DPoint(2).getX());
- CPPUNIT_ASSERT_EQUAL(double(3510), aPolygon.getB2DPoint(2).getY());
+ CPPUNIT_ASSERT_EQUAL(double(16889), aPolygon.getB2DPoint(2).getX());
+ CPPUNIT_ASSERT_EQUAL(double(3511), aPolygon.getB2DPoint(2).getY());
- CPPUNIT_ASSERT_EQUAL(double(16892), aPolygon.getB2DPoint(3).getX());
+ CPPUNIT_ASSERT_EQUAL(double(16889), aPolygon.getB2DPoint(3).getX());
CPPUNIT_ASSERT_EQUAL(double(-35), aPolygon.getB2DPoint(3).getY());
}
@@ -1624,13 +1633,14 @@ DECLARE_OOXMLIMPORT_TEST(testWrapPolyCrop, "wrap-poly-crop.docx")
// 10582, the lower 33% of the graphic is cropped, and the wrap polygon covers the middle third
// of the area vertically. Which means 10582*2/3 = 7054.67 is the cropped height, and the top of
// the middle third is 2351.55.
+ // Then there is a 15 twips shift from the origo, so it's 2351.55 + 26.46 = 2378.01 in mm100.
//
// Without the accompanying fix in place, this test would have failed with:
- // - Expected: 2361
+ // - Expected: 2368
// - Actual : 3542
// i.e. the wrap polygon covered a larger-than-correct area, which end the end means 3 lines
// were wrapping around the image, not only 2 as Word does it.
- CPPUNIT_ASSERT_EQUAL(2361., aPolygon.getB2DPoint(0).getY());
+ CPPUNIT_ASSERT_EQUAL(2368., aPolygon.getB2DPoint(0).getY());
}
DECLARE_OOXMLIMPORT_TEST(testTdf117843, "tdf117843.docx")
diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx
index 459811f0a56b..0a690a9ba00f 100644
--- a/sw/source/filter/ww8/docxsdrexport.cxx
+++ b/sw/source/filter/ww8/docxsdrexport.cxx
@@ -700,7 +700,8 @@ void DocxSdrExport::startDMLAnchorInline(const SwFrameFormat* pFrameFormat, cons
m_pImpl->m_pSerializer->startElementNS(XML_wp, XML_wrapPolygon,
XML_edited, "0",
FSEND);
- 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->m_pSerializer->singleElementNS(XML_wp, (i == 0 ? XML_start : XML_lineTo),
XML_x, OString::number(aPoly[i].X()),
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 93776963dadb..b1036b59d6b3 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -4131,8 +4131,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 bf841d6d977a..4724194c6c8c 100644
--- a/sw/source/filter/ww8/writerhelper.cxx
+++ b/sw/source/filter/ww8/writerhelper.cxx
@@ -55,6 +55,7 @@
#include <IDocumentStylePoolAccess.hxx>
#include <IDocumentMarkAccess.hxx>
#include <IMark.hxx>
+#include <grfatr.hxx>
using namespace com::sun::star;
@@ -667,10 +668,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 27dbd1b7b13c..aff22fb84aa4 100644
--- a/sw/source/filter/ww8/writerhelper.hxx
+++ b/sw/source/filter/ww8/writerhelper.hxx
@@ -613,7 +613,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 e1655946c80c..84fd91333033 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -2153,7 +2153,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);
diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.cxx b/writerfilter/source/dmapper/WrapPolygonHandler.cxx
index e3bc6e4e2c94..3885427ee236 100644
--- a/writerfilter/source/dmapper/WrapPolygonHandler.cxx
+++ b/writerfilter/source/dmapper/WrapPolygonHandler.cxx
@@ -20,6 +20,7 @@
#include <com/sun/star/drawing/PointSequence.hpp>
#include <com/sun/star/text/GraphicCrop.hpp>
#include <comphelper/sequence.hxx>
+#include <tools/mapunit.hxx>
#include <ooxml/resourceids.hxx>
@@ -97,7 +98,7 @@ WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygon(const awt::Size & rSr
const long nWrap100Percent = 21600;
Fraction aMove(nWrap100Percent, rSrcSize.Width);
- aMove = aMove * Fraction(15, 1);
+ aMove = aMove * Fraction(convertTwipToMm100(15), 1);
awt::Point aMovePoint(aMove.operator long(), 0);
pResult = move(aMovePoint);