svx/qa/unit/customshapes.cxx                      |   82 ++++++++++++++++++++++
 svx/qa/unit/data/tdf138945_resizeRotatedShape.odg |binary
 svx/source/svdraw/svdoashp.cxx                    |   24 ++++++
 3 files changed, 106 insertions(+)

New commits:
commit d4ca360f6632f03e9fb7e9af37aac40d23f1249a
Author:     Regina Henschel <rb.hensc...@t-online.de>
AuthorDate: Tue Dec 15 20:20:55 2020 +0100
Commit:     Regina Henschel <rb.hensc...@t-online.de>
CommitDate: Wed Dec 16 13:59:14 2020 +0100

    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.hensc...@t-online.de>

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
new file mode 100644
index 000000000000..20a2825af7fe
Binary files /dev/null and b/svx/qa/unit/data/tdf138945_resizeRotatedShape.odg 
differ
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();
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to