oox/source/export/shapes.cxx | 6 ++- sc/qa/unit/data/xlsx/tdf169496_hidden_graphic.xlsx |binary sc/qa/unit/subsequent_export_test4.cxx | 39 +++++++++++++++++++++ sd/qa/unit/data/pptx/tdf169496_hidden_graphic.pptx |binary sd/qa/unit/export-tests-ooxml4.cxx | 37 +++++++++++++++++++ 5 files changed, 81 insertions(+), 1 deletion(-)
New commits: commit 5a22c7cd10014ec6919b19a00b2861e7be4ce8d0 Author: Aron Budea <[email protected]> AuthorDate: Tue Nov 18 12:31:21 2025 +1030 Commit: Xisco Fauli <[email protected]> CommitDate: Thu Nov 20 22:50:49 2025 +0100 tdf#169496 oox: hidden images in PPTX/XLSX shown after roundtrip Because 'hidden' attribute of 'cNvPr' wasn't exported. Change-Id: I5f8a79232e3b76f04269caae0631ba5b9710443a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194142 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> Reviewed-by: Aron Budea <[email protected]> (cherry picked from commit a913faf181afb8b8718711eba0ad0cceec961f01) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194246 Reviewed-by: Xisco Fauli <[email protected]> diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index 4ba318720479..64904f5ed124 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -1422,11 +1422,14 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape presentation::ClickAction eClickAction = presentation::ClickAction_NONE; OUString sDescr, sURL, sBookmark, sPPAction; + bool bVisible = true; if ( GetProperty( xShapeProps, u"Description"_ustr ) ) mAny >>= sDescr; if ( GetProperty( xShapeProps, u"URL"_ustr ) ) mAny >>= sURL; + if ( GetProperty( xShapeProps, u"Visible"_ustr ) ) + mAny >>= bVisible; if (GetProperty(xShapeProps, u"Bookmark"_ustr)) mAny >>= sBookmark; if (GetProperty(xShapeProps, u"OnClick"_ustr)) @@ -1435,7 +1438,8 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape pFS->startElementNS( mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetNewShapeID(xShape)), XML_name, GetShapeName(xShape), - XML_descr, sax_fastparser::UseIf(sDescr, !sDescr.isEmpty())); + XML_descr, sax_fastparser::UseIf(sDescr, !sDescr.isEmpty()), + XML_hidden, sax_fastparser::UseIf("1", !bVisible)); if (eClickAction != presentation::ClickAction_NONE) { diff --git a/sc/qa/unit/data/xlsx/tdf169496_hidden_graphic.xlsx b/sc/qa/unit/data/xlsx/tdf169496_hidden_graphic.xlsx new file mode 100644 index 000000000000..ce1a9a75c14a Binary files /dev/null and b/sc/qa/unit/data/xlsx/tdf169496_hidden_graphic.xlsx differ diff --git a/sc/qa/unit/subsequent_export_test4.cxx b/sc/qa/unit/subsequent_export_test4.cxx index 25efb2268b59..30f223630afd 100644 --- a/sc/qa/unit/subsequent_export_test4.cxx +++ b/sc/qa/unit/subsequent_export_test4.cxx @@ -1082,6 +1082,45 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf139258_rotated_image) assertXPathContent(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:to/xdr:row", u"25"); } +CPPUNIT_TEST_FIXTURE(ScExportTest4, testtdf169496_hidden_graphic) +{ + createScDoc("xlsx/tdf169496_hidden_graphic.xlsx"); + + save(u"Calc Office Open XML"_ustr); + + xmlDocUniquePtr pDrawing = parseExport(u"xl/drawings/drawing1.xml"_ustr); + CPPUNIT_ASSERT(pDrawing); + + // Graphic 4 is hidden and Graphic 3 is visible, but their order might change in the XML + // Without the fix the hidden attribute wasn't exported + OUString sName1 = getXPath( + pDrawing, "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:pic/xdr:nvPicPr/xdr:cNvPr", "name"); + OUString sName2 = getXPath( + pDrawing, "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:pic/xdr:nvPicPr/xdr:cNvPr", "name"); + if (sName1 == "Graphic 4" && sName2 == "Graphic 3") + { + OUString aHidden = getXPath( + pDrawing, "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:pic/xdr:nvPicPr/xdr:cNvPr", "hidden"); + bool bHidden = aHidden == u"true"_ustr || aHidden == u"1"; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Graphic 3 is supposed to be hidden", true, bHidden); + + assertXPathNoAttribute( + pDrawing, "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:pic/xdr:nvPicPr/xdr:cNvPr", "hidden"); + } + else if (sName1 == "Graphic 3" && sName2 == "Graphic 4") + { + assertXPathNoAttribute( + pDrawing, "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:pic/xdr:nvPicPr/xdr:cNvPr", "hidden"); + + OUString aHidden = getXPath( + pDrawing, "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:pic/xdr:nvPicPr/xdr:cNvPr", "hidden"); + bool bHidden = aHidden == u"true"_ustr || aHidden == u"1"; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Graphic 4 is supposed to be hidden", true, bHidden); + } + else + CPPUNIT_FAIL("Names of graphics is incorrect"); +} + CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf144642_RowHeightRounding) { // MS Excel round down row heights to 0.75pt diff --git a/sd/qa/unit/data/pptx/tdf169496_hidden_graphic.pptx b/sd/qa/unit/data/pptx/tdf169496_hidden_graphic.pptx new file mode 100644 index 000000000000..a87c644e9cc3 Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf169496_hidden_graphic.pptx differ diff --git a/sd/qa/unit/export-tests-ooxml4.cxx b/sd/qa/unit/export-tests-ooxml4.cxx index d5f5d4404b41..2dbcae675ab8 100644 --- a/sd/qa/unit/export-tests-ooxml4.cxx +++ b/sd/qa/unit/export-tests-ooxml4.cxx @@ -1429,6 +1429,43 @@ CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest4, testOLEObjectAnimationTarget) "spid", sOleId); } +CPPUNIT_TEST_FIXTURE(SdOOXMLExportTest4, testtdf169496_hidden_graphic) +{ + createSdImpressDoc("pptx/tdf169496_hidden_graphic.pptx"); + save(u"Impress Office Open XML"_ustr); + + xmlDocUniquePtr pXmlDoc = parseExport(u"ppt/slides/slide1.xml"_ustr); + + // Graphic 5 is hidden and Graphic 4 is visible, but their order might change in the XML + // Without the fix the hidden attribute wasn't exported + OUString sName1 + = getXPath(pXmlDoc, "/p:sld/p:cSld/p:spTree/p:pic[1]/p:nvPicPr/p:cNvPr", "name"); + OUString sName2 + = getXPath(pXmlDoc, "/p:sld/p:cSld/p:spTree/p:pic[2]/p:nvPicPr/p:cNvPr", "name"); + if (sName1 == "Graphic 5" && sName2 == "Graphic 4") + { + OUString aHidden + = getXPath(pXmlDoc, "/p:sld/p:cSld/p:spTree/p:pic[1]/p:nvPicPr/p:cNvPr", "hidden"); + bool bHidden = aHidden == u"true"_ustr || aHidden == u"1"; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Graphic 3 is supposed to be hidden", true, bHidden); + + assertXPathNoAttribute(pXmlDoc, "/p:sld/p:cSld/p:spTree/p:pic[2]/p:nvPicPr/p:cNvPr", + "hidden"); + } + else if (sName1 == "Graphic 4" && sName2 == "Graphic 5") + { + assertXPathNoAttribute(pXmlDoc, "/p:sld/p:cSld/p:spTree/p:pic[1]/p:nvPicPr/p:cNvPr", + "hidden"); + + OUString aHidden + = getXPath(pXmlDoc, "/p:sld/p:cSld/p:spTree/p:pic[2]/p:nvPicPr/p:cNvPr", "hidden"); + bool bHidden = aHidden == u"true"_ustr || aHidden == u"1"; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Graphic 4 is supposed to be hidden", true, bHidden); + } + else + CPPUNIT_FAIL("Names of graphics is incorrect"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
