diff options
author | Regina Henschel <rb.henschel@t-online.de> | 2020-12-15 20:20:55 +0100 |
---|---|---|
committer | Regina Henschel <rb.henschel@t-online.de> | 2020-12-16 13:59:14 +0100 |
commit | d4ca360f6632f03e9fb7e9af37aac40d23f1249a (patch) | |
tree | 5462a631173e6ac6e29b36910de8f3d472e9184b /svx/qa/unit | |
parent | bcb8d2d3a08991b4e57189b81f8702aaa8af8a89 (diff) |
tdf#138945 update fObjectRotation for NbcResize
SdrObjCustomShape::NbcResize uses the inherited SdrTextObj::NbcResize.
But a SdrTextObj does not know fObjectRotation. Explicit update to new
rotation angle after resize is needed.
The error became visible, if you changed width or height of a rotated
or sheared custom shape in the Position&Size dialog. Then the shape
handles were not on the shape outline.
Change-Id: Idbe47a3b1ef2b34e9645d62830cb330f2e49bd3e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107792
Tested-by: Jenkins
Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Diffstat (limited to 'svx/qa/unit')
-rw-r--r-- | svx/qa/unit/customshapes.cxx | 82 | ||||
-rw-r--r-- | svx/qa/unit/data/tdf138945_resizeRotatedShape.odg | bin | 0 -> 9457 bytes |
2 files changed, 82 insertions, 0 deletions
diff --git a/svx/qa/unit/customshapes.cxx b/svx/qa/unit/customshapes.cxx index 737ab5bdf6d0..e3a5e0ac92a3 100644 --- a/svx/qa/unit/customshapes.cxx +++ b/svx/qa/unit/customshapes.cxx @@ -90,6 +90,88 @@ sal_uInt8 CustomshapesTest::countShapes() return xDrawPage->getCount(); } +void lcl_AssertRectEqualWithTolerance(const OString& sInfo, const tools::Rectangle& rExpected, + const tools::Rectangle& rActual, const sal_Int32 nTolerance) +{ + // Left + OString sMsg = sInfo + " Left expected " + OString::number(rExpected.Left()) + " actual " + + OString::number(rActual.Left()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), + std::abs(rExpected.Left() - rActual.Left()) <= nTolerance); + + // Top + sMsg = sInfo + " Top expected " + OString::number(rExpected.Top()) + " actual " + + OString::number(rActual.Top()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), std::abs(rExpected.Top() - rActual.Top()) <= nTolerance); + + // Width + sMsg = sInfo + " Width expected " + OString::number(rExpected.GetWidth()) + " actual " + + OString::number(rActual.GetWidth()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), + std::abs(rExpected.GetWidth() - rActual.GetWidth()) <= nTolerance); + + // Height + sMsg = sInfo + " Height expected " + OString::number(rExpected.GetHeight()) + " actual " + + OString::number(rActual.GetHeight()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), + std::abs(rExpected.GetHeight() - rActual.GetHeight()) <= nTolerance); +} + +CPPUNIT_TEST_FIXTURE(CustomshapesTest, testResizeRotatedShape) +{ + // tdf#138945 Setting width or height for a rotated or sheared shape in the Position&Size dialog + // had resulted in a mismatch of handle position and shape outline. That becomes visible in object + // properties as mismatch of frame rectangle and bound rectangle. + // Problem was, that fObjectRotation was not updated. + + // Load document and get shape. It is a rectangle custom shape with 45° shear and 330° rotation. + OUString aURL + = m_directories.getURLFromSrc(sDataDirectory) + "tdf138945_resizeRotatedShape.odg"; + mxComponent = loadFromDesktop(aURL, "com.sun.star.comp.presentation.PresentationDocument"); + CPPUNIT_ASSERT_MESSAGE("Could not load document", mxComponent.is()); + uno::Reference<drawing::XShape> xShape(getShape(0)); + + // Change height and mirror vertical + { + SdrObjCustomShape& rSdrShape( + static_cast<SdrObjCustomShape&>(*GetSdrObjectFromXShape(xShape))); + rSdrShape.NbcResize(rSdrShape.GetRelativePos(), Fraction(1.0), Fraction(-0.5)); + tools::Rectangle aSnapRect(rSdrShape.GetSnapRect()); + tools::Rectangle aBoundRect(rSdrShape.GetCurrentBoundRect()); + lcl_AssertRectEqualWithTolerance("height changed, mirror vert", aSnapRect, aBoundRect, 3); + } + + // Change height + { + SdrObjCustomShape& rSdrShape( + static_cast<SdrObjCustomShape&>(*GetSdrObjectFromXShape(xShape))); + rSdrShape.NbcResize(rSdrShape.GetRelativePos(), Fraction(1.0), Fraction(2.0)); + tools::Rectangle aSnapRect(rSdrShape.GetSnapRect()); + tools::Rectangle aBoundRect(rSdrShape.GetCurrentBoundRect()); + lcl_AssertRectEqualWithTolerance("height changed", aSnapRect, aBoundRect, 3); + } + + // Change width + { + SdrObjCustomShape& rSdrShape( + static_cast<SdrObjCustomShape&>(*GetSdrObjectFromXShape(xShape))); + rSdrShape.NbcResize(rSdrShape.GetRelativePos(), Fraction(2.0), Fraction(1.0)); + tools::Rectangle aSnapRect(rSdrShape.GetSnapRect()); + tools::Rectangle aBoundRect(rSdrShape.GetCurrentBoundRect()); + lcl_AssertRectEqualWithTolerance("width changed", aSnapRect, aBoundRect, 3); + } + + // Change width and mirror horizontal + { + SdrObjCustomShape& rSdrShape( + static_cast<SdrObjCustomShape&>(*GetSdrObjectFromXShape(xShape))); + rSdrShape.NbcResize(rSdrShape.GetRelativePos(), Fraction(-0.5), Fraction(1.0)); + tools::Rectangle aSnapRect(rSdrShape.GetSnapRect()); + tools::Rectangle aBoundRect(rSdrShape.GetCurrentBoundRect()); + lcl_AssertRectEqualWithTolerance("width changed, mirror hori", aSnapRect, aBoundRect, 3); + } +} + CPPUNIT_TEST_FIXTURE(CustomshapesTest, testViewBoxLeftTop) { // tdf#121890 formula values "left" and "top" are wrongly calculated diff --git a/svx/qa/unit/data/tdf138945_resizeRotatedShape.odg b/svx/qa/unit/data/tdf138945_resizeRotatedShape.odg Binary files differnew file mode 100644 index 000000000000..20a2825af7fe --- /dev/null +++ b/svx/qa/unit/data/tdf138945_resizeRotatedShape.odg |