diff options
author | Regina Henschel <rb.henschel@t-online.de> | 2020-12-15 20:20:55 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2020-12-17 11:16:38 +0100 |
commit | c6bc280fa986bac1b62726a4a19fd0be1c735fc0 (patch) | |
tree | 329f716a1d23e50e9b8efd0b35c67e0ca6e29129 /svx | |
parent | 16d05d51444dff723fe0efc57d68750845ed3e34 (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>
(cherry picked from commit d4ca360f6632f03e9fb7e9af37aac40d23f1249a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107803
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/qa/unit/customshapes.cxx | 82 | ||||
-rw-r--r-- | svx/qa/unit/data/tdf138945_resizeRotatedShape.odg | bin | 0 -> 9457 bytes | |||
-rw-r--r-- | svx/source/svdraw/svdoashp.cxx | 24 |
3 files changed, 106 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 diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx index 35812345b27b..30552b63fa4d 100644 --- a/svx/source/svdraw/svdoashp.cxx +++ b/svx/source/svdraw/svdoashp.cxx @@ -1525,6 +1525,30 @@ void SdrObjCustomShape::NbcResize( const Point& rRef, const Fraction& rxFact, co { } } + + // updating fObjectRotation + tools::Long nTextObjRotation = aGeo.nRotationAngle; + double fAngle = nTextObjRotation; + fAngle /= 100.0; + if (IsMirroredX()) + { + if (IsMirroredY()) + fObjectRotation = fAngle - 180.0; + else + fObjectRotation = -fAngle; + } + else + { + if (IsMirroredY()) + fObjectRotation = 180.0 - fAngle; + else + fObjectRotation = fAngle; + } + while (fObjectRotation < 0) + fObjectRotation += 360.0; + while (fObjectRotation >= 360.0) + fObjectRotation -= 360.0; + InvalidateRenderGeometry(); } |