summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/CppunitTest_writerfilter_dmapper.mk1
-rw-r--r--writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx30
-rw-r--r--writerfilter/qa/cppunittests/dmapper/data/wrap-poly-crop.docxbin0 -> 15018 bytes
-rw-r--r--writerfilter/source/dmapper/GraphicImport.cxx11
-rw-r--r--writerfilter/source/dmapper/WrapPolygonHandler.cxx18
-rw-r--r--writerfilter/source/dmapper/WrapPolygonHandler.hxx7
6 files changed, 67 insertions, 0 deletions
diff --git a/writerfilter/CppunitTest_writerfilter_dmapper.mk b/writerfilter/CppunitTest_writerfilter_dmapper.mk
index 270844557d3b..c29b3b9e1c39 100644
--- a/writerfilter/CppunitTest_writerfilter_dmapper.mk
+++ b/writerfilter/CppunitTest_writerfilter_dmapper.mk
@@ -25,6 +25,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,writerfilter_dmapper, \
))
$(eval $(call gb_CppunitTest_use_libraries,writerfilter_dmapper, \
+ basegfx \
comphelper \
cppu \
oox \
diff --git a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
index 590a93273e92..7648d9e9420d 100644
--- a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
@@ -15,6 +15,9 @@
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/container/XNamed.hpp>
#include <com/sun/star/text/RelOrientation.hpp>
+#include <com/sun/star/drawing/PointSequenceSequence.hpp>
+
+#include <basegfx/polygon/b2dpolypolygontools.hxx>
using namespace ::com::sun::star;
@@ -134,6 +137,33 @@ CPPUNIT_TEST_FIXTURE(Test, testRelfromhInsidemargin)
xShape->getPropertyValue("PageToggle") >>= bPageToggle;
CPPUNIT_ASSERT(bPageToggle);
}
+
+CPPUNIT_TEST_FIXTURE(Test, testWrapPolyCrop)
+{
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "wrap-poly-crop.docx";
+ getComponent() = loadFromDesktop(aURL);
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(getComponent(), uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
+ uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+ drawing::PointSequenceSequence aContour;
+ xShape->getPropertyValue("ContourPolyPolygon") >>= aContour;
+ auto aPolyPolygon = basegfx::utils::UnoPointSequenceSequenceToB2DPolyPolygon(aContour);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt32(1), aPolyPolygon.count());
+ auto aPolygon = aPolyPolygon.getB2DPolygon(0);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), aPolygon.count());
+
+ // Ideally this would be 2352, because the graphic size in mm100, using the graphic's DPI is
+ // 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.
+ //
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 2361
+ // - 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());
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/qa/cppunittests/dmapper/data/wrap-poly-crop.docx b/writerfilter/qa/cppunittests/dmapper/data/wrap-poly-crop.docx
new file mode 100644
index 000000000000..1835a130d740
--- /dev/null
+++ b/writerfilter/qa/cppunittests/dmapper/data/wrap-poly-crop.docx
Binary files differ
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 74ce96871499..73333b23e790 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -1404,6 +1404,17 @@ uno::Reference<text::XTextContent> GraphicImport::createGraphicObject(uno::Refer
pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygonPixel(aGraphicSize);
}
}
+
+ text::GraphicCrop aGraphicCrop;
+ xShapeProps->getPropertyValue("GraphicCrop") >>= aGraphicCrop;
+ if (aGraphicCrop.Top != 0 || aGraphicCrop.Bottom != 0 || aGraphicCrop.Left != 0
+ || aGraphicCrop.Right != 0)
+ {
+ // Word's wrap polygon deals with a canvas which has the size of the already
+ // cropped graphic, correct our polygon to have the same render result.
+ pCorrected = pCorrected->correctCrop(aGraphicSize, aGraphicCrop);
+ }
+
if (pCorrected)
{
aContourPolyPolygon <<= pCorrected->getPointSequenceSequence();
diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.cxx b/writerfilter/source/dmapper/WrapPolygonHandler.cxx
index 7d2526c0bbaf..00b8699972bc 100644
--- a/writerfilter/source/dmapper/WrapPolygonHandler.cxx
+++ b/writerfilter/source/dmapper/WrapPolygonHandler.cxx
@@ -18,6 +18,7 @@
*/
#include <com/sun/star/drawing/PointSequence.hpp>
+#include <com/sun/star/text/GraphicCrop.hpp>
#include <comphelper/sequence.hxx>
#include <ooxml/resourceids.hxx>
@@ -135,6 +136,23 @@ WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygonPixel(const awt::Size
return pResult;
}
+WrapPolygon::Pointer_t WrapPolygon::correctCrop(const awt::Size& rGraphicSize,
+ const text::GraphicCrop& rGraphicCrop)
+{
+ WrapPolygon::Pointer_t pResult;
+
+ Fraction aScaleX(rGraphicSize.Width - rGraphicCrop.Left - rGraphicCrop.Right,
+ rGraphicSize.Width);
+ Fraction aScaleY(rGraphicSize.Height - rGraphicCrop.Top - rGraphicCrop.Bottom,
+ rGraphicSize.Height);
+ pResult = scale(aScaleX, aScaleY);
+
+ awt::Point aMove(rGraphicCrop.Left, rGraphicCrop.Top);
+ pResult = pResult->move(aMove);
+
+ return pResult;
+}
+
drawing::PointSequenceSequence WrapPolygon::getPointSequenceSequence() const
{
drawing::PointSequenceSequence aPolyPolygon(1);
diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.hxx b/writerfilter/source/dmapper/WrapPolygonHandler.hxx
index 6b8b458e616c..e9e58dc0907b 100644
--- a/writerfilter/source/dmapper/WrapPolygonHandler.hxx
+++ b/writerfilter/source/dmapper/WrapPolygonHandler.hxx
@@ -25,6 +25,11 @@
#include <tools/fract.hxx>
#include <vector>
+namespace com::sun::star::text
+{
+struct GraphicCrop;
+}
+
namespace writerfilter {
namespace dmapper {
@@ -51,6 +56,8 @@ public:
WrapPolygon::Pointer_t scale(const Fraction & rFractionX, const Fraction & rFractionY);
WrapPolygon::Pointer_t correctWordWrapPolygon(const css::awt::Size & rSrcSize);
WrapPolygon::Pointer_t correctWordWrapPolygonPixel(const css::awt::Size & rSrcSize);
+ WrapPolygon::Pointer_t correctCrop(const css::awt::Size& rGraphicSize,
+ const css::text::GraphicCrop& rGraphicCrop);
css::drawing::PointSequenceSequence getPointSequenceSequence() const;
};