include/oox/export/drawingml.hxx    |    2 +-
 oox/source/export/drawingml.cxx     |    6 +++---
 oox/source/export/shapes.cxx        |   33 ++++++++++++++++++++++++++++++++-
 sd/qa/unit/data/pptx/tdf149697.pptx |binary
 sd/qa/unit/export-tests-ooxml2.cxx  |   25 +++++++++++++++++++++++++
 5 files changed, 61 insertions(+), 5 deletions(-)

New commits:
commit 4d153517183193f468dee9148c94fe9d874bacb3
Author:     Tibor Nagy <nagy.tib...@nisz.hu>
AuthorDate: Mon Jun 27 09:45:04 2022 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Fri Jul 22 13:40:25 2022 +0200

    tdf#149697 PPTX export: fix changing place of connection points
    
    Place of the connection point of a polygon changed during
    a PPTX round-trip, connecting other vertices of e.g. a square
    or a hexagon, as before.
    
    See also commit c3f73f75772d076dfb2ed0538e7d515503edc038
    "tdf#149128 PPTX export: fix <stCxn> and <endCxn> connector properties".
    
    Change-Id: I64fc6377417a99d32e84ea71fbed13cf36760118
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136474
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index 455676e9c262..c80024ea1fdd 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -231,7 +231,7 @@ public:
     void WriteColorTransformations( const css::uno::Sequence< 
css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
     void WriteGradientStop(sal_uInt16 nStop, ::Color nColor, sal_Int32 nAlpha 
= MAX_PERCENT);
     void WriteLineArrow( const css::uno::Reference< css::beans::XPropertySet 
>& rXPropSet, bool bLineStart );
-    void WriteConnectorConnections( EscherConnectorListEntry& rConnectorEntry, 
sal_Int32 nStartID, sal_Int32 nEndID );
+    void WriteConnectorConnections( sal_uInt32 nStartGlueId, sal_Int32 
nEndGlueId, sal_Int32 nStartID, sal_Int32 nEndID );
 
     bool WriteCharColor(const css::uno::Reference<css::beans::XPropertySet>& 
xPropertySet);
     bool WriteFillColor(const css::uno::Reference<css::beans::XPropertySet>& 
xPropertySet);
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index d889f475c556..392ce6f4d6aa 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -4747,19 +4747,19 @@ void DrawingML::WritePolyPolygon(const 
css::uno::Reference<css::drawing::XShape>
     mpFS->endElementNS(XML_a, XML_custGeom);
 }
 
-void DrawingML::WriteConnectorConnections( EscherConnectorListEntry& 
rConnectorEntry, sal_Int32 nStartID, sal_Int32 nEndID )
+void DrawingML::WriteConnectorConnections( sal_uInt32 nStartGlueId, sal_Int32 
nEndGlueId, sal_Int32 nStartID, sal_Int32 nEndID )
 {
     if( nStartID != -1 )
     {
         mpFS->singleElementNS( XML_a, XML_stCxn,
                                XML_id, OString::number(nStartID),
-                               XML_idx, 
OString::number(rConnectorEntry.GetConnectorRule(true)) );
+                               XML_idx, OString::number(nStartGlueId) );
     }
     if( nEndID != -1 )
     {
         mpFS->singleElementNS( XML_a, XML_endCxn,
                                XML_id, OString::number(nEndID),
-                               XML_idx, 
OString::number(rConnectorEntry.GetConnectorRule(false)) );
+                               XML_idx, OString::number(nEndGlueId) );
     }
 }
 
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index f0b446a7eb33..19ef8156f3e3 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -63,6 +63,8 @@
 #include <com/sun/star/drawing/XDrawPages.hpp>
 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
 #include <com/sun/star/presentation/ClickAction.hpp>
+#include <com/sun/star/drawing/XGluePointsSupplier.hpp>
+#include <com/sun/star/container/XIdentifierAccess.hpp>
 #include <tools/globname.hxx>
 #include <comphelper/classids.hxx>
 #include <comphelper/propertysequence.hxx>
@@ -1636,11 +1638,33 @@ static void lcl_GetConnectorAdjustValue(const 
Reference<XShape>& xShape, tools::
     }
 }
 
+static sal_Int32 lcl_GetGluePointId(const Reference<XShape>& xShape, 
sal_Int32& nGluePointId)
+{
+    uno::Reference<drawing::XGluePointsSupplier> xSupplier(xShape, 
uno::UNO_QUERY);
+    uno::Reference<container::XIdentifierAccess> 
xGluePoints(xSupplier->getGluePoints(),
+                                                             uno::UNO_QUERY);
+    sal_uInt32 nCount = xGluePoints->getIdentifiers().size();
+    if (nCount > 4)
+        nGluePointId -= 4;
+    else
+    {
+        // change id of the bounding box (1 <-> 3)
+        if (nGluePointId == 1)
+            nGluePointId = 3; // Right
+        else if (nGluePointId == 3)
+            nGluePointId = 1; // Left
+    }
+
+    return nGluePointId;
+}
+
 ShapeExport& ShapeExport::WriteConnectorShape( const Reference< XShape >& 
xShape )
 {
     bool bFlipH = false;
     bool bFlipV = false;
     sal_Int32 nAngle = 0;
+    sal_Int32 nStartGlueId = 0;
+    sal_Int32 nEndGlueId = 0;
 
     SAL_INFO("oox.shape", "write connector shape");
 
@@ -1680,6 +1704,13 @@ ShapeExport& ShapeExport::WriteConnectorShape( const 
Reference< XShape >& xShape
     GET( rXShapeA, EdgeStartConnection );
     GET( rXShapeB, EdgeEndConnection );
 
+    GET(nStartGlueId, StartGluePointIndex);
+    if (nStartGlueId != -1)
+        lcl_GetGluePointId(rXShapeA, nStartGlueId);
+    GET(nEndGlueId, EndGluePointIndex);
+    if (nEndGlueId != -1)
+        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())
     {
@@ -1749,7 +1780,7 @@ ShapeExport& ShapeExport::WriteConnectorShape( const 
Reference< XShape >& xShape
             GetNewShapeID(rXShapeA);
         if (GetShapeID(rXShapeB) == -1)
             GetNewShapeID(rXShapeB);
-        WriteConnectorConnections(aConnectorEntry, GetShapeID(rXShapeA), 
GetShapeID(rXShapeB));
+        WriteConnectorConnections(nStartGlueId, nEndGlueId, 
GetShapeID(rXShapeA), GetShapeID(rXShapeB));
         pFS->endElementNS(mnXmlNamespace, XML_cNvCxnSpPr);
         if (GetDocumentType() == DOCUMENT_PPTX)
             pFS->singleElementNS(mnXmlNamespace, XML_nvPr);
diff --git a/sd/qa/unit/data/pptx/tdf149697.pptx 
b/sd/qa/unit/data/pptx/tdf149697.pptx
new file mode 100644
index 000000000000..b8209e360a79
Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf149697.pptx differ
diff --git a/sd/qa/unit/export-tests-ooxml2.cxx 
b/sd/qa/unit/export-tests-ooxml2.cxx
index 0029f882463b..c74f5e41d925 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -70,6 +70,7 @@ static void assertMotionPath(std::u16string_view rStr1, 
std::u16string_view rStr
 class SdOOXMLExportTest2 : public SdModelTestBaseXML
 {
 public:
+    void testTdf149697();
     void testTdf149126();
     void testTdf131905();
     void testTdf93883();
@@ -138,6 +139,7 @@ public:
 
     CPPUNIT_TEST_SUITE(SdOOXMLExportTest2);
 
+    CPPUNIT_TEST(testTdf149697);
     CPPUNIT_TEST(testTdf149126);
     CPPUNIT_TEST(testTdf131905);
     CPPUNIT_TEST(testTdf93883);
@@ -212,6 +214,29 @@ public:
     }
 };
 
+void SdOOXMLExportTest2::testTdf149697()
+{
+    ::sd::DrawDocShellRef xDocShRef
+        = 
loadURL(m_directories.getURLFromSrc(u"/sd/qa/unit/data/pptx/tdf149697.pptx"), 
PPTX);
+    utl::TempFile tempFile;
+    xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
+
+    xmlDocUniquePtr pXmlDocContent = parseExport(tempFile, 
"ppt/slides/slide1.xml");
+    assertXPath(pXmlDocContent, 
"/p:sld/p:cSld/p:spTree/p:cxnSp[1]/p:nvCxnSpPr/p:cNvCxnSpPr/a:stCxn",
+                "idx", "5");
+
+    assertXPath(pXmlDocContent, 
"/p:sld/p:cSld/p:spTree/p:cxnSp[1]/p:nvCxnSpPr/p:cNvCxnSpPr/a:endCxn",
+                "idx", "4");
+
+    assertXPath(pXmlDocContent, 
"/p:sld/p:cSld/p:spTree/p:cxnSp[2]/p:nvCxnSpPr/p:cNvCxnSpPr/a:stCxn",
+        "idx", "3");
+
+    assertXPath(pXmlDocContent, 
"/p:sld/p:cSld/p:spTree/p:cxnSp[2]/p:nvCxnSpPr/p:cNvCxnSpPr/a:endCxn",
+        "idx", "1");
+
+    xDocShRef->DoClose();
+}
+
 void SdOOXMLExportTest2::testTdf149126()
 {
     ::sd::DrawDocShellRef xDocShRef

Reply via email to