include/xmloff/txtparae.hxx | 4 + sw/qa/extras/odfexport/data/nestedTableInFooter.odt |binary sw/qa/extras/odfexport/data/tdf124470TableAndEmbeddedUsedFonts.odt |binary sw/qa/extras/odfexport/odfexport.cxx | 29 +++++++++ sw/source/filter/xml/xmltble.cxx | 30 +++++++++- sw/source/filter/xml/xmltexte.hxx | 6 ++ xmloff/source/text/txtparae.cxx | 6 ++ 7 files changed, 73 insertions(+), 2 deletions(-)
New commits: commit ef27927b9d953aca6043f09074df956401b32a43 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri Aug 21 00:15:29 2020 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Tue Sep 15 11:50:26 2020 +0200 tdf#135942: avoid collecting autostyles during writing them This modifies the container over which iteration is performed. Additionally, make sure that all nested table autostyles are collected on the first phase. Change-Id: I74c0bb1aaacad095226c21e6bf51cc8668133bb3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101096 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> (cherry picked from commit f0286ad82465152b29bba01ab2edeb97291397fa) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101069 Reviewed-by: Caolán McNamara <caol...@redhat.com> (cherry picked from commit 0273675e7dde577077ccca17571846a0942f2630) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102700 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/include/xmloff/txtparae.hxx b/include/xmloff/txtparae.hxx index 7ded21114fd6..c01c03eea4d3 100644 --- a/include/xmloff/txtparae.hxx +++ b/include/xmloff/txtparae.hxx @@ -365,6 +365,8 @@ protected: const css::uno::Reference< css::beans::XPropertySet> & i_xPortion, bool i_bAutoStyles, bool i_isProgress, bool & rPrevCharIsSpace); + bool isAutoStylesCollected() const { return mbCollected; } + virtual void exportTableAutoStyles(); public: diff --git a/sw/qa/extras/odfexport/data/nestedTableInFooter.odt b/sw/qa/extras/odfexport/data/nestedTableInFooter.odt new file mode 100644 index 000000000000..0356f04ee14e Binary files /dev/null and b/sw/qa/extras/odfexport/data/nestedTableInFooter.odt differ diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index c40824a1e823..5ef2d7cd0b38 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -2414,5 +2414,17 @@ DECLARE_ODFEXPORT_TEST(tdf124470, "tdf124470TableAndEmbeddedUsedFonts.odt") } } +DECLARE_ODFEXPORT_TEST(tdf135942, "nestedTableInFooter.odt") +{ + // All table autostyles should be collected, including nested, and must not crash. + + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + if (xmlDocPtr pXmlDoc = parseExport("styles.xml")) + { + assertXPath(pXmlDoc, "/office:document-styles/office:automatic-styles/style:style[@style:family='table']", 2); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx index 80d786d8d884..6a4fa1c9902b 100644 --- a/sw/source/filter/xml/xmltble.cxx +++ b/sw/source/filter/xml/xmltble.cxx @@ -1183,8 +1183,27 @@ void SwXMLTextParagraphExport::exportTable( // During the flat XML export (used e.g. by .sdw-export) // ALL flags are set at the same time. const bool bExportStyles = bool( GetExport().getExportFlags() & SvXMLExportFlags::STYLES ); - if ( bExportStyles || !pFormat->GetDoc()->IsInHeaderFooter( aIdx ) ) + if (!isAutoStylesCollected() + && (bExportStyles || !pFormat->GetDoc()->IsInHeaderFooter(aIdx))) + { maTableNodes.push_back(pTableNd); + // Collect all tables inside cells of this table, too + const auto aCellNames = pXTable->getCellNames(); + for (const OUString& rCellName : aCellNames) + { + css::uno::Reference<css::container::XEnumerationAccess> xCell( + pXTable->getCellByName(rCellName), css::uno::UNO_QUERY); + if (!xCell) + continue; + auto xEnumeration = xCell->createEnumeration(); + while (xEnumeration->hasMoreElements()) + { + if (css::uno::Reference<css::text::XTextTable> xInnerTable{ + xEnumeration->nextElement(), css::uno::UNO_QUERY }) + exportTable(xInnerTable, bAutoStyles, _bProgress); + } + } + } } else { diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index b830da30579b..24b5a8f2cbae 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -3675,6 +3675,8 @@ void XMLTextParagraphExport::exportTableAutoStyles() {} void XMLTextParagraphExport::exportTextAutoStyles() { + // tdf#135942: do not collect styles during their export: this may modify iterated containers + mbCollected = true; exportTableAutoStyles(); GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_PARAGRAPH ); commit f483a26be68fd9f13d176ac5c17ffec25f0634f6 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Aug 5 11:16:32 2020 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Tue Sep 15 11:50:12 2020 +0200 tdf#124470: Split export of table autostyles out from collection phase This allows to call collectAutoStyles where required (e.g. when enumerating used fonts), without side effect of writing table styles XML inside the call, out of place. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100153 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> (cherry picked from commit 35021cd56b3b4e38035804087f215c80085564be) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100221 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100274 Change-Id: Ida05e373eb8502590c43e2b0e85c3b0c1107c551 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102699 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/include/xmloff/txtparae.hxx b/include/xmloff/txtparae.hxx index b85f78f1dbfe..7ded21114fd6 100644 --- a/include/xmloff/txtparae.hxx +++ b/include/xmloff/txtparae.hxx @@ -365,6 +365,8 @@ protected: const css::uno::Reference< css::beans::XPropertySet> & i_xPortion, bool i_bAutoStyles, bool i_isProgress, bool & rPrevCharIsSpace); + virtual void exportTableAutoStyles(); + public: XMLTextParagraphExport( diff --git a/sw/qa/extras/odfexport/data/tdf124470TableAndEmbeddedUsedFonts.odt b/sw/qa/extras/odfexport/data/tdf124470TableAndEmbeddedUsedFonts.odt new file mode 100644 index 000000000000..21969e9e5485 Binary files /dev/null and b/sw/qa/extras/odfexport/data/tdf124470TableAndEmbeddedUsedFonts.odt differ diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index de10b5946584..c40824a1e823 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -2397,5 +2397,22 @@ DECLARE_ODFEXPORT_TEST(testArabicZero5Numbering, "arabic-zero5-numbering.odt") aMap["NumberingType"].get<sal_uInt16>()); } +DECLARE_ODFEXPORT_TEST(tdf124470, "tdf124470TableAndEmbeddedUsedFonts.odt") +{ + // Table styles were exported out of place, inside font-face-decls. + // Without the fix in place, this will fail already in ODF validation: + // "content.xml[2,2150]: Error: tag name "style:style" is not allowed. Possible tag names are: <font-face>" + + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + if (xmlDocPtr pXmlDoc = parseExport("content.xml")) + { + assertXPath(pXmlDoc, "/office:document-content/office:font-face-decls/style:style", 0); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:family='table']", 1); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:family='table-column']", 2); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:family='paragraph']", 1); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx index bef72a6f5357..80d786d8d884 100644 --- a/sw/source/filter/xml/xmltble.cxx +++ b/sw/source/filter/xml/xmltble.cxx @@ -1140,6 +1140,13 @@ void SwXMLExport::ExportTable( const SwTableNode& rTableNd ) } } +void SwXMLTextParagraphExport::exportTableAutoStyles() { + for (const auto* pTableNode : maTableNodes) + { + static_cast<SwXMLExport&>(GetExport()).ExportTableAutoStyles(*pTableNode); + } +} + void SwXMLTextParagraphExport::exportTable( const Reference < XTextContent > & rTextContent, bool bAutoStyles, bool _bProgress ) @@ -1177,7 +1184,7 @@ void SwXMLTextParagraphExport::exportTable( // ALL flags are set at the same time. const bool bExportStyles = bool( GetExport().getExportFlags() & SvXMLExportFlags::STYLES ); if ( bExportStyles || !pFormat->GetDoc()->IsInHeaderFooter( aIdx ) ) - static_cast<SwXMLExport&>(GetExport()).ExportTableAutoStyles( *pTableNd ); + maTableNodes.push_back(pTableNd); } else { diff --git a/sw/source/filter/xml/xmltexte.hxx b/sw/source/filter/xml/xmltexte.hxx index 8da021506c0d..4432e4ce0166 100644 --- a/sw/source/filter/xml/xmltexte.hxx +++ b/sw/source/filter/xml/xmltexte.hxx @@ -28,6 +28,7 @@ class SwXMLExport; class SvXMLAutoStylePoolP; class SwNoTextNode; +class SwTableNode; namespace com { namespace sun { namespace star { namespace style { class XStyle; } } } } @@ -38,6 +39,9 @@ class SwXMLTextParagraphExport : public XMLTextParagraphExport const SvGlobalName aPluginClassId; const SvGlobalName aIFrameClassId; + // Collected autostyles for use in exportTextAutoStyles + std::vector<const SwTableNode*> maTableNodes; + static SwNoTextNode *GetNoTextNode( const css::uno::Reference < css::beans::XPropertySet >& rPropSet ); @@ -52,6 +56,8 @@ protected: const css::uno::Reference< css::text::XTextContent > & rTextContent, bool bAutoStyles, bool bProgress ) override; + virtual void exportTableAutoStyles() override; + public: SwXMLTextParagraphExport( SwXMLExport& rExp, diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index 0238e918535d..b830da30579b 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -3671,8 +3671,12 @@ void XMLTextParagraphExport::recordTrackedChangesNoXText() pRedlineExport->SetCurrentXText(); } +void XMLTextParagraphExport::exportTableAutoStyles() {} + void XMLTextParagraphExport::exportTextAutoStyles() { + exportTableAutoStyles(); + GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_PARAGRAPH ); GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_TEXT ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits