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

Regina Henschel (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 10 18:01:44 UTC 2019


 svx/qa/unit/customshapes.cxx                      |   20 +++++++++++++++
 svx/qa/unit/data/tdf125782_QuadraticCurveTo.odg   |binary
 svx/source/customshapes/EnhancedCustomShape2d.cxx |   28 ++++++++--------------
 3 files changed, 31 insertions(+), 17 deletions(-)

New commits:
commit 39599fc689364b70cf83e834a5742cc2181b13b0
Author:     Regina Henschel <rb.henschel at t-online.de>
AuthorDate: Sat Jun 8 21:49:50 2019 +0200
Commit:     Regina Henschel <rb.henschel at t-online.de>
CommitDate: Mon Jun 10 20:00:58 2019 +0200

    tdf#125782 use correct 'current point' for quadraticcurveto
    
    Use the same way to get the 'current point' as in
    command arcangleto. The error was visible in shape teardrop.
    
    Change-Id: Ie7af2b9111150bae7e3ea492eeb439a0cc2bfe7c
    Reviewed-on: https://gerrit.libreoffice.org/73723
    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 6426d72ab970..b70a8e536218 100644
--- a/svx/qa/unit/customshapes.cxx
+++ b/svx/qa/unit/customshapes.cxx
@@ -393,6 +393,26 @@ CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf115813_OOXML_XY_handle)
     }
     CPPUNIT_ASSERT_EQUAL(OUString(), sErrors);
 }
+
+CPPUNIT_TEST_FIXTURE(CustomshapesTest, testQuadraticCurveTo)
+{
+    // tdf125782 command Q (quadraticcurveto) uses wrong 'current point'.
+    // When converting to cubic Bezier curve, this had resulted in a wrong first control point.
+    // The quadraticcurveto segment starts in shape center in the test file. The first control
+    // point should produce a horizontal tangent in the start point.
+    const OUString sFileName("tdf125782_QuadraticCurveTo.odg");
+    const 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());
+    uno::Reference<drawing::XShape> xShape(getShape(0));
+    uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
+    CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeProps.is());
+    awt::Rectangle aBoundRect;
+    xShapeProps->getPropertyValue(UNO_NAME_MISC_OBJ_BOUNDRECT) >>= aBoundRect;
+    const double fHeight = static_cast<double>(aBoundRect.Height);
+    //Add some tolerance
+    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("bad height of quadraticcurveto", 3004, fHeight, 10.0);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/qa/unit/data/tdf125782_QuadraticCurveTo.odg b/svx/qa/unit/data/tdf125782_QuadraticCurveTo.odg
new file mode 100644
index 000000000000..ba7b495367ce
Binary files /dev/null and b/svx/qa/unit/data/tdf125782_QuadraticCurveTo.odg differ
diff --git a/svx/source/customshapes/EnhancedCustomShape2d.cxx b/svx/source/customshapes/EnhancedCustomShape2d.cxx
index 256b96cd5362..482650fdf9d0 100644
--- a/svx/source/customshapes/EnhancedCustomShape2d.cxx
+++ b/svx/source/customshapes/EnhancedCustomShape2d.cxx
@@ -2292,27 +2292,21 @@ void EnhancedCustomShape2d::CreateSubPath(
                 {
                     for ( sal_Int32 i(0); ( i < nPntCount ) && ( rSrcPt + 1 < nCoordSize ); i++ )
                     {
-                        if ( rSrcPt )
+                        DBG_ASSERT(aNewB2DPolygon.count(), "EnhancedCustomShape2d::CreateSubPath: Error no previous point for Q (!)");
+                        if (aNewB2DPolygon.count() > 0)
                         {
-                            const Point aPreviousEndPoint(GetPoint( seqCoordinates[ rSrcPt - 1 ], true, true));
-                            const Point aControlQ(GetPoint( seqCoordinates[ rSrcPt++ ], true, true ));
-                            const Point aEnd(GetPoint( seqCoordinates[ rSrcPt++ ], true, true ));
-                            const Point aControlA((aPreviousEndPoint + (aControlQ * 2)) / 3);
-                            const Point aControlB(((aControlQ * 2) + aEnd) / 3);
-
-                            DBG_ASSERT(aNewB2DPolygon.count(), "EnhancedCustomShape2d::CreateSubPath: Error in adding Q control point (!)");
-                            aNewB2DPolygon.appendBezierSegment(
-                                basegfx::B2DPoint(aControlA.X(), aControlA.Y()),
-                                basegfx::B2DPoint(aControlB.X(), aControlB.Y()),
-                                basegfx::B2DPoint(aEnd.X(), aEnd.Y()));
+                            const basegfx::B2DPoint aPreviousEndPoint(aNewB2DPolygon.getB2DPoint(aNewB2DPolygon.count()-1));
+                            const basegfx::B2DPoint aControlQ(GetPointAsB2DPoint( seqCoordinates[ rSrcPt++ ], true, true ));
+                            const basegfx::B2DPoint aEnd(GetPointAsB2DPoint( seqCoordinates[ rSrcPt++ ], true, true ));
+                            const basegfx::B2DPoint aControlA((aPreviousEndPoint + (aControlQ * 2)) / 3);
+                            const basegfx::B2DPoint aControlB(((aControlQ * 2) + aEnd) / 3);
+                            aNewB2DPolygon.appendBezierSegment(aControlA, aControlB, aEnd);
                         }
-                        else // no previous point , do a moveto
+                        else // no previous point; ill structured path, but try to draw as much as possible
                         {
                             rSrcPt++; // skip control point
-                            const Point aEnd(GetPoint( seqCoordinates[ rSrcPt++ ], true, true ));
-
-                            DBG_ASSERT(aNewB2DPolygon.count(), "EnhancedCustomShape2d::CreateSubPath: Error in adding Q control point (!)");
-                            aNewB2DPolygon.append(basegfx::B2DPoint(aEnd.X(), aEnd.Y()));
+                            const basegfx::B2DPoint aEnd(GetPointAsB2DPoint( seqCoordinates[ rSrcPt++ ], true, true ));
+                            aNewB2DPolygon.append(aEnd);
                         }
                     }
                 }


More information about the Libreoffice-commits mailing list