[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - 2 commits - sw/qa sw/source writerfilter/CppunitTest_writerfilter_dmapper.mk writerfilter/qa writerfilter/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri May 15 08:51:37 UTC 2020


 sw/qa/extras/ooxmlimport/ooxmlimport.cxx                      |   22 ++++---
 sw/source/filter/ww8/docxsdrexport.cxx                        |    3 -
 sw/source/filter/ww8/rtfattributeoutput.cxx                   |    4 -
 sw/source/filter/ww8/writerhelper.cxx                         |   24 +++++++-
 sw/source/filter/ww8/writerhelper.hxx                         |    2 
 sw/source/filter/ww8/wrtw8esh.cxx                             |    2 
 writerfilter/CppunitTest_writerfilter_dmapper.mk              |    1 
 writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx        |   30 ++++++++++
 writerfilter/qa/cppunittests/dmapper/data/wrap-poly-crop.docx |binary
 writerfilter/source/dmapper/GraphicImport.cxx                 |   11 +++
 writerfilter/source/dmapper/WrapPolygonHandler.cxx            |   21 ++++++-
 writerfilter/source/dmapper/WrapPolygonHandler.hxx            |    7 ++
 12 files changed, 111 insertions(+), 16 deletions(-)

New commits:
commit 6f54eee8453ae0371588e2109bb152922939a11b
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu May 14 18:02:23 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri May 15 10:51:06 2020 +0200

    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.
    
    (cherry picked from commit c68b458514b35cae70c9a6630e06f46a867aa3b9)
    
    Change-Id: Ieef18aad3c76f7945c7348201b07bcb27a4cd48d

diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index de03b1c0ce1c..4b2c4cc814bf 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -955,7 +955,7 @@ DECLARE_OOXMLIMPORT_TEST(testFdo75722dml, "fdo75722-dml.docx")
     CPPUNIT_ASSERT_EQUAL(sal_Int64(3128), nRot);
 }
 
-DECLARE_OOXMLIMPORT_TEST(testFdo76803, "fdo76803.docx")
+DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testFdo76803, "fdo76803.docx")
 {
     // The ContourPolyPolygon was wrong
     uno::Reference<beans::XPropertySet> xPropertySet(getShape(1), uno::UNO_QUERY);
@@ -971,16 +971,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());
 }
 
diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx
index e9381ca77d0d..0989b36f0bec 100644
--- a/sw/source/filter/ww8/docxsdrexport.cxx
+++ b/sw/source/filter/ww8/docxsdrexport.cxx
@@ -768,7 +768,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 f3d05263385b..edd666e28cf9 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -4154,8 +4154,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 a062941f6b57..104edeaa7608 100644
--- a/sw/source/filter/ww8/writerhelper.cxx
+++ b/sw/source/filter/ww8/writerhelper.cxx
@@ -59,6 +59,7 @@
 #include <IDocumentStylePoolAccess.hxx>
 #include <IDocumentMarkAccess.hxx>
 #include <IMark.hxx>
+#include <grfatr.hxx>
 
 using namespace com::sun::star;
 
@@ -650,10 +651,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 fb90d4c406e8..95cb1a5aa7ce 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -2114,7 +2114,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/qa/cppunittests/dmapper/GraphicImport.cxx b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
index 14fb181f2e07..37e462012c66 100644
--- a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
@@ -162,13 +162,14 @@ CPPUNIT_TEST_FIXTURE(Test, testWrapPolyCrop)
     // 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());
 }
 }
 
diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.cxx b/writerfilter/source/dmapper/WrapPolygonHandler.cxx
index 14c1d6a0c5bf..aa23342443a4 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>
 
@@ -99,7 +100,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);
 
commit 2400f319c45853ae0d70487e5b140c20439a9b61
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed May 13 17:59:34 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri May 15 10:51:06 2020 +0200

    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.
    
    (cherry picked from commit 2abe9837deee3823c7928a76b5b2f94f1464f1a3)
    
    Conflicts:
            writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
    
    Change-Id: Iab2adaa81a33eb04e1806b17ed129ac50f5d2aa3

diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 0030a6ba68aa..de03b1c0ce1c 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -971,17 +971,17 @@ DECLARE_OOXMLIMPORT_TEST(testFdo76803, "fdo76803.docx")
 
     CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), aPolygon.count());
 
-    CPPUNIT_ASSERT_EQUAL(double(-163), aPolygon.getB2DPoint(0).getX());
-    CPPUNIT_ASSERT_EQUAL(double(0), aPolygon.getB2DPoint(0).getY());
+    CPPUNIT_ASSERT_EQUAL(double(-162), aPolygon.getB2DPoint(0).getX());
+    CPPUNIT_ASSERT_EQUAL(double(-35), aPolygon.getB2DPoint(0).getY());
 
-    CPPUNIT_ASSERT_EQUAL(double(-163), aPolygon.getB2DPoint(1).getX());
-    CPPUNIT_ASSERT_EQUAL(double(3661), aPolygon.getB2DPoint(1).getY());
+    CPPUNIT_ASSERT_EQUAL(double(-162), aPolygon.getB2DPoint(1).getX());
+    CPPUNIT_ASSERT_EQUAL(double(3510), aPolygon.getB2DPoint(1).getY());
 
-    CPPUNIT_ASSERT_EQUAL(double(16987), aPolygon.getB2DPoint(2).getX());
-    CPPUNIT_ASSERT_EQUAL(double(3661), aPolygon.getB2DPoint(2).getY());
+    CPPUNIT_ASSERT_EQUAL(double(16892), aPolygon.getB2DPoint(2).getX());
+    CPPUNIT_ASSERT_EQUAL(double(3510), aPolygon.getB2DPoint(2).getY());
 
-    CPPUNIT_ASSERT_EQUAL(double(16987), aPolygon.getB2DPoint(3).getX());
-    CPPUNIT_ASSERT_EQUAL(double(0), aPolygon.getB2DPoint(3).getY());
+    CPPUNIT_ASSERT_EQUAL(double(16892), aPolygon.getB2DPoint(3).getX());
+    CPPUNIT_ASSERT_EQUAL(double(-35), aPolygon.getB2DPoint(3).getY());
 }
 
 DECLARE_OOXMLIMPORT_TEST(testUnbalancedColumnsCompat, "unbalanced-columns-compat.docx")
diff --git a/writerfilter/CppunitTest_writerfilter_dmapper.mk b/writerfilter/CppunitTest_writerfilter_dmapper.mk
index 55299bb672a9..fcd535ac899f 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 01dd3d6ca602..14fb181f2e07 100644
--- a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
@@ -18,8 +18,10 @@
 #include <com/sun/star/text/XTextTablesSupplier.hpp>
 #include <com/sun/star/text/RelOrientation.hpp>
 #include <com/sun/star/container/XNamed.hpp>
+#include <com/sun/star/drawing/PointSequenceSequence.hpp>
 
 #include <comphelper/processfactory.hxx>
+#include <basegfx/polygon/b2dpolypolygontools.hxx>
 
 using namespace ::com::sun::star;
 
@@ -141,6 +143,33 @@ CPPUNIT_TEST_FIXTURE(Test, testInlineInShapeAnchoredZOrder)
     // i.e. the image was behind the textbox that was hosting it.
     CPPUNIT_ASSERT_EQUAL(OUString("Picture 1"), xOval->getName());
 }
+
+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
Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/wrap-poly-crop.docx differ
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 33540be2ff72..f8a2482d39ef 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -1400,6 +1400,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 862dae53e2e2..14c1d6a0c5bf 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>
@@ -136,6 +137,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 807e78362924..d5dfd3487d84 100644
--- a/writerfilter/source/dmapper/WrapPolygonHandler.hxx
+++ b/writerfilter/source/dmapper/WrapPolygonHandler.hxx
@@ -26,6 +26,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;
 };
 


More information about the Libreoffice-commits mailing list