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

Regina Henschel (via logerrit) logerrit at kemper.freedesktop.org
Wed Sep 23 18:21:39 UTC 2020


 svx/qa/unit/customshapes.cxx              |   57 ++++++++++++++++++++++++++++++
 svx/qa/unit/data/tdf136176_rot30_flip.odg |binary
 svx/source/svdraw/svdoashp.cxx            |   25 ++++++++-----
 3 files changed, 73 insertions(+), 9 deletions(-)

New commits:
commit 3b4198d4654e4cf569f9b82d87a2498dbbecb9ac
Author:     Regina Henschel <rb.henschel at t-online.de>
AuthorDate: Wed Sep 23 19:02:30 2020 +0200
Commit:     Regina Henschel <rb.henschel at t-online.de>
CommitDate: Wed Sep 23 20:21:03 2020 +0200

    tdf#136176 Correct update fObjectRotation in NbcShear
    
    Change-Id: I4a73a720845436d25fc1a02eb615dad47f17f96d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103269
    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 e500c9bd2649..10abdad0f7e3 100644
--- a/svx/qa/unit/customshapes.cxx
+++ b/svx/qa/unit/customshapes.cxx
@@ -12,10 +12,14 @@
 #include <rtl/ustring.hxx>
 #include <editeng/unoprnms.hxx>
 #include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <basegfx/polygon/b2dpolygon.hxx>
+#include <basegfx/point/b2dpoint.hxx>
 #include <svx/EnhancedCustomShape2d.hxx>
 #include <svx/svdoashp.hxx>
 #include <svx/svdopath.hxx>
 #include <svx/unoapi.hxx>
+#include <unotools/mediadescriptor.hxx>
+#include <unotools/tempfile.hxx>
 
 #include <cppunit/TestAssert.h>
 
@@ -24,6 +28,7 @@
 #include <com/sun/star/drawing/XDrawPage.hpp>
 #include <com/sun/star/awt/Rectangle.hpp>
 #include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
 
 using namespace ::com::sun::star;
 
@@ -749,6 +754,58 @@ CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf122323_largeSwingAngle)
     const basegfx::B2DPoint aEnd(aPolygon.getB2DPoint(aPolygon.count() - 2));
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Start <> End", aStart, aEnd);
 }
+
+CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf136176)
+{
+    // Error was, that fObjectRotation was not correctly updated after shearing.
+    // The problem becomes visible after save and reload.
+    OUString sURL = m_directories.getURLFromSrc(sDataDirectory) + "tdf136176_rot30_flip.odg";
+    mxComponent = loadFromDesktop(sURL, "com.sun.star.comp.drawing.DrawingDocument");
+    CPPUNIT_ASSERT_MESSAGE("Could not load document", mxComponent.is());
+
+    for (sal_uInt16 i = 0; i < 3; i++)
+    {
+        // get shape
+        uno::Reference<drawing::XShape> xShape(getShape(i));
+        SdrObjCustomShape& rSdrObjCustomShape(
+            static_cast<SdrObjCustomShape&>(*GetSdrObjectFromXShape(xShape)));
+        // apply shearing 20deg
+        const Point aCenter = rSdrObjCustomShape.GetSnapRect().Center();
+        rSdrObjCustomShape.Shear(aCenter, 2000, tan(basegfx::deg2rad(20.0)), false);
+    }
+
+    // Save and reload
+    uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+    utl::TempFile aTempFile;
+    utl::MediaDescriptor aMediaDescriptor;
+    aMediaDescriptor["FilterName"] <<= OUString("draw8");
+    xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+    mxComponent->dispose();
+    mxComponent = loadFromDesktop(aTempFile.GetURL());
+
+    // Expected values of point 4 of the shape polygon
+    const OString sTestCase[] = { "FlipH", "FlipV", "FlipHV" };
+    const double fX[] = { 14981.0, 3849.0, 15214.0 };
+    const double fY[] = { 9366.0, 16464.0, 23463.0 };
+
+    // Verify correct positions
+    for (sal_uInt16 i = 0; i < 3; i++)
+    {
+        // Get shape
+        const uno::Reference<drawing::XShape> xShape(getShape(i));
+        const SdrObjCustomShape& rSdrObjCustomShape(
+            static_cast<SdrObjCustomShape&>(*GetSdrObjectFromXShape(xShape)));
+        // Create polygon from shape and examine point 4 of the polygon
+        const basegfx::B2DPolyPolygon aLineGeometry = rSdrObjCustomShape.GetLineGeometry(false);
+        const basegfx::B2DPoint aPoint(aLineGeometry.getB2DPolygon(0).getB2DPoint(4));
+        // Allow some tolerance for rounding errors
+        if (fabs(aPoint.getX() - fX[i]) > 2.0 || fabs(aPoint.getY() - fY[i]) > 2.0)
+        {
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sTestCase[i].getStr(), aPoint,
+                                         basegfx::B2DPoint(fX[i], fY[i]));
+        }
+    }
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/qa/unit/data/tdf136176_rot30_flip.odg b/svx/qa/unit/data/tdf136176_rot30_flip.odg
new file mode 100644
index 000000000000..75707a0f5ecb
Binary files /dev/null and b/svx/qa/unit/data/tdf136176_rot30_flip.odg differ
diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx
index 662ab4a06797..3e7391d8123c 100644
--- a/svx/source/svdraw/svdoashp.cxx
+++ b/svx/source/svdraw/svdoashp.cxx
@@ -1649,22 +1649,29 @@ void SdrObjCustomShape::NbcShear( const Point& rRef, long nAngle, double tn, boo
     // updating fObjectRotation
     long nTextObjRotation = aGeo.nRotationAngle;
     double fAngle = nTextObjRotation;
-
     fAngle /= 100.0;
-
-    bool bSingleFlip = (IsMirroredX()!= IsMirroredY());
-
-    fObjectRotation = fmod( bSingleFlip ? -fAngle : fAngle, 360.0 );
-
-    if ( fObjectRotation < 0 )
+    if (IsMirroredX())
     {
-        fObjectRotation = 360.0 + fObjectRotation;
+        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();
 }
 
-
 SdrGluePoint SdrObjCustomShape::GetVertexGluePoint(sal_uInt16 nPosNum) const
 {
     sal_Int32 nWdt = ImpGetLineWdt(); // #i25616#


More information about the Libreoffice-commits mailing list