sw/qa/extras/odfexport/data/table-in-frame-in-table-in-header-base.odt |binary
 sw/qa/extras/odfexport/odfexport.cxx                                   |   14 
+++
 sw/source/filter/xml/xmltble.cxx                                       |   40 
++++++----
 sw/source/filter/xml/xmltexte.hxx                                      |    4 +
 xmloff/source/text/txtparae.cxx                                        |    3 
 5 files changed, 45 insertions(+), 16 deletions(-)

New commits:
commit c43b50bf027def7054bc15187d61d61d9b132bd7
Author:     Mike Kaganski <[email protected]>
AuthorDate: Tue Sep 13 20:42:22 2022 +0300
Commit:     Xisco Fauli <[email protected]>
CommitDate: Thu Sep 15 10:09:43 2022 +0200

    tdf#150927: properly handle nesting in tables
    
    This re-implements the relevant part of commit
    35021cd56b3b4e38035804087f215c80085564be, to follow the same
    recursion logic that is used in SwXMLExport::ExportTable.
    
    Additionally, it found a place where XML was still emitted
    when collecting autostyles (breaks were exported); fixed.
    
    Change-Id: I3b7eed06e0eca9ad20304b45db4c3e9d72478c9b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139901
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    (cherry picked from commit 58cb4fc7d17ae5b339c5ed6ae139e6ef2433c927)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139843
    Reviewed-by: Xisco Fauli <[email protected]>
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139930

diff --git 
a/sw/qa/extras/odfexport/data/table-in-frame-in-table-in-header-base.odt 
b/sw/qa/extras/odfexport/data/table-in-frame-in-table-in-header-base.odt
new file mode 100644
index 000000000000..44dbf0bdec69
Binary files /dev/null and 
b/sw/qa/extras/odfexport/data/table-in-frame-in-table-in-header-base.odt differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx 
b/sw/qa/extras/odfexport/odfexport.cxx
index a907a3981cce..d57712f593bc 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -3154,6 +3154,20 @@ DECLARE_ODFEXPORT_EXPORTONLY_TEST(tdf135942, 
"nestedTableInFooter.odt")
     assertXPath(pXmlDoc, 
"/office:document-styles/office:automatic-styles/style:style[@style:family='table']",
 2);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, tdf150927)
+{
+    // Similar to tdf135942
+
+    loadAndReload("table-in-frame-in-table-in-header-base.odt");
+    // All table autostyles should be collected, including nested, and must 
not crash.
+
+    CPPUNIT_ASSERT_EQUAL(1, getPages());
+
+    xmlDocUniquePtr pXmlDoc = parseExport("styles.xml");
+
+    assertXPath(pXmlDoc, 
"/office:document-styles/office:automatic-styles/style:style[@style:family='table']",
 2);
+}
+
 DECLARE_ODFEXPORT_TEST(testGutterLeft, "gutter-left.odt")
 {
     CPPUNIT_ASSERT_EQUAL(1, getPages());
diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx
index 3655949f522c..fae84d9be2c8 100644
--- a/sw/source/filter/xml/xmltble.cxx
+++ b/sw/source/filter/xml/xmltble.cxx
@@ -1209,6 +1209,30 @@ void SwXMLTextParagraphExport::exportTableAutoStyles() {
     }
 }
 
+void SwXMLTextParagraphExport::CollectTableLinesAutoStyles(const SwTableLines& 
rLines,
+                                                           SwFrameFormat& 
rFormat, bool _bProgress)
+{
+    // Follow SwXMLExport::ExportTableLines/ExportTableLine/ExportTableBox
+    for (const SwTableLine* pLine : rLines)
+    {
+        for (SwTableBox* pBox : pLine->GetTabBoxes())
+        {
+            if (pBox->getRowSpan() <= 0)
+                continue;
+            if (pBox->GetSttNd())
+            {
+                if (rtl::Reference<SwXCell> xCell = 
SwXCell::CreateXCell(&rFormat, pBox))
+                    exportText(xCell, true /*bAutoStyles*/, _bProgress, true 
/*bExportParagraph*/);
+            }
+            else
+            {
+                // no start node -> merged cells: export subtable in cell
+                CollectTableLinesAutoStyles(pBox->GetTabLines(), rFormat, 
_bProgress);
+            }
+        }
+    }
+}
+
 void SwXMLTextParagraphExport::exportTable(
         const Reference < XTextContent > & rTextContent,
         bool bAutoStyles, bool _bProgress )
@@ -1245,21 +1269,7 @@ void SwXMLTextParagraphExport::exportTable(
                     maTableNodes.push_back(pTableNd);
                     m_TableFormats.emplace(pTableNd, 
::std::make_pair(SwXMLTextParagraphExport::FormatMap(), 
SwXMLTextParagraphExport::FormatMap()));
                     // 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);
-                        }
-                    }
+                    CollectTableLinesAutoStyles(pTable->GetTabLines(), 
*pFormat, _bProgress);
                 }
             }
             else
diff --git a/sw/source/filter/xml/xmltexte.hxx 
b/sw/source/filter/xml/xmltexte.hxx
index 65f26040651c..09ce6c46f4ca 100644
--- a/sw/source/filter/xml/xmltexte.hxx
+++ b/sw/source/filter/xml/xmltexte.hxx
@@ -32,6 +32,7 @@ class SwXMLExport;
 class SvXMLAutoStylePoolP;
 class SwNoTextNode;
 class SwTableNode;
+class SwTableLines;
 namespace com::sun::star::style { class XStyle; }
 
 class SwXMLTextParagraphExport : public XMLTextParagraphExport
@@ -50,6 +51,9 @@ private:
     static SwNoTextNode *GetNoTextNode(
         const css::uno::Reference < css::beans::XPropertySet >& rPropSet );
 
+    void CollectTableLinesAutoStyles(const SwTableLines& rLines, 
SwFrameFormat& rFormat,
+                                     bool bProgress);
+
 protected:
     virtual void _collectTextEmbeddedAutoStyles(
         const css::uno::Reference< css::beans::XPropertySet > & rPropSet ) 
override;
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 732c119cdb58..23c05515fc3c 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -2354,7 +2354,8 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
             }
             else if (sType == gsSoftPageBreak)
             {
-                exportSoftPageBreak();
+                if (!bAutoStyles)
+                    exportSoftPageBreak();
             }
             else {
                 OSL_FAIL("unknown text portion type");

Reply via email to