[Libreoffice-commits] core.git: svx/qa svx/source

Regina Henschel (via logerrit) logerrit at kemper.freedesktop.org
Sat Sep 28 18:01:28 UTC 2019


 svx/qa/unit/customshapes.cxx                      |   45 ++++++++++++++++++++++
 svx/qa/unit/data/tdf127785_Mirror.odp             |binary
 svx/source/customshapes/EnhancedCustomShape2d.cxx |   10 ++--
 3 files changed, 50 insertions(+), 5 deletions(-)

New commits:
commit 7830a9d42926a9c5265230d42fce4a4858b303c1
Author:     Regina Henschel <rb.henschel at t-online.de>
AuthorDate: Sat Sep 28 00:34:35 2019 +0200
Commit:     Regina Henschel <rb.henschel at t-online.de>
CommitDate: Sat Sep 28 20:00:51 2019 +0200

    tdf#127785 correct calculation of text rectangle in flipped shape
    
    The calculation had used a wrong corner. That resulted in negative
    width or height. Thus the entire shape frame was used as fallback
    instead of the smaller text rectangle.
    
    Change-Id: Ia18d9630dc83c0556115609575f26dcfa71bdb13
    Reviewed-on: https://gerrit.libreoffice.org/79774
    Tested-by: Jenkins
    Reviewed-by: Regina Henschel <rb.henschel at t-online.de>

diff --git a/svx/qa/unit/customshapes.cxx b/svx/qa/unit/customshapes.cxx
index 5d1d4c3f44fe..5f5983776e15 100644
--- a/svx/qa/unit/customshapes.cxx
+++ b/svx/qa/unit/customshapes.cxx
@@ -460,6 +460,51 @@ CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf126512_OOXML_handle_in_ODP)
     }
     CPPUNIT_ASSERT_EQUAL(OUString(), sErrors);
 }
+
+CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf127785_Mirror)
+{
+    // The document contains two shapes, one with horizontal flip, the other with vertical
+    // flip. They are diamonds, so their text frame is symmetric to the center of the shape.
+    // The shapes have not stroke and no fill, so that the bounding box sourrounds the text
+    // and therefore equals approximately the text frame.
+    // Error was, that because of wrong calculation, the flipped shapes do not use the
+    // text frame but the frame rectangle for their text.
+    const OUString sFileName("tdf127785_Mirror.odp");
+    OUString sURL = m_directories.getURLFromSrc(sDataDirectory) + sFileName;
+    mxComponent = loadFromDesktop(sURL, "com.sun.star.comp.drawing.DrawingDocument");
+    CPPUNIT_ASSERT_MESSAGE("Could not load document", mxComponent.is());
+    OUString sErrors; // sErrors collects the errors and should be empty in case all is OK.
+
+    uno::Reference<drawing::XShape> xShapeV(getShape(0));
+    uno::Reference<beans::XPropertySet> xShapeVProps(xShapeV, uno::UNO_QUERY);
+    CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeVProps.is());
+    awt::Rectangle aBoundRectV;
+    xShapeVProps->getPropertyValue(UNO_NAME_MISC_OBJ_BOUNDRECT) >>= aBoundRectV;
+    const sal_Int32 nHeightV = aBoundRectV.Height;
+    const sal_Int32 nWidthV = aBoundRectV.Width;
+    const sal_Int32 nLeftV = aBoundRectV.X;
+    const sal_Int32 nTopV = aBoundRectV.Y;
+    if (abs(nHeightV - 4149) > 5 || abs(nWidthV - 3819) > 5)
+        sErrors += "Flip vertical wrong size.";
+    if (abs(nLeftV - 3155) > 5 || abs(nTopV - 3736) > 5)
+        sErrors += " Flip vertical wrong position.";
+
+    uno::Reference<drawing::XShape> xShapeH(getShape(1));
+    uno::Reference<beans::XPropertySet> xShapeHProps(xShapeH, uno::UNO_QUERY);
+    CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeHProps.is());
+    awt::Rectangle aBoundRectH;
+    xShapeHProps->getPropertyValue(UNO_NAME_MISC_OBJ_BOUNDRECT) >>= aBoundRectH;
+    const sal_Int32 nHeightH = aBoundRectH.Height;
+    const sal_Int32 nWidthH = aBoundRectH.Width;
+    const sal_Int32 nLeftH = aBoundRectH.X;
+    const sal_Int32 nTopH = aBoundRectH.Y;
+    if (abs(nHeightH - 4149) > 5 || abs(nWidthH - 3819) > 5)
+        sErrors += " Flip horizontal wrong size.";
+    if (abs(nLeftH - 15026) > 5 || abs(nTopH - 4115) > 5)
+        sErrors += " Flip horizontal wrong position.";
+
+    CPPUNIT_ASSERT_EQUAL(OUString(), sErrors);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/qa/unit/data/tdf127785_Mirror.odp b/svx/qa/unit/data/tdf127785_Mirror.odp
new file mode 100644
index 000000000000..ff867839f4ac
Binary files /dev/null and b/svx/qa/unit/data/tdf127785_Mirror.odp differ
diff --git a/svx/source/customshapes/EnhancedCustomShape2d.cxx b/svx/source/customshapes/EnhancedCustomShape2d.cxx
index ee0331987c65..6151ea928e47 100644
--- a/svx/source/customshapes/EnhancedCustomShape2d.cxx
+++ b/svx/source/customshapes/EnhancedCustomShape2d.cxx
@@ -1101,17 +1101,17 @@ tools::Rectangle EnhancedCustomShape2d::GetTextRect() const
     sal_Int32 nIndex = 0;
     Point aTopLeft( GetPoint( seqTextFrames[ nIndex ].TopLeft, !bOOXMLShape, true ) );
     Point aBottomRight( GetPoint( seqTextFrames[ nIndex ].BottomRight, !bOOXMLShape, true ) );
+    tools::Rectangle aRect( aTopLeft, aBottomRight );
     if ( bFlipH )
     {
-        aTopLeft.setX( aLogicRect.GetWidth() - aTopLeft.X() );
-        aBottomRight.setX( aLogicRect.GetWidth() - aBottomRight.X() );
+        aRect.SetLeft(aLogicRect.GetWidth() - 1 - aBottomRight.X());
+        aRect.SetRight( aLogicRect.GetWidth() - 1 - aTopLeft.X());
     }
     if ( bFlipV )
     {
-        aTopLeft.setY( aLogicRect.GetHeight() - aTopLeft.Y() );
-        aBottomRight.setY( aLogicRect.GetHeight() - aBottomRight.Y() );
+        aRect.SetTop(aLogicRect.GetHeight() - 1 - aBottomRight.Y());
+        aRect.SetBottom(aLogicRect.GetHeight() - 1 - aTopLeft.Y());
     }
-    tools::Rectangle aRect( aTopLeft, aBottomRight );
     SAL_INFO("svx", aRect.GetWidth() << " x " << aRect.GetHeight());
     if( aRect.GetWidth() <= 1 || aRect.GetHeight() <= 1 )
         return aLogicRect;


More information about the Libreoffice-commits mailing list