diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-05-13 17:59:34 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-05-13 21:29:25 +0200 |
commit | 2abe9837deee3823c7928a76b5b2f94f1464f1a3 (patch) | |
tree | 6aba4ef8158d9b0f555581d2628bea4ea2818eb1 /writerfilter/source | |
parent | cbc9c1ef729a09abdda97f74469d4d600ae6974b (diff) |
DOCX import: fix interaction between the crop and the wrap polygon of images
Word first applies the crop, then applies the wrap polygon on the
remaining visible part of the image.
Writer applies the crop on the original bitmap, and even has explicit
code to make sure the uncropped bitmap is used for the wrap polygon, see
how SwFlyFrame::GetContour() calls SwNoTextFrame::GetGrfArea(), which
will extend the resulting size based on cropping.
Fix the problem by moving and scaling the wrap polygon, so it ends up
where it would in Word.
Also adapt testFdo76803, which had a similar crop+wrap polygon case, but
the different there is quite small.
Change-Id: Iab2adaa81a33eb04e1806b17ed129ac50f5d2aa3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94149
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'writerfilter/source')
-rw-r--r-- | writerfilter/source/dmapper/GraphicImport.cxx | 11 | ||||
-rw-r--r-- | writerfilter/source/dmapper/WrapPolygonHandler.cxx | 18 | ||||
-rw-r--r-- | writerfilter/source/dmapper/WrapPolygonHandler.hxx | 7 |
3 files changed, 36 insertions, 0 deletions
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; }; |