diff options
author | Regina Henschel <rb.henschel@t-online.de> | 2019-09-28 00:34:35 +0200 |
---|---|---|
committer | Regina Henschel <rb.henschel@t-online.de> | 2019-09-28 20:00:51 +0200 |
commit | 7830a9d42926a9c5265230d42fce4a4858b303c1 (patch) | |
tree | 63bebe7a9ffebdb39df04132c74a411b03aad79b | |
parent | 4ea413542ebb142dcdec81f43b1b5e565dbe7316 (diff) |
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@t-online.de>
-rw-r--r-- | svx/qa/unit/customshapes.cxx | 45 | ||||
-rw-r--r-- | svx/qa/unit/data/tdf127785_Mirror.odp | bin | 0 -> 13742 bytes | |||
-rw-r--r-- | svx/source/customshapes/EnhancedCustomShape2d.cxx | 10 |
3 files changed, 50 insertions, 5 deletions
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 Binary files differnew file mode 100644 index 000000000000..ff867839f4ac --- /dev/null +++ b/svx/qa/unit/data/tdf127785_Mirror.odp 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; |