include/oox/export/shapes.hxx | 4 ++- oox/source/export/shapes.cxx | 46 ++++++++++++++++++++----------------- sd/qa/unit/data/odp/tdf119223.odp |binary sd/qa/unit/data/xml/tdf90338_0.xml | 2 - sd/qa/unit/data/xml/tdf92001_0.xml | 2 - sd/qa/unit/export-tests-ooxml2.cxx | 36 ++++++++++++++++++++++++++++ 6 files changed, 66 insertions(+), 24 deletions(-)
New commits: commit 3212626c66205ab8f38cf17350522bd5705c77a8 Author: Mark Hung <mark...@gmail.com> AuthorDate: Sun Jun 28 10:57:09 2020 +0800 Commit: Gabor Kelemen <kelemen.gab...@nisz.hu> CommitDate: Thu Feb 25 13:43:59 2021 +0100 tdf#119223 export the object name for pptx documents. Originally the name was always an object type plus an index. That not only ignores the existing object name, but also makes an unnamed object named in the roundtrip. So here the object name is used no matter it is empty or not, to keep unamed object unamed. Change-Id: Ib29a8fbc1fd67fa9a4a4efbfd0b2e9c4fb50de0a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96908 Tested-by: Jenkins Reviewed-by: Mark Hung <mark...@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111536 Tested-by: Gabor Kelemen <kelemen.gab...@nisz.hu> Reviewed-by: Gabor Kelemen <kelemen.gab...@nisz.hu> diff --git a/include/oox/export/shapes.hxx b/include/oox/export/shapes.hxx index 2dbbb658c036..53d505f168a2 100644 --- a/include/oox/export/shapes.hxx +++ b/include/oox/export/shapes.hxx @@ -87,10 +87,12 @@ public: typedef std::unordered_map< css::uno::Reference< css::drawing::XShape>, sal_Int32> ShapeHashMap; protected: - sal_Int32 mnShapeIdMax, mnPictureIdMax; + sal_Int32 mnShapeIdMax; void WriteGraphicObjectShapePart( const css::uno::Reference< css::drawing::XShape >& xShape, const Graphic *pGraphic=nullptr ); + OUString GetShapeName(const css::uno::Reference< css::drawing::XShape >& xShape); + private: sal_Int32 mnXmlNamespace; MapMode maMapModeSrc, maMapModeDest; diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index 8a86bb07152c..ab0d53861d3e 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -91,7 +91,6 @@ using ::css::frame::XModel; using ::oox::core::XmlFilterBase; using ::sax_fastparser::FSHelperPtr; -#define IDS(x) OString(#x " " + OString::number(mnShapeIdMax++)).getStr() namespace oox { @@ -325,7 +324,6 @@ ShapeExport::ShapeExport( sal_Int32 nXmlNamespace, FSHelperPtr pFS, ShapeHashMap : DrawingML( std::move(pFS), pFB, eDocumentType, pTextExport ) , m_nEmbeddedObjects(0) , mnShapeIdMax( 1 ) - , mnPictureIdMax( 1 ) , mnXmlNamespace( nXmlNamespace ) , maMapModeSrc( MapUnit::Map100thMM ) , maMapModeDest( MapUnit::MapInch, Point(), Fraction( 1, 576 ), Fraction( 1, 576 ) ) @@ -416,7 +414,7 @@ ShapeExport& ShapeExport::WritePolyPolygonShape( const Reference< XShape >& xSha pFS->startElementNS(mnXmlNamespace, XML_nvSpPr); pFS->singleElementNS( mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), - XML_name, IDS( Freeform ) ); + XML_name, GetShapeName(xShape).toUtf8()); } pFS->singleElementNS(mnXmlNamespace, XML_cNvSpPr); if (GetDocumentType() != DOCUMENT_DOCX) @@ -477,7 +475,7 @@ ShapeExport& ShapeExport::WriteGroupShape(const uno::Reference<drawing::XShape>& pFS->startElementNS(mnXmlNamespace, XML_nvGrpSpPr); pFS->singleElementNS(mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), - XML_name, IDS(Group)); + XML_name, GetShapeName(xShape).toUtf8()); pFS->singleElementNS(mnXmlNamespace, XML_cNvGrpSpPr); WriteNonVisualProperties(xShape ); pFS->endElementNS(mnXmlNamespace, XML_nvGrpSpPr); @@ -803,7 +801,7 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape ) pFS->startElementNS( mnXmlNamespace, XML_nvSpPr ); pFS->startElementNS( mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), - XML_name, IDS( CustomShape ), + XML_name, GetShapeName(xShape).toUtf8(), XML_hidden, isVisible ? nullptr : "1" ); if( GETA( URL ) ) @@ -1061,7 +1059,7 @@ ShapeExport& ShapeExport::WriteEllipseShape( const Reference< XShape >& xShape ) pFS->startElementNS(mnXmlNamespace, XML_nvSpPr); pFS->singleElementNS( mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), - XML_name, IDS( Ellipse ) ); + XML_name, GetShapeName(xShape).toUtf8()); pFS->singleElementNS( mnXmlNamespace, XML_cNvSpPr ); WriteNonVisualProperties( xShape ); pFS->endElementNS( mnXmlNamespace, XML_nvSpPr ); @@ -1195,11 +1193,9 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape pFS->startElementNS(mnXmlNamespace, XML_nvPicPr); - OUString sName, sDescr, sURL; - bool bHaveName, bHaveDesc; + OUString sDescr, sURL; + bool bHaveDesc; - if ( ( bHaveName= GetProperty( xShapeProps, "Name" ) ) ) - mAny >>= sName; if ( ( bHaveDesc = GetProperty( xShapeProps, "Description" ) ) ) mAny >>= sDescr; if ( GetProperty( xShapeProps, "URL" ) ) @@ -1207,9 +1203,7 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape pFS->startElementNS( mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), - XML_name, bHaveName - ? sName.toUtf8() - : OString("Picture " + OString::number(mnPictureIdMax++)), + XML_name, GetShapeName(xShape).toUtf8(), XML_descr, bHaveDesc ? sDescr.toUtf8().getStr() : nullptr ); // OOXTODO: //cNvPr children: XML_extLst, XML_hlinkHover @@ -1362,7 +1356,7 @@ ShapeExport& ShapeExport::WriteConnectorShape( const Reference< XShape >& xShape pFS->startElementNS(mnXmlNamespace, XML_nvCxnSpPr); pFS->singleElementNS(mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), - XML_name, IDS(xShape)); + XML_name, GetShapeName(xShape).toUtf8()); // non visual connector shape drawing properties pFS->startElementNS(mnXmlNamespace, XML_cNvCxnSpPr); WriteConnectorConnections(aConnectorEntry, GetShapeID(rXShapeA), GetShapeID(rXShapeB)); @@ -1415,7 +1409,7 @@ ShapeExport& ShapeExport::WriteLineShape( const Reference< XShape >& xShape ) pFS->startElementNS(mnXmlNamespace, XML_nvSpPr); pFS->singleElementNS( mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), - XML_name, IDS( Line ) ); + XML_name, GetShapeName(xShape).toUtf8()); } pFS->singleElementNS( mnXmlNamespace, XML_cNvSpPr ); if (GetDocumentType() != DOCUMENT_DOCX) @@ -1490,7 +1484,7 @@ ShapeExport& ShapeExport::WriteRectangleShape( const Reference< XShape >& xShape pFS->startElementNS(mnXmlNamespace, XML_nvSpPr); pFS->singleElementNS( mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), - XML_name, IDS( Rectangle ) ); + XML_name, GetShapeName(xShape).toUtf8()); pFS->singleElementNS(mnXmlNamespace, XML_cNvSpPr); WriteNonVisualProperties( xShape ); pFS->endElementNS( mnXmlNamespace, XML_nvSpPr ); @@ -1868,7 +1862,7 @@ ShapeExport& ShapeExport::WriteTableShape( const Reference< XShape >& xShape ) pFS->singleElementNS( mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), - XML_name, IDS(Table) ); + XML_name, GetShapeName(xShape).toUtf8()); pFS->singleElementNS(mnXmlNamespace, XML_cNvGraphicFramePr); @@ -1897,7 +1891,7 @@ ShapeExport& ShapeExport::WriteTextShape( const Reference< XShape >& xShape ) pFS->startElementNS(mnXmlNamespace, XML_nvSpPr); pFS->startElementNS(mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), - XML_name, IDS(TextShape)); + XML_name, GetShapeName(xShape).toUtf8()); OUString sURL; if (GetProperty(xShapeProps, "URL")) mAny >>= sURL; @@ -1960,7 +1954,7 @@ void ShapeExport::WriteMathShape(Reference<XShape> const& xShape) mpFS->startElementNS(mnXmlNamespace, XML_nvSpPr); mpFS->singleElementNS(mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), - XML_name, IDS(Formula)); + XML_name, GetShapeName(xShape).toUtf8()); mpFS->singleElementNS(mnXmlNamespace, XML_cNvSpPr, XML_txBox, "1"); mpFS->singleElementNS(mnXmlNamespace, XML_nvPr); mpFS->endElementNS(mnXmlNamespace, XML_nvSpPr); @@ -2133,7 +2127,7 @@ ShapeExport& ShapeExport::WriteOLE2Shape( const Reference< XShape >& xShape ) mpFS->singleElementNS( mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), - XML_name, IDS(Object) ); + XML_name, GetShapeName(xShape).toUtf8()); mpFS->singleElementNS(mnXmlNamespace, XML_cNvGraphicFramePr); @@ -2226,6 +2220,18 @@ sal_Int32 ShapeExport::GetShapeID( const Reference< XShape >& rXShape, ShapeHash return aIter->second; } +OUString ShapeExport::GetShapeName(const Reference<XShape>& xShape) +{ + Reference<XPropertySet> rXPropSet(xShape, UNO_QUERY); + + // Empty name keeps the object unnamed. + OUString sName; + + if (GetProperty(rXPropSet, "Name")) + mAny >>= sName; + return sName; +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/qa/unit/data/odp/tdf119223.odp b/sd/qa/unit/data/odp/tdf119223.odp new file mode 100644 index 000000000000..efb4306b9c04 Binary files /dev/null and b/sd/qa/unit/data/odp/tdf119223.odp differ diff --git a/sd/qa/unit/data/xml/tdf90338_0.xml b/sd/qa/unit/data/xml/tdf90338_0.xml index a357211c6a0a..2f779413596b 100644 --- a/sd/qa/unit/data/xml/tdf90338_0.xml +++ b/sd/qa/unit/data/xml/tdf90338_0.xml @@ -1,6 +1,6 @@ <?xml version="1.0"?> <XShapes> - <XShape positionX="5498" positionY="2715" sizeX="11630" sizeY="8623" type="com.sun.star.drawing.CustomShape" name="CustomShape 1" fontHeight="18.000000" fontColor="ffffffff" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="BLOCK" textVerticalAdjust="TOP" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="SOLID" fillColor="e7e6e6" fillTransparence="0" fillTransparenceGradientName=""> + <XShape positionX="5498" positionY="2715" sizeX="11630" sizeY="8623" type="com.sun.star.drawing.CustomShape" name="Freeform 3" fontHeight="18.000000" fontColor="ffffffff" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="BLOCK" textVerticalAdjust="TOP" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="SOLID" fillColor="e7e6e6" fillTransparence="0" fillTransparenceGradientName=""> <FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillGradient style="LINEAR" startColor="3465a4" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillHatch style="SINGLE" color="3465a4" distance="20" angle="0"/> diff --git a/sd/qa/unit/data/xml/tdf92001_0.xml b/sd/qa/unit/data/xml/tdf92001_0.xml index 3bfe7f391c88..40e64cdc1cea 100644 --- a/sd/qa/unit/data/xml/tdf92001_0.xml +++ b/sd/qa/unit/data/xml/tdf92001_0.xml @@ -1,6 +1,6 @@ <?xml version="1.0"?> <XShapes> - <XShape positionX="4826" positionY="4826" sizeX="19557" sizeY="12953" type="com.sun.star.drawing.CustomShape" name="CustomShape 1" fontHeight="18.000000" fontColor="ffffffff" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="BLOCK" textVerticalAdjust="TOP" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="SOLID" fillColor="729fcf" fillTransparence="0" fillTransparenceGradientName=""> + <XShape positionX="4826" positionY="4826" sizeX="19557" sizeY="12953" type="com.sun.star.drawing.CustomShape" fontHeight="18.000000" fontColor="ffffffff" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="BLOCK" textVerticalAdjust="TOP" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="SOLID" fillColor="729fcf" fillTransparence="0" fillTransparenceGradientName=""> <FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillGradient style="LINEAR" startColor="3465a4" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillHatch style="SINGLE" color="3465a4" distance="20" angle="0"/> diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx index c6d2f48aedde..cfbafb4a5352 100644 --- a/sd/qa/unit/export-tests-ooxml2.cxx +++ b/sd/qa/unit/export-tests-ooxml2.cxx @@ -197,6 +197,7 @@ public: void testTdf132282(); void testTdf132201EffectOrder(); void testShapeSoftEdgeEffect(); + void testTdf119223(); CPPUNIT_TEST_SUITE(SdOOXMLExportTest2); @@ -311,6 +312,7 @@ public: CPPUNIT_TEST(testTdf132282); CPPUNIT_TEST(testTdf132201EffectOrder); CPPUNIT_TEST(testShapeSoftEdgeEffect); + CPPUNIT_TEST(testTdf119223); CPPUNIT_TEST_SUITE_END(); @@ -1579,7 +1581,7 @@ void SdOOXMLExportTest2::testTdf114845_rotateShape() xDocShRef->DoClose(); xmlDocUniquePtr pXmlDocContent = parseExport(tempFile, "ppt/slides/slide1.xml"); - assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp[5]/p:nvSpPr/p:cNvPr", "name", "CustomShape 5"); + assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp[5]/p:nvSpPr/p:cNvPr", "name", "Straight Arrow Connector 9"); assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp[5]/p:spPr/a:xfrm", "flipV", "1"); double dX = getXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp[5]/p:spPr/a:xfrm/a:off", "x").toDouble(); double dY = getXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp[5]/p:spPr/a:xfrm/a:off", "y").toDouble(); @@ -2923,6 +2925,38 @@ void SdOOXMLExportTest2::testShapeSoftEdgeEffect() CPPUNIT_ASSERT_EQUAL(sal_Int32(635), nRadius); // 18 pt } +void SdOOXMLExportTest2::testTdf119223() +{ + auto xDocShRef + = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/odp/tdf119223.odp"), ODP); + utl::TempFile tempFile; + xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile); + + xDocShRef->DoClose(); + + xmlDocUniquePtr pXmlDocRels = parseExport(tempFile, "ppt/slides/slide1.xml"); + assertXPath(pXmlDocRels, + "//p:cNvPr[@name='SomeCustomShape']"); + + assertXPath(pXmlDocRels, + "//p:cNvPr[@name='SomePicture']"); + + assertXPath(pXmlDocRels, + "//p:cNvPr[@name='SomeFormula']"); + + assertXPath(pXmlDocRels, + "//p:cNvPr[@name='SomeLine']"); + + assertXPath(pXmlDocRels, + "//p:cNvPr[@name='SomeTextbox']"); + + assertXPath(pXmlDocRels, + "//p:cNvPr[@name='SomeTable']"); + + assertXPath(pXmlDocRels, + "//p:cNvPr[@name='SomeGroup']"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest2); CPPUNIT_PLUGIN_IMPLEMENT(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits