sw/source/filter/ww8/docxattributeoutput.cxx |   31 +++++++++++++++++----------
 1 file changed, 20 insertions(+), 11 deletions(-)

New commits:
commit 2f9d909a01f90197c3029a446f8aac8135f53f48
Author:     Justin Luth <justin_l...@sil.org>
AuthorDate: Fri May 14 09:52:01 2021 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue May 18 16:06:59 2021 +0200

    tdf#76817 tdf#141966 ooxmlexport: write OutlineRule if not inherited
    
    The previous LO 6.1 version of this patch was fine in practice,
    but in theory the special "Outline" numbering style COULD be
    applied directly to a paragraph - especially during import
    since "Chapter Numbering" is a LO invention, not a DOCX spec.
    
    So, ensure that both the listLevel and the numId match
    what is inherited from the style before deciding that
    writing out the numbering is not needed.
    
    This patch will be needed for tdf#141966.
    
    Change-Id: I9ec4477ed18f84c22a0b5941d0d218186ab6875b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115612
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_l...@sil.org>
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index f0775d63f6b8..09772ab2ccb3 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -8645,20 +8645,29 @@ void DocxAttributeOutput::ParaNumRule_Impl( const 
SwTextNode* pTextNd, sal_Int32
     if ( USHRT_MAX == nNumId )
         return;
 
+    // LibreOffice is not very flexible with "Outline Numbering" (aka 
"Outline" numbering style).
+    // Only ONE numbering rule ("Outline") can be associated with a 
style-assigned-listLevel,
+    // and no other style is able to inherit these numId/nLvl settings - only 
text nodes can.
+    // So listLevel only exists in paragraph properties EXCEPT for up to ten 
styles that have been
+    // assigned to one of these special Chapter Numbering listlevels (by 
default Heading 1-10).
     const sal_Int32 nTableSize = m_rExport.m_pUsedNumTable ? 
m_rExport.m_pUsedNumTable->size() : 0;
     const SwNumRule* pRule = nNumId > 0 && nNumId <= nTableSize ? 
(*m_rExport.m_pUsedNumTable)[nNumId-1] : nullptr;
-    const bool bOutlineRule = pRule && pRule->IsOutlineRule();
-
-    // Do not export outline rules (Chapter Numbering) as paragraph 
properties, only as style properties.
-    if ( !pTextNd || !bOutlineRule )
-    {
-        m_pSerializer->startElementNS(XML_w, XML_numPr);
-        m_pSerializer->singleElementNS(XML_w, XML_ilvl,
-                                       FSNS(XML_w, XML_val), 
OString::number(nLvl));
-        m_pSerializer->singleElementNS(XML_w, XML_numId,
-                                       FSNS(XML_w, XML_val), 
OString::number(nNumId));
-        m_pSerializer->endElementNS( XML_w, XML_numPr );
+    const SwTextFormatColl* pColl = pTextNd ? pTextNd->GetTextColl() : nullptr;
+    // Do not duplicate numbering that is inherited from the (Chapter 
numbering) style
+    // (since on import we duplicate style numbering/listlevel to the 
paragraph).
+    if (pColl && pColl->IsAssignedToListLevelOfOutlineStyle()
+        && nLvl == pColl->GetAssignedOutlineStyleLevel() && pRule && 
pRule->IsOutlineRule())
+    {
+        // By definition of how LO is implemented, assignToListLevel is only 
possible
+        // when the style is also using OutlineRule for numbering. Adjust 
logic if that changes.
+        assert(pRule->GetName() == pColl->GetNumRule(true).GetValue());
+        return;
     }
+
+    m_pSerializer->startElementNS(XML_w, XML_numPr);
+    m_pSerializer->singleElementNS(XML_w, XML_ilvl, FSNS(XML_w, XML_val), 
OString::number(nLvl));
+    m_pSerializer->singleElementNS(XML_w, XML_numId, FSNS(XML_w, XML_val), 
OString::number(nNumId));
+    m_pSerializer->endElementNS(XML_w, XML_numPr);
 }
 
 void DocxAttributeOutput::ParaScriptSpace( const SfxBoolItem& rScriptSpace )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to