oox/source/ppt/slidepersist.cxx      |   24 +++++++++++++++++++-----
 sd/qa/unit/data/pptx/connectors.pptx |binary
 sd/qa/unit/import-tests.cxx          |   16 ++++++++++++----
 3 files changed, 31 insertions(+), 9 deletions(-)

New commits:
commit d8c89fb920af747ec51ce966b5d7b65e9340afbd
Author:     Tibor Nagy <nagy.tib...@nisz.hu>
AuthorDate: Fri Nov 4 20:58:36 2022 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Mon Nov 14 13:31:36 2022 +0100

    tdf#151891 PPTX import: fix regression of connector position
    
    If the connector shape is connected to the glue point which there
    is inside the bounding box, then the position of connector appear
    incorrectly, for example different direction of the arrow head.
    
    Regression likely from commit cbf66ec3e60d07efb7c3cceed9b4f0fb4f0510c8
    "tdf#89449 PPTX import: fix line connectors", as tdf#148926.
    
    Follow-up to commit eec48130271188cab63665acedbabf1ff5e850a2
    "tdf#148926 tdf#151678 PPTX import: position of standard connector
     - part1".
    
    Change-Id: I5671bc70e663a979c43bad1b786118a6a9e92972
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142293
    Reviewed-by: László Németh <nem...@numbertext.org>
    Tested-by: László Németh <nem...@numbertext.org>

diff --git a/oox/source/ppt/slidepersist.cxx b/oox/source/ppt/slidepersist.cxx
index 126fc664bd3a..3b9a93ded03c 100644
--- a/oox/source/ppt/slidepersist.cxx
+++ b/oox/source/ppt/slidepersist.cxx
@@ -46,6 +46,7 @@
 #include <com/sun/star/drawing/EnhancedCustomShapeGluePointType.hpp>
 #include <com/sun/star/drawing/ConnectorType.hpp>
 #include <utility>
+#include <svx/svdobj.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::oox::core;
@@ -355,6 +356,7 @@ static void 
lcl_SetEdgeLineValue(uno::Reference<drawing::XShape>& rXConnector,
 {
     sal_Int32 nEdge = 0;
     awt::Point aStartPt, aEndPt;
+    tools::Rectangle aStartRect, aEndRect;
     uno::Reference<drawing::XShape> xStartSp, xEndSp;
     uno::Reference<beans::XPropertySet> xPropSet(rXConnector, uno::UNO_QUERY);
     xPropSet->getPropertyValue("EdgeStartPoint") >>= aStartPt;
@@ -366,6 +368,14 @@ static void 
lcl_SetEdgeLineValue(uno::Reference<drawing::XShape>& rXConnector,
     xPropSet->setPropertyValue("EdgeNode2HorzDist", Any(sal_Int32(0)));
     xPropSet->setPropertyValue("EdgeNode2VertDist", Any(sal_Int32(0)));
 
+    SdrObject* pStartObj = xStartSp.is() ? 
SdrObject::getSdrObjectFromXShape(xStartSp) : nullptr;
+    SdrObject* pEndObj = xEndSp.is() ? 
SdrObject::getSdrObjectFromXShape(xEndSp) : nullptr;
+
+    if (pStartObj)
+        aStartRect = pStartObj->GetSnapRect();
+    if (pEndObj)
+        aEndRect = pEndObj->GetSnapRect();
+
     const OUString sConnectorName = rShapePtr->getConnectorName();
     if (sConnectorName == "bentConnector2")
     {
@@ -375,16 +385,20 @@ static void 
lcl_SetEdgeLineValue(uno::Reference<drawing::XShape>& rXConnector,
             if (aConnSize.Height < aConnSize.Width)
             {
                 if (xStartSp.is())
-                    nEdge = (aStartPt.Y > aEndPt.Y) ? -aConnSize.Height : 
aConnSize.Height;
+                    nEdge -= (aStartPt.Y > aEndPt.Y) ? (aStartRect.Top() - 
aEndPt.Y)
+                                                     : (aStartRect.Bottom() - 
aEndPt.Y);
                 else
-                    nEdge = (aStartPt.Y > aEndPt.Y) ? aConnSize.Height : 
-aConnSize.Height;
+                    nEdge -= (aStartPt.Y > aEndPt.Y) ? (aEndRect.Bottom() - 
aStartPt.Y)
+                                                     : (aEndRect.Top() - 
aStartPt.Y);
             }
             else
             {
                 if (xStartSp.is())
-                    nEdge = (aStartPt.X > aEndPt.X) ? -aConnSize.Width : 
aConnSize.Width;
+                    nEdge -= (aStartPt.X > aEndPt.X) ? (aStartRect.Left() - 
aEndPt.X)
+                                                     : (aStartRect.Right() - 
aEndPt.X);
                 else
-                    nEdge = (aStartPt.X > aEndPt.X) ? aConnSize.Width : 
-aConnSize.Width;
+                    nEdge -= (aStartPt.X > aEndPt.X) ? (aEndRect.Right() - 
aStartPt.X)
+                                                     : (aEndRect.Left() - 
aStartPt.X);
             }
         }
         else
@@ -395,7 +409,7 @@ static void 
lcl_SetEdgeLineValue(uno::Reference<drawing::XShape>& rXConnector,
             if (aConnSize.Height < aConnSize.Width)
             {
                 if ((nConnectorAngle == 90 && bFlipH && bFlipV) || 
(nConnectorAngle == 180)
-                    || (nConnectorAngle == 180 && bFlipV) || (nConnectorAngle 
== 270 && bFlipH))
+                    || (nConnectorAngle == 270 && bFlipH))
                     nEdge -= aConnSize.Width;
                 else
                     nEdge += aConnSize.Width;
diff --git a/sd/qa/unit/data/pptx/connectors.pptx 
b/sd/qa/unit/data/pptx/connectors.pptx
index fa03ef0f6046..ba959068663c 100644
Binary files a/sd/qa/unit/data/pptx/connectors.pptx and 
b/sd/qa/unit/data/pptx/connectors.pptx differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 6e10700d5671..34523fa136cd 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -344,12 +344,20 @@ void SdImportTest::testConnectors()
 {
     loadFromURL(u"pptx/connectors.pptx");
 
-    sal_Int32 aEdgeValue[] = { -1167, -1167, -1591, 1476, 1357, -1357, 1604, 
-1540 };
-    for (size_t i = 1; i < 9; i++)
+    sal_Int32 aEdgeValue[] = { -1167, -1167, -1591, 1476,  1356, -1357, 1604,  
-1540,
+                               607,   1296,  -1638, -1060, -522, 1578,  -1291, 
333 };
+
+    sal_Int32 nCount = 0;
+    for (size_t i = 0; i < 18; i++)
     {
         uno::Reference<beans::XPropertySet> xConnector(getShapeFromPage(i, 0));
-        sal_Int32 nEdgeLine = 
xConnector->getPropertyValue("EdgeLine1Delta").get<sal_Int32>();
-        CPPUNIT_ASSERT_EQUAL(aEdgeValue[i - 1], nEdgeLine);
+        bool bConnector = 
xConnector->getPropertySetInfo()->hasPropertyByName("EdgeLine1Delta");
+        if (bConnector)
+        {
+            sal_Int32 nEdgeLine = 
xConnector->getPropertyValue("EdgeLine1Delta").get<sal_Int32>();
+            CPPUNIT_ASSERT_EQUAL(aEdgeValue[nCount], nEdgeLine);
+            nCount++;
+        }
     }
 }
 

Reply via email to