oox/source/export/shapes.cxx        |   37 ++++++++++++++++++++++++++++--------
 oox/source/ppt/slidepersist.cxx     |   15 +++++++++-----
 sd/qa/unit/data/pptx/tdf154363.pptx |binary
 sd/qa/unit/import-tests.cxx         |   26 +++++++++++++++++++++++++
 4 files changed, 65 insertions(+), 13 deletions(-)

New commits:
commit 756e7701486318e72dce823f3946b7b2ea350132
Author:     Tibor Nagy <nagy.tib...@nisz.hu>
AuthorDate: Wed Mar 29 09:00:47 2023 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Apr 18 09:27:32 2023 +0200

    tdf#154363 sd: fix line connectors regression of mirrored shapes
    
    caused by commit cbf66ec3e60d07efb7c3cceed9b4f0fb4f0510c8
    (tdf#89449 PPTX import: fix line connectors).
    
    Note: partial revert of commit 9ab16e2738b4b9bd324c9aded8acb2ecba0fd2b0
    "oox: fix crash in lcl_GetGluePointId by removing unused code".
    
    Change-Id: Icc45c93c4fa3a22c0f34866ccb64ea6b9037d936
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149676
    Reviewed-by: László Németh <nem...@numbertext.org>
    Tested-by: László Németh <nem...@numbertext.org>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150202
    Tested-by: Jenkins

diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index a77ee85b8b92..ec2ebd54d56c 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -1640,17 +1640,38 @@ static void lcl_GetConnectorAdjustValue(const 
Reference<XShape>& xShape, tools::
     }
 }
 
-static sal_Int32 lcl_GetGluePointId(sal_Int32 nGluePointId)
+static sal_Int32 lcl_GetGluePointId(const Reference<XShape>& xShape, sal_Int32 
nGluePointId)
 {
     if (nGluePointId > 3)
         return nGluePointId - 4;
     else
     {
-        // change id of the bounding box (1 <-> 3)
-        if (nGluePointId == 1)
-            return 3; // Right
-        else if (nGluePointId == 3)
-            return 1; // Left
+        bool bFlipH = false;
+        bool bFlipV = false;
+        Reference<XPropertySet> xShapeProps(xShape, UNO_QUERY);
+        if 
(xShapeProps->getPropertySetInfo()->hasPropertyByName("CustomShapeGeometry"))
+        {
+            Sequence<PropertyValue> aGeometrySeq;
+            xShapeProps->getPropertyValue("CustomShapeGeometry") >>= 
aGeometrySeq;
+            for (int i = 0; i < aGeometrySeq.getLength(); i++)
+            {
+                const PropertyValue& rProp = aGeometrySeq[i];
+                if (rProp.Name == "MirroredX")
+                    rProp.Value >>= bFlipH;
+
+                if (rProp.Name == "MirroredY")
+                    rProp.Value >>= bFlipV;
+            }
+        }
+
+        if ((!bFlipH && !bFlipV) || (bFlipH && bFlipV))
+        {
+            // change id of the bounding box (1 <-> 3)
+            if (nGluePointId == 1)
+                nGluePointId = 3; // Right
+            else if (nGluePointId == 3)
+                nGluePointId = 1; // Left
+        }
     }
 
     return nGluePointId;
@@ -1708,12 +1729,12 @@ ShapeExport& ShapeExport::WriteConnectorShape( const 
Reference< XShape >& xShape
     if (GetProperty(rXPropSet, "StartGluePointIndex"))
         mAny >>= nStartGlueId;
     if (nStartGlueId != -1)
-        nStartGlueId = lcl_GetGluePointId(nStartGlueId);
+        nStartGlueId = lcl_GetGluePointId(rXShapeA, nStartGlueId);
 
     if (GetProperty(rXPropSet, "EndGluePointIndex"))
         mAny >>= nEndGlueId;
     if (nEndGlueId != -1)
-        nEndGlueId = lcl_GetGluePointId(nEndGlueId);
+        nEndGlueId = lcl_GetGluePointId(rXShapeB, nEndGlueId);
 
     // Position is relative to group in Word, but relative to anchor of group 
in API.
     if (GetDocumentType() == DOCUMENT_DOCX && !mbUserShapes && m_xParent.is())
diff --git a/oox/source/ppt/slidepersist.cxx b/oox/source/ppt/slidepersist.cxx
index 7298eea1247c..349262fc6b8f 100644
--- a/oox/source/ppt/slidepersist.cxx
+++ b/oox/source/ppt/slidepersist.cxx
@@ -654,11 +654,16 @@ void SlidePersist::createConnectorShapeConnection()
                         nGlueId += 4;
                     else
                     {
-                        // change id of the left and right glue points of the 
bounding box (1 <-> 3)
-                        if (nGlueId == 1)
-                            nGlueId = 3; // Right
-                        else if (nGlueId == 3)
-                            nGlueId = 1; // Left
+                        bool bFlipH = pShape->second->getFlipH();
+                        bool bFlipV = pShape->second->getFlipV();
+                        if ((!bFlipH && !bFlipV) || (bFlipH && bFlipV))
+                        {
+                            // change id of the left and right glue points of 
the bounding box (1 <-> 3)
+                            if (nGlueId == 1)
+                                nGlueId = 3; // Right
+                            else if (nGlueId == 3)
+                                nGlueId = 1; // Left
+                        }
                     }
 
                     bool bStart = aConnectorShapeProperties[j].mbStartShape;
diff --git a/sd/qa/unit/data/pptx/tdf154363.pptx 
b/sd/qa/unit/data/pptx/tdf154363.pptx
new file mode 100644
index 000000000000..b549fda90135
Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf154363.pptx differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 3ab567c43877..2d9422f4f3df 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -83,6 +83,7 @@ public:
     }
 
     void testDocumentLayout();
+    void testTdf154363();
     void testTdf152434();
     void testStandardConnectors();
     void testConnectors();
@@ -161,6 +162,7 @@ public:
     CPPUNIT_TEST_SUITE(SdImportTest);
 
     CPPUNIT_TEST(testDocumentLayout);
+    CPPUNIT_TEST(testTdf154363);
     CPPUNIT_TEST(testTdf152434);
     CPPUNIT_TEST(testStandardConnectors);
     CPPUNIT_TEST(testConnectors);
@@ -346,6 +348,30 @@ void SdImportTest::testDocumentLayout()
     }
 }
 
+void SdImportTest::testTdf154363()
+{
+    sal_Int32 nGlueId;
+    createSdImpressDoc("pptx/tdf154363.pptx");
+    {
+        uno::Reference<beans::XPropertySet> xConnector1(getShapeFromPage(1, 
0), uno::UNO_SET_THROW);
+        uno::Reference<beans::XPropertySet> xConnector2(getShapeFromPage(3, 
0), uno::UNO_SET_THROW);
+        nGlueId = 
xConnector1->getPropertyValue("StartGluePointIndex").get<sal_Int32>();
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1), nGlueId);
+        nGlueId = 
xConnector2->getPropertyValue("EndGluePointIndex").get<sal_Int32>();
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1), nGlueId);
+    }
+
+    saveAndReload("Impress MS PowerPoint 2007 XML");
+    {
+        uno::Reference<beans::XPropertySet> xConnector1(getShapeFromPage(1, 
0), uno::UNO_SET_THROW);
+        uno::Reference<beans::XPropertySet> xConnector2(getShapeFromPage(3, 
0), uno::UNO_SET_THROW);
+        nGlueId = 
xConnector1->getPropertyValue("StartGluePointIndex").get<sal_Int32>();
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1), nGlueId);
+        nGlueId = 
xConnector2->getPropertyValue("EndGluePointIndex").get<sal_Int32>();
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1), nGlueId);
+    }
+}
+
 void SdImportTest::testTdf152434()
 {
     createSdImpressDoc("pptx/tdf152434.pptx");

Reply via email to