sw/qa/extras/ooxmlexport/data/lost-footer-style.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport5.cxx            |   15 ++++++++++++
 sw/source/filter/ww8/wrtw8sty.cxx                    |   22 ++++++++++++-------
 3 files changed, 30 insertions(+), 7 deletions(-)

New commits:
commit 270b5f977934f87ddfcb2d471405cf19c9cecb17
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Aug 30 12:18:32 2024 +0200
Commit:     Adolfo Jayme Barrientos <fit...@ubuntu.com>
CommitDate: Mon Sep 2 02:56:54 2024 +0200

    tdf#162707 DOCX export: fix lost paragraph styles with many numberings
    
    Open the bugdoc, style of the only para of the only footer is Footer,
    save as DOCX, reopen, style changes from Footer to Default.
    
    What seems to happen is that the document has too many numberings, and
    each numbering has 9 levels, so if we have a char style for each level,
    that easily runs into the MSWORD_MAX_STYLES_LIMIT limit, after which we
    silently start dropping styles during export.
    
    Fix the problem by tweaking the fix done in commit
    7376a47680b65cbdfd747a736f288e06f51f7f2d (tdf#92335 DOCX: fix
    multiplying of "ListLabel" styles, 2019-05-28): if we don't just avoid
    writing those ListLabel styles (where the real info is written as a
    non-style in numbering.xml, so no formatting is list) but we filter them
    out earlier, then MSWordStyles::BuildStylesTable() will count styles
    correctly and we'll still have space for the lost Footer style.
    
    Regression from commit f9c8d97d82a85b897520a2fe897352ee5ad879d9
    (tdf#95213 DOCX import: don't reuse list label styles, 2016-01-07).
    
    Change-Id: I7a6b0b7b5a7b3c813a844c5fd185cf2f419e1a5c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172647
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 32b667acd665ce9e66ec6db952e1effb7b4c1031)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172671
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/sw/qa/extras/ooxmlexport/data/lost-footer-style.docx 
b/sw/qa/extras/ooxmlexport/data/lost-footer-style.docx
new file mode 100644
index 000000000000..ed9db77a7121
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/lost-footer-style.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index fbd5ae53647b..6f814fa9a2a4 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -700,6 +700,21 @@ CPPUNIT_TEST_FIXTURE(Test, testfdo79968_sldx)
         u"PowerPoint.Slide.12"_ustr);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testLostFooterStyle)
+{
+    // Given a document with many numberings and a Footer para style:
+    loadAndSave("lost-footer-style.docx");
+
+    // When saving that to DOCX and checking the Footer style:
+    xmlDocUniquePtr pXmlDoc = parseExport(u"word/styles.xml"_ustr);
+    // Without the accompanying fix in place, this test would have failed, the 
Footer style was
+    // lost on export due to the many ListLabel char styles.
+    OUString aType = getXPath(pXmlDoc, 
"/w:styles/w:style[@w:styleId='Footer']"_ostr, "type"_ostr);
+
+    // Then make sure we have a Footer para style:
+    CPPUNIT_ASSERT_EQUAL(u"paragraph"_ustr, aType);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx 
b/sw/source/filter/ww8/wrtw8sty.cxx
index 6cbc2702e02d..39ab72c1fbc3 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -320,7 +320,22 @@ void MSWordStyles::BuildStylesTable()
     const SwCharFormats& rArr = *m_rExport.m_rDoc.GetCharFormats();       // 
first CharFormat
     // the default character style ( 0 ) will not be outputted !
     for (size_t n = 1; n < rArr.size() && m_aStyles.size() < 
MSWORD_MAX_STYLES_LIMIT; ++n)
+    {
+        if (m_rExport.GetExportFormat() == MSWordExportBase::DOCX
+            && rArr[n]->GetName().startsWith("ListLabel"))
+        {
+            // tdf#92335 don't export redundant DOCX import style "ListLabel"
+            continue;
+        }
+
         m_aStyles.emplace_back(rArr[n]);
+    }
+
+    if (m_aStyles.size() == MSWORD_MAX_STYLES_LIMIT)
+    {
+        SAL_WARN("sw.ww8", "MSWordStyles::BuildStylesTable: too many styles, 
have "
+                               << rArr.size() << " char styles");
+    }
 
     const SwTextFormatColls& rArr2 = *m_rExport.m_rDoc.GetTextFormatColls();   
// then TextFormatColls
     // the default paragraph style ( 0 ) will not be outputted !
@@ -700,13 +715,6 @@ void MSWordStyles::OutputStyle(sal_uInt16 nSlot)
 
         GetStyleData(entry.format, bFormatColl, nBase, nWwNext, nWwLink);
 
-        if (!bFormatColl && m_rExport.GetExportFormat() == 
MSWordExportBase::DOCX &&
-                        entry.style_id.startsWith("ListLabel"))
-        {
-            // tdf#92335 don't export redundant DOCX import style "ListLabel"
-            return;
-        }
-
         m_rExport.AttrOutput().StartStyle(entry.ww_name, (bFormatColl ? 
STYLE_TYPE_PARA : STYLE_TYPE_CHAR),
                 nBase, nWwNext, nWwLink, m_aStyles[nSlot].ww_id, nSlot,
                 entry.format->IsAutoUpdateOnDirectFormat() );

Reply via email to