diff options
author | Vasily Melenchuk <vasily.melenchuk@cib.de> | 2020-04-13 11:06:29 +0300 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2020-04-27 22:36:12 +0200 |
commit | 7459b9ecb54a298f02d19089620149718f8d8d48 (patch) | |
tree | 8e26f751e26b4e4f7ca53d36d6c94603d096650c /sw/source/core | |
parent | 4ba179eb9208185406207522e39626327c7d74c3 (diff) |
tdf#116883: sw: support for lists level format string
Multilevel lists are more flexible in case of DOCX. There is
supported custom format for any level in DOCX unlike in LO
and ODT where we are limited only with prefix and suffix
for hardcoded list levels separated by dot. At the same time
DOCX can have lists not only "1.2.3.4", but "1/2/3/4" or even
"1!2>3)4" and such format can vary on each list level.
Here is basic implementation for list format as a core feature
for all documents and old way (prefix-suffix + ".") is left
as fallback.
Practically its usage is currently implemented only in DOCX
import/export.
Some RTF/OOXML unittests were redesigned: since we are not creating
prefix/suffix for these formats conditions should be checked in
a different way.
Change-Id: I1ec58bcc5874d4fa19aee6a1f42bf1671d853b14
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92106
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'sw/source/core')
-rw-r--r-- | sw/source/core/doc/number.cxx | 116 | ||||
-rw-r--r-- | sw/source/core/unocore/unosett.cxx | 15 |
2 files changed, 87 insertions, 44 deletions
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx index cce3aefe0714..d26c48fe579d 100644 --- a/sw/source/core/doc/number.cxx +++ b/sw/source/core/doc/number.cxx @@ -642,64 +642,94 @@ OUString SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVecto const SwNumFormat& rMyNFormat = Get( static_cast<sal_uInt16>(nLevel) ); { - SwNumberTree::tNumberVector::size_type i = nLevel; + css::lang::Locale aLocale( LanguageTag::convertToLocale(nLang)); - if( !IsContinusNum() && - // - do not include upper levels, if level isn't numbered. - rMyNFormat.GetNumberingType() != SVX_NUM_NUMBER_NONE && - rMyNFormat.GetIncludeUpperLevels() ) // Just the own level? + OUString sLevelFormat = rMyNFormat.GetListFormat(); + if (!sLevelFormat.isEmpty()) { - sal_uInt8 n = rMyNFormat.GetIncludeUpperLevels(); - if( 1 < n ) + // In this case we are ignoring GetIncludeUpperLevels: we put all + // level nubers requested by level format + for (SwNumberTree::tNumberVector::size_type i=0; i <= nLevel; ++i) { - if( i+1 >= n ) - i -= n - 1; + OUString sReplacement; + if (rNumVector[i]) + { + if (bOnlyArabic) + sReplacement = OUString::number(rNumVector[i]); + else + sReplacement = Get(i).GetNumStr(rNumVector[i], aLocale); + } else - i = 0; + sReplacement = "0"; // all 0 level are a 0 + + OUString sFind("%" + OUString::number(i + 1)); + sal_Int32 nPosition = sLevelFormat.indexOf(sFind); + if (nPosition >= 0) + sLevelFormat = sLevelFormat.replaceAt(nPosition, sFind.getLength(), sReplacement); } + aStr = sLevelFormat; } - - css::lang::Locale aLocale( LanguageTag::convertToLocale(nLang)); - - for( ; i <= nLevel; ++i ) + else { - const SwNumFormat& rNFormat = Get( i ); - if( SVX_NUM_NUMBER_NONE == rNFormat.GetNumberingType() ) + // Fallback case: level format is not defined + // So use old way with levels joining by dot "." + SwNumberTree::tNumberVector::size_type i = nLevel; + + if (!IsContinusNum() && + // - do not include upper levels, if level isn't numbered. + rMyNFormat.GetNumberingType() != SVX_NUM_NUMBER_NONE && + rMyNFormat.GetIncludeUpperLevels()) // Just the own level? { - // Should 1.1.1 --> 2. NoNum --> 1..1 or 1.1 ?? - // if( i != rNum.nMyLevel ) - // aStr += "."; - continue; + sal_uInt8 n = rMyNFormat.GetIncludeUpperLevels(); + if (1 < n) + { + if (i + 1 >= n) + i -= n - 1; + else + i = 0; + } } - if( rNumVector[ i ] ) + for (; i <= nLevel; ++i) { - if( bOnlyArabic ) - aStr.append(OUString::number( rNumVector[ i ] )); + const SwNumFormat& rNFormat = Get(i); + if (SVX_NUM_NUMBER_NONE == rNFormat.GetNumberingType()) + { + // Should 1.1.1 --> 2. NoNum --> 1..1 or 1.1 ?? + // if( i != rNum.nMyLevel ) + // aStr += "."; + continue; + } + + if (rNumVector[i]) + { + if (bOnlyArabic) + aStr.append(OUString::number(rNumVector[i])); + else + aStr.append(rNFormat.GetNumStr(rNumVector[i], aLocale)); + } else - aStr.append(rNFormat.GetNumStr( rNumVector[ i ], aLocale )); + aStr.append("0"); // all 0 level are a 0 + if (i != nLevel && !aStr.isEmpty()) + aStr.append("."); } - else - aStr.append("0"); // all 0 level are a 0 - if( i != nLevel && !aStr.isEmpty() ) - aStr.append("."); - } - // The type doesn't have any number, so don't append - // the post-/prefix string - if( bInclStrings && !bOnlyArabic && - SVX_NUM_CHAR_SPECIAL != rMyNFormat.GetNumberingType() && - SVX_NUM_BITMAP != rMyNFormat.GetNumberingType() ) - { - const OUString& sPrefix = rMyNFormat.GetPrefix(); - const OUString& sSuffix = rMyNFormat.GetSuffix(); - - aStr.insert(0, sPrefix); - aStr.append(sSuffix); - if ( pExtremities ) + // The type doesn't have any number, so don't append + // the post-/prefix string + if (bInclStrings && !bOnlyArabic && + SVX_NUM_CHAR_SPECIAL != rMyNFormat.GetNumberingType() && + SVX_NUM_BITMAP != rMyNFormat.GetNumberingType()) { - pExtremities->nPrefixChars = sPrefix.getLength(); - pExtremities->nSuffixChars = sSuffix.getLength(); + const OUString& sPrefix = rMyNFormat.GetPrefix(); + const OUString& sSuffix = rMyNFormat.GetSuffix(); + + aStr.insert(0, sPrefix); + aStr.append(sSuffix); + if (pExtremities) + { + pExtremities->nPrefixChars = sPrefix.getLength(); + pExtremities->nSuffixChars = sSuffix.getLength(); + } } } } diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx index 612a938cc621..2257a49faf1e 100644 --- a/sw/source/core/unocore/unosett.cxx +++ b/sw/source/core/unocore/unosett.cxx @@ -1334,6 +1334,10 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFormat aUString = rFormat.GetSuffix(); aPropertyValues.push_back(comphelper::makePropertyValue("Suffix", aUString)); + //listformat + aUString = rFormat.GetListFormat(); + aPropertyValues.push_back(comphelper::makePropertyValue("ListFormat", aUString)); + //char style name aUString.clear(); @@ -1573,7 +1577,9 @@ void SwXNumberingRules::SetPropertiesToNumFormat( // these two are accepted but ignored for some reason UNO_NAME_BULLET_REL_SIZE, // 25 UNO_NAME_BULLET_COLOR, // 26 - UNO_NAME_GRAPHIC_URL // 27 + UNO_NAME_GRAPHIC_URL, // 27 + + UNO_NAME_LIST_FORMAT // 28 }; enum { @@ -2027,6 +2033,13 @@ void SwXNumberingRules::SetPropertiesToNumFormat( bWrongArg = true; } break; + case 28: //"ListFormat", + { + OUString uTmp; + pProp->Value >>= uTmp; + aFormat.SetListFormat(uTmp); + } + break; } } if(!bWrongArg && (pSetBrush || pSetSize || pSetVOrient)) |