diff options
author | Vasily Melenchuk <vasily.melenchuk@cib.de> | 2021-10-28 13:36:50 +0300 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2021-11-05 10:54:47 +0100 |
commit | e0b41fcb56e51f20684da4ba44d7ed6e0e1a3234 (patch) | |
tree | 727cbfd490620a23f4bbbda0981eeed5311fe939 /sw/source/filter | |
parent | 4a7022c199addb1fbc7445708c0f4801fbf1e47f (diff) |
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.stahl@allotropia.de>
Diffstat (limited to 'sw/source/filter')
-rw-r--r-- | sw/source/filter/ww8/wrtw8num.cxx | 24 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par.hxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par2.cxx | 20 |
3 files changed, 16 insertions, 30 deletions
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); } |