sd/qa/unit/data/xml/shapes-test_page1.xml               |    1 
 svx/CppunitTest_svx_unit.mk                             |    1 
 svx/qa/unit/data/tdf157543_5PointStar.ppt               |binary
 svx/qa/unit/gluepointTest.cxx                           |  110 ++++++++++++++++
 svx/source/customshapes/EnhancedCustomShapeGeometry.cxx |    7 -
 5 files changed, 118 insertions(+), 1 deletion(-)

New commits:
commit dd7fc07f83416a3d8a444947b7d28f7347520d6a
Author:     Regina Henschel <rb.hensc...@t-online.de>
AuthorDate: Sun Oct 1 14:47:09 2023 +0200
Commit:     Regina Henschel <rb.hensc...@t-online.de>
CommitDate: Mon Oct 2 16:23:26 2023 +0200

    tdf#157543 Add glue points to binary 5-point star
    
    The patch adds the glue points defined in 'Microsoft Office Drawing
    97-2007 Binary Format Specification' to our corresponding preset
    'msoStar'.
    
    This star shape is contained on page 1 in odp/shapes-test.odp. It had
    previously no glue points, but now it has five glue points. Thus I have
    updated the xml dump.
    
    Import from pptx is still broken, tracked in tdf#157216.
    
    Change-Id: Ifc9f28118fe23a3d37af0357b72bb23eeef6b894
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157446
    Tested-by: Jenkins
    Reviewed-by: Regina Henschel <rb.hensc...@t-online.de>

diff --git a/sd/qa/unit/data/xml/shapes-test_page1.xml 
b/sd/qa/unit/data/xml/shapes-test_page1.xml
index b5d97b55888a..344342bc4ac4 100644
--- a/sd/qa/unit/data/xml/shapes-test_page1.xml
+++ b/sd/qa/unit/data/xml/shapes-test_page1.xml
@@ -314,6 +314,7 @@
        <EnhancedCustomShapeSegment command="5" count="0"/>
       </Segments>
      </PropertyValue>
+     <PropertyValue name="GluePoints" handle="0" propertyState="DIRECT_VALUE"/>
     </Path>
    </PropertyValue>
    <PropertyValue name="AdjustmentValues">
diff --git a/svx/CppunitTest_svx_unit.mk b/svx/CppunitTest_svx_unit.mk
index a46aa5b0d583..95c76b2d0733 100644
--- a/svx/CppunitTest_svx_unit.mk
+++ b/svx/CppunitTest_svx_unit.mk
@@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,svx_unit, \
        svx/qa/unit/svdraw/test_SdrTextObject \
        svx/qa/unit/customshapes \
     svx/qa/unit/classicshapes \
+    svx/qa/unit/gluepointTest \
        svx/qa/unit/sdr \
        svx/qa/unit/svdraw \
        svx/qa/unit/table \
diff --git a/svx/qa/unit/data/tdf157543_5PointStar.ppt 
b/svx/qa/unit/data/tdf157543_5PointStar.ppt
new file mode 100644
index 000000000000..f39b24e06599
Binary files /dev/null and b/svx/qa/unit/data/tdf157543_5PointStar.ppt differ
diff --git a/svx/qa/unit/gluepointTest.cxx b/svx/qa/unit/gluepointTest.cxx
new file mode 100644
index 000000000000..647f555b8095
--- /dev/null
+++ b/svx/qa/unit/gluepointTest.cxx
@@ -0,0 +1,110 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/unoapi_test.hxx>
+
+#include <cppunit/TestAssert.h>
+
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
+#include <com/sun/star/drawing/XDrawPage.hpp>
+#include <com/sun/star/drawing/XDrawPages.hpp>
+#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
+#include <com/sun/star/drawing/XShape.hpp>
+
+using namespace ::com::sun::star;
+
+namespace
+{
+/// Tests related to glue points defined in the custom shape geometry.
+class GluePointTest : public UnoApiTest
+{
+public:
+    GluePointTest()
+        : UnoApiTest("svx/qa/unit/data/")
+    {
+    }
+
+protected:
+    // get shape nShapeIndex from page 0
+    uno::Reference<drawing::XShape> getShape(sal_uInt8 nShapeIndex);
+};
+
+uno::Reference<drawing::XShape> GluePointTest::getShape(sal_uInt8 nShapeIndex)
+{
+    uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent,
+                                                                   
uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_MESSAGE("Could not get XDrawPagesSupplier", 
xDrawPagesSupplier.is());
+    uno::Reference<drawing::XDrawPages> 
xDrawPages(xDrawPagesSupplier->getDrawPages());
+    uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->getByIndex(0), 
uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_MESSAGE("Could not get xDrawPage", xDrawPage.is());
+    uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(nShapeIndex), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_MESSAGE("Could not get xShape", xShape.is());
+    return xShape;
+}
+
+// Glue points from custom shape geometry. Values are relative to viewBox.
+// Usable if values are constant and not calculated by formula.
+bool lcl_getGeometryGluePoints(
+    uno::Sequence<drawing::EnhancedCustomShapeParameterPair>& rGluePoints,
+    const uno::Reference<drawing::XShape>& xShape)
+{
+    uno::Reference<beans::XPropertySet> xShapeProps(xShape, 
uno::UNO_QUERY_THROW);
+    uno::Any anotherAny = xShapeProps->getPropertyValue("CustomShapeGeometry");
+    uno::Sequence<beans::PropertyValue> aCustomShapeGeometry;
+    if (!(anotherAny >>= aCustomShapeGeometry))
+        return false;
+    uno::Sequence<beans::PropertyValue> aPathProps;
+    for (beans::PropertyValue const& rProp : 
std::as_const(aCustomShapeGeometry))
+    {
+        if (rProp.Name == "Path")
+        {
+            rProp.Value >>= aPathProps;
+            break;
+        }
+    }
+
+    for (beans::PropertyValue const& rProp : std::as_const(aPathProps))
+    {
+        if (rProp.Name == "GluePoints")
+        {
+            rProp.Value >>= rGluePoints;
+            break;
+        }
+    }
+    if (rGluePoints.getLength() > 0)
+        return true;
+    else
+        return false;
+}
+
+CPPUNIT_TEST_FIXTURE(GluePointTest, testTdf157543_5PointStar)
+{
+    loadFromURL(u"tdf157543_5PointStar.ppt");
+    uno::Sequence<drawing::EnhancedCustomShapeParameterPair> aGluePoints;
+    CPPUNIT_ASSERT(lcl_getGeometryGluePoints(aGluePoints, getShape(0)));
+    // Without fix only two glue points exist.
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aGluePoints.getLength());
+    // coordinates according "Microsoft Office Drawing 97-2007 Binary Format 
Specification"
+    sal_Int32 aExpectedX[] = { 10800, 0, 4200, 17400, 21600 };
+    sal_Int32 aExpectedY[] = { 0, 8259, 21600, 21600, 8259 };
+    for (sal_uInt8 i = 0; i < 5; i++)
+    {
+        sal_Int32 aActualX;
+        aGluePoints[i].First.Value >>= aActualX;
+        sal_Int32 aActualY;
+        aGluePoints[i].Second.Value >>= aActualY;
+        CPPUNIT_ASSERT_EQUAL(aExpectedX[i], aActualX);
+        CPPUNIT_ASSERT_EQUAL(aExpectedY[i], aActualY);
+    }
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/customshapes/EnhancedCustomShapeGeometry.cxx 
b/svx/source/customshapes/EnhancedCustomShapeGeometry.cxx
index c2ae1c20f268..a4b991efb6a5 100644
--- a/svx/source/customshapes/EnhancedCustomShapeGeometry.cxx
+++ b/svx/source/customshapes/EnhancedCustomShapeGeometry.cxx
@@ -3915,6 +3915,11 @@ const SvxMSDffTextRectangles mso_sptStarTextRect[] =
 {
     { { 6722, 8256 }, { 14878, 15460 } }
 };
+
+const SvxMSDffVertPair mso_sptStarGluePoints[] =
+{
+    { 10800, 0 }, { 0, 8259 }, { 4200, 21600 }, { 17400, 21600 }, { 21600, 
8259 }
+};
 const mso_CustomShape msoStar =
 {
     const_cast<SvxMSDffVertPair*>(mso_sptStarVert), SAL_N_ELEMENTS( 
mso_sptStarVert ),
@@ -3924,7 +3929,7 @@ const mso_CustomShape msoStar =
     const_cast<SvxMSDffTextRectangles*>(mso_sptStarTextRect), SAL_N_ELEMENTS( 
mso_sptStarTextRect ),
     21600, 21600,
     MIN_INT32, MIN_INT32,
-    nullptr, 0,
+    const_cast<SvxMSDffVertPair*>(mso_sptStarGluePoints), 
SAL_N_ELEMENTS(mso_sptStarGluePoints),
     nullptr, 0     // handles
 };
 

Reply via email to