sw/qa/extras/ooxmlexport/data/tdf144668.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx  |    9 +++++++++
 sw/source/filter/ww8/wrtw8num.cxx           |   24 +++---------------------
 sw/source/filter/ww8/ww8par.hxx             |    2 +-
 sw/source/filter/ww8/ww8par2.cxx            |   20 ++++++++++++--------
 5 files changed, 25 insertions(+), 30 deletions(-)

New commits:
commit e0b41fcb56e51f20684da4ba44d7ed6e0e1a3234
Author:     Vasily Melenchuk <vasily.melenc...@cib.de>
AuthorDate: Thu Oct 28 13:36:50 2021 +0300
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Nov 5 10:54:47 2021 +0100

    tdf#144668: docx export: simpler way to create lvlText in numberings
    
    Oldr approach with populating ListLabelString with some predefined
    values and than replacing them by placeholders is not so good. It
    can lead to collisions if we use numbers in format string.
    
    Anow with support of list strings in core we do not need this: it
    is enougth to replace LO placeholders %1%, %2%, ... by MS binary
    placeholders \0, \1, ...
    
    Additionally added support for list level initialization in DOC
    import: that case was still setting just prefix/suffix leaving
    list level uninitialized.
    
    Change-Id: Ia85551f46b4e229dea93c663459ec1a8715c8a23
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124326
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf144668.odt 
b/sw/qa/extras/ooxmlexport/data/tdf144668.odt
new file mode 100644
index 000000000000..7504adce400d
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf144668.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 77645a84aefb..36555f71a671 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -115,6 +115,15 @@ DECLARE_OOXMLEXPORT_TEST(testTdf142407, "tdf142407.docx")
     CPPUNIT_ASSERT_EQUAL( sal_Int16(36), nGridLines);   // was 23, left large 
space before text.
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf144668, "tdf144668.odt")
+{
+    uno::Reference<beans::XPropertySet> xPara1(getParagraph(1, u"level1"), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("[0001]"), getProperty<OUString>(xPara1, 
"ListLabelString"));
+
+    uno::Reference<beans::XPropertySet> xPara2(getParagraph(2, u"level2"), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("[001]"), getProperty<OUString>(xPara2, 
"ListLabelString"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/wrtw8num.cxx 
b/sw/source/filter/ww8/wrtw8num.cxx
index ae67e973c98a..bb61901d24ae 100644
--- a/sw/source/filter/ww8/wrtw8num.cxx
+++ b/sw/source/filter/ww8/wrtw8num.cxx
@@ -412,13 +412,6 @@ void MSWordExportBase::AbstractNumberingDefinitions()
 void MSWordExportBase::NumberingLevel(
         SwNumRule const& rRule, sal_uInt8 const nLvl)
 {
-    // prepare the NodeNum to generate the NumString
-    static const SwNumberTree::tNumberVector aNumVector = [] {
-        SwNumberTree::tNumberVector vec(WW8ListManager::nMaxLevel);
-        std::iota(vec.begin(), vec.end(), 0);
-        return vec;
-    }();
-
     // write the static data of the SwNumFormat of this level
     sal_uInt8 aNumLvlPos[WW8ListManager::nMaxLevel] = { 0,0,0,0,0,0,0,0,0 };
 
@@ -480,35 +473,24 @@ void MSWordExportBase::NumberingLevel(
     else
     {
         // Create level string
-        // For docx it is not the best way: we can just take it from 
rRule.Get(nLvl).GetListFormat()
-        // But for compatibility with doc we follow same routine
         if (SVX_NUM_NUMBER_NONE != rFormat.GetNumberingType())
         {
             sal_uInt8* pLvlPos = aNumLvlPos;
-            // the numbering string has to be restrict
-            // to the level currently working on.
-            sNumStr = rRule.MakeNumString(aNumVector, true, true, nLvl);
+            sNumStr = rFormat.GetListFormat();
 
             // now search the nums in the string
             for (sal_uInt8 i = 0; i <= nLvl; ++i)
             {
-                OUString sSrch(OUString::number(i));
+                OUString sSrch("%" + OUString::number(i+1) + "%");
                 sal_Int32 nFnd = sNumStr.indexOf(sSrch);
                 if (-1 != nFnd)
                 {
                     *pLvlPos = static_cast<sal_uInt8>(nFnd + 1);
                     ++pLvlPos;
-                    sNumStr = sNumStr.replaceAt(nFnd, 1, 
OUString(static_cast<char>(i)));
+                    sNumStr = sNumStr.replaceAt(nFnd, sSrch.getLength(), 
OUString(static_cast<char>(i)));
                 }
             }
         }
-
-        if (!rRule.Get(nLvl).HasListFormat())
-        {
-            if (!rFormat.GetPrefix().isEmpty())
-                sNumStr = rFormat.GetPrefix() + sNumStr;
-            sNumStr += rFormat.GetSuffix();
-        }
     }
 
     if (SVX_NUM_CHAR_SPECIAL == rFormat.GetNumberingType() ||
diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx
index 3d640b8485de..14a1ea1a35b7 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -1572,7 +1572,7 @@ private:
 // rglst, hpllfo and hsttbListNames
 // the corresponding structures are: LSTF, LVLF, LFO LFOLVL
 
-    void SetAnlvStrings(SwNumFormat &rNum, WW8_ANLV const &rAV, const 
sal_uInt8* pText,
+    void SetAnlvStrings(SwNumFormat &rNum, int nLevel, WW8_ANLV const &rAV, 
const sal_uInt8* pText,
         size_t nStart, size_t nElements, bool bOutline);
     void SetAnld(SwNumRule* pNumR, WW8_ANLD const * pAD, sal_uInt8 nSwLevel, 
bool bOutLine);
     void SetNumOlst( SwNumRule* pNumR, WW8_OLST* pO, sal_uInt8 nSwLevel );
diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx
index 1391cbb47d15..7cf96ade0bc2 100644
--- a/sw/source/filter/ww8/ww8par2.cxx
+++ b/sw/source/filter/ww8/ww8par2.cxx
@@ -620,7 +620,7 @@ static void SetBaseAnlv(SwNumFormat &rNum, WW8_ANLV const 
&rAV, sal_uInt8 nSwLev
     }
 }
 
-void SwWW8ImplReader::SetAnlvStrings(SwNumFormat &rNum, WW8_ANLV const &rAV,
+void SwWW8ImplReader::SetAnlvStrings(SwNumFormat &rNum, int nLevel, WW8_ANLV 
const &rAV,
     const sal_uInt8* pText, size_t nStart, size_t nElements, bool bOutline)
 {
     if (nStart > nElements)
@@ -718,16 +718,20 @@ void SwWW8ImplReader::SetAnlvStrings(SwNumFormat &rNum, 
WW8_ANLV const &rAV,
     if( !bInsert )
         return;
 
+    OUString sPrefix;
+    OUString sSuffix;
     if (rAV.cbTextBefore)
     {
-        OUString sP( sText.copy( 0, rAV.cbTextBefore ).makeStringAndClear() );
-        rNum.SetPrefix( sP );
+        sPrefix = sText.copy( 0, rAV.cbTextBefore ).makeStringAndClear();
     }
     if( rAV.cbTextAfter )
     {
-        OUString sP( rNum.GetSuffix() );
-        sP += sText.copy( rAV.cbTextBefore, 
rAV.cbTextAfter).makeStringAndClear();
-        rNum.SetSuffix( sP );
+        sSuffix = rNum.GetSuffix();
+        sSuffix += sText.copy( rAV.cbTextBefore, 
rAV.cbTextAfter).makeStringAndClear();
+    }
+    if (rAV.cbTextBefore || rAV.cbTextAfter)
+    {
+        rNum.SetListFormat(sPrefix, sSuffix, nLevel);
     }
 // The characters before and after multiple digits do not apply because
 // those are handled differently by the writer and the result is in most
@@ -746,7 +750,7 @@ void SwWW8ImplReader::SetAnld(SwNumRule* pNumR, WW8_ANLD 
const * pAD, sal_uInt8
         m_bCurrentAND_fNumberAcross = 0 != pAD->fNumberAcross;
         WW8_ANLV const &rAV = pAD->eAnlv;
         SetBaseAnlv(aNF, rAV, nSwLevel);                    // set the base 
format
-        SetAnlvStrings(aNF, rAV, pAD->rgchAnld, 0, 
SAL_N_ELEMENTS(pAD->rgchAnld), bOutLine); // set the rest
+        SetAnlvStrings(aNF, nSwLevel, rAV, pAD->rgchAnld, 0, 
SAL_N_ELEMENTS(pAD->rgchAnld), bOutLine); // set the rest
     }
     pNumR->Set(nSwLevel, aNF);
 }
@@ -884,7 +888,7 @@ void SwWW8ImplReader::SetNumOlst(SwNumRule* pNumR, 
WW8_OLST* pO, sal_uInt8 nSwLe
 
     if (!m_bVer67)
         nTextOfs *= 2;
-    SetAnlvStrings(aNF, rAV, pO->rgch, nTextOfs, SAL_N_ELEMENTS(pO->rgch), 
true); // and apply
+    SetAnlvStrings(aNF, nSwLevel, rAV, pO->rgch, nTextOfs, 
SAL_N_ELEMENTS(pO->rgch), true); // and apply
     pNumR->Set(nSwLevel, aNF);
 }
 

Reply via email to