From a14531e4135a82df53615254cac5e9ea0c357ef4 Mon Sep 17 00:00:00 2001 From: Tibor Nagy Date: Fri, 5 Jul 2024 08:37:21 +0200 Subject: The connector shape is losing its connection The issue is that we are trying to set the connector shape properties too early, but the shapes that we want to connect to have not been created yet. Follow-up to commit Ie95ccd5bcd4d5c3f9c45c7dcc4f88acc0c9438aa "tdf#157172 tdf#157460 PPTX import: fix connectors adjustment values" Change-Id: I63c76535cc718bc46d5c3ed5489b752925cd6a77 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170007 Tested-by: Jenkins Reviewed-by: Nagy Tibor --- oox/qa/unit/data/connectorConnection.pptx | Bin 0 -> 33296 bytes oox/qa/unit/shape.cxx | 28 ++++++++++++++++ oox/source/ppt/slidepersist.cxx | 54 +++++++++++++++--------------- 3 files changed, 55 insertions(+), 27 deletions(-) create mode 100644 oox/qa/unit/data/connectorConnection.pptx (limited to 'oox') diff --git a/oox/qa/unit/data/connectorConnection.pptx b/oox/qa/unit/data/connectorConnection.pptx new file mode 100644 index 000000000000..e8a86a157151 Binary files /dev/null and b/oox/qa/unit/data/connectorConnection.pptx differ diff --git a/oox/qa/unit/shape.cxx b/oox/qa/unit/shape.cxx index 3e4c270162c1..28266b8783c6 100644 --- a/oox/qa/unit/shape.cxx +++ b/oox/qa/unit/shape.cxx @@ -92,6 +92,34 @@ uno::Reference OoxShapeTest::getShapeByName(std::u16string_view return xRet; } +CPPUNIT_TEST_FIXTURE(OoxShapeTest, testConnectorConnection) +{ + loadFromFile(u"connectorConnection.pptx"); + + uno::Reference xDrawPagesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + + uno::Reference xConnector(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xConnectorProps(xConnector, uno::UNO_QUERY); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 + // - Actual : -1 + // i.e. the connector shape is not attaching to the shape + sal_Int32 nStartGlueId; + xConnectorProps->getPropertyValue("StartGluePointIndex") >>= nStartGlueId; + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nStartGlueId); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2 + // - Actual : -1 + // i.e. the connector shape is not attaching to the shape + sal_Int32 nEndGlueId; + xConnectorProps->getPropertyValue("EndGluePointIndex") >>= nEndGlueId; + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), nEndGlueId); +} + CPPUNIT_TEST_FIXTURE(OoxShapeTest, testElbowConnectors) { loadFromFile(u"elbowConnectors.pptx"); diff --git a/oox/source/ppt/slidepersist.cxx b/oox/source/ppt/slidepersist.cxx index 2164311a0bfb..915ce1a1d733 100644 --- a/oox/source/ppt/slidepersist.cxx +++ b/oox/source/ppt/slidepersist.cxx @@ -164,6 +164,7 @@ void SlidePersist::createXShapes( XmlFilterBase& rFilterBase ) Reference< XShapes > xShapes( getPage() ); std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() ); + oox::drawingml::ShapeIdMap aConnectorShapeMap; for (auto const& shape : rShapes) { @@ -176,40 +177,39 @@ void SlidePersist::createXShapes( XmlFilterBase& rFilterBase ) { pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, aTransformation, &getShapeMap() ); - oox::drawingml::ShapeIdMap aConnectorShapeMap; const auto& pIter = maShapeMap.find(pPPTShape->getId()); if (pIter != maShapeMap.end()) lcl_createShapeMap(pIter->second, aConnectorShapeMap); + } + else + child->addShape( rFilterBase, getTheme().get(), xShapes, aTransformation, maShapesPtr->getFillProperties(), &getShapeMap() ); + } + } - if(!aConnectorShapeMap.empty()) - { - for (auto& pIt : aConnectorShapeMap) - { - SdrObject* pObj = SdrObject::getSdrObjectFromXShape(pIt.second->getXShape()); - SdrModel& rModel(pObj->getSdrModelFromSdrObject()); - rModel.setLock(false); + if (!aConnectorShapeMap.empty()) + { + for (auto& pIt : aConnectorShapeMap) + { + ConnectorHelper::applyConnections(pIt.second, getShapeMap()); - ConnectorHelper::applyConnections(pIt.second, getShapeMap()); + SdrObject* pObj = SdrObject::getSdrObjectFromXShape(pIt.second->getXShape()); + SdrModel& rModel(pObj->getSdrModelFromSdrObject()); + rModel.setLock(false); - if (pIt.second->getConnectorName() == u"bentConnector3"_ustr - || pIt.second->getConnectorName() == u"bentConnector4"_ustr - || pIt.second->getConnectorName() == u"bentConnector5"_ustr) - { - ConnectorHelper::applyBentHandleAdjustments(pIt.second); - } - else if (pIt.second->getConnectorName() == u"curvedConnector3"_ustr - || pIt.second->getConnectorName() == u"curvedConnector4"_ustr - || pIt.second->getConnectorName() == u"curvedConnector5"_ustr) - { - ConnectorHelper::applyCurvedHandleAdjustments(pIt.second); - } - else // bentConnector2 - createConnectorShapeConnection(pIt.second); - } - } + if (pIt.second->getConnectorName() == u"bentConnector3"_ustr + || pIt.second->getConnectorName() == u"bentConnector4"_ustr + || pIt.second->getConnectorName() == u"bentConnector5"_ustr) + { + ConnectorHelper::applyBentHandleAdjustments(pIt.second); } - else - child->addShape( rFilterBase, getTheme().get(), xShapes, aTransformation, maShapesPtr->getFillProperties(), &getShapeMap() ); + else if (pIt.second->getConnectorName() == u"curvedConnector3"_ustr + || pIt.second->getConnectorName() == u"curvedConnector4"_ustr + || pIt.second->getConnectorName() == u"curvedConnector5"_ustr) + { + ConnectorHelper::applyCurvedHandleAdjustments(pIt.second); + } + else // bentConnector2 + createConnectorShapeConnection(pIt.second); } } -- cgit v1.2.3