diff options
author | Vasily Melenchuk <vasily.melenchuk@cib.de> | 2021-06-14 14:27:56 +0300 |
---|---|---|
committer | Thorsten Behrens <thorsten.behrens@allotropia.de> | 2021-06-29 19:02:20 +0200 |
commit | 9987b518fca1476bd0ce8c86bcf6ac7c81f7b580 (patch) | |
tree | 3aa1af29be70b24bc96951a310f3379a621a54b1 /xmloff | |
parent | d8dcd706c74b4a0fa420946c707137b097b3c7fe (diff) |
new ODF numbered list parameter loext:num-list-format
Instead of style:num-prefix and style:num-suffix new list format
is much more flexible for storing list multilevel numberings.
Now it is possible to have not just prefix/suffix but any random
separators between levels, arbitrary levels order, etc.
Internal LO format for list format is changed: instead of placeholders
like %1, %2, etc we right now use %1%, %2%... Reason: for ODT documents,
having more than 9 levels there is ambiguity in "%10": it is "%1"
followed by "0" suffix, or "%10"?
Aux changes:
* removed zero width space hack: since format string is always defined
this hack is interfering with standard list numbers printing
(see changes in ooxmlexport14.cxx, ww8export3.cxx tests)
* changed cross-references values to lists: they are now including full
list label string: previously this was bit self-contradictory (see
changes in odfexport.cxx and check_cross_references.py tests)
Conflicts:
sw/qa/extras/odfexport/odfexport.cxx
Change-Id: I9696cc4846375c5f6222539aeaadbca5ae58ce27
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117156
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118040
Reviewed-by: Vasily Melenchuk <vasily.melenchuk@cib.de>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 1 | ||||
-rw-r--r-- | xmloff/source/style/xmlnume.cxx | 24 | ||||
-rw-r--r-- | xmloff/source/style/xmlnumi.cxx | 27 | ||||
-rw-r--r-- | xmloff/source/token/tokens.txt | 1 |
4 files changed, 39 insertions, 14 deletions
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 4334f52a74ac..27815a3d1ebf 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -1376,6 +1376,7 @@ namespace xmloff::token { TOKEN( "null-year", XML_NULL_YEAR ), TOKEN( "num-format", XML_NUM_FORMAT ), TOKEN( "num-letter-sync", XML_NUM_LETTER_SYNC ), + TOKEN( "num-list-format", XML_NUM_LIST_FORMAT ), TOKEN( "num-prefix", XML_NUM_PREFIX ), TOKEN( "num-suffix", XML_NUM_SUFFIX ), TOKEN( "numalign", XML_NUMALIGN ), diff --git a/xmloff/source/style/xmlnume.cxx b/xmloff/source/style/xmlnume.cxx index 132e3f701a2e..45e398b5c889 100644 --- a/xmloff/source/style/xmlnume.cxx +++ b/xmloff/source/style/xmlnume.cxx @@ -82,7 +82,7 @@ void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel, sal_Int16 eType = NumberingType::CHAR_SPECIAL; sal_Int16 eAdjust = HoriOrientation::LEFT; - OUString sPrefix, sSuffix; + OUString sPrefix, sSuffix, sListFormat; OUString sTextStyleName; bool bHasColor = false; sal_Int32 nColor = 0; @@ -123,20 +123,7 @@ void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel, } else if (rProp.Name == "ListFormat") { - OUString sListFormat; rProp.Value >>= sListFormat; - - // Since we have no support for entire format string it should be converted - // to prefix and suffix. Of course, it is not so flexible as format string, - // but it is the only option - sal_Int32 nFirstReplacement = sListFormat.indexOf('%'); - sal_Int32 nLastReplacement = sListFormat.lastIndexOf('%') + 1; - if (nFirstReplacement > 0) - // Everything before first '%' will be prefix - sPrefix = sListFormat.copy(0, nFirstReplacement); - if (nLastReplacement >= 0 && nLastReplacement < sListFormat.getLength() -1 ) - // Everything beyond last '%' (+1 for follow up id) is a suffix - sSuffix = sListFormat.copy(nLastReplacement + 1); } else if (rProp.Name == "BulletChar") { @@ -269,6 +256,15 @@ void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel, GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, GetExport().EncodeStyleName( sTextStyleName ) ); } + if (!sListFormat.isEmpty()) + { + if (GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) + { + // Write only in extended mode: in ODF 1.3 we write only prefix/suffix, + // no list format yet available. Praying we did not lost some formatting. + GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_NUM_LIST_FORMAT, sListFormat); + } + } if (!sPrefix.isEmpty()) { GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_PREFIX, diff --git a/xmloff/source/style/xmlnumi.cxx b/xmloff/source/style/xmlnumi.cxx index 3f8040bbad6c..335bbfac928f 100644 --- a/xmloff/source/style/xmlnumi.cxx +++ b/xmloff/source/style/xmlnumi.cxx @@ -64,6 +64,7 @@ #include <xmloff/maptype.hxx> #include <xmloff/xmlnumi.hxx> +#include <optional> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -114,6 +115,8 @@ class SvxXMLListLevelStyleContext_Impl : public SvXMLImportContext OUString sPrefix; OUString sSuffix; + std::optional<OUString> sListFormat; // It is optional to distinguish empty format string + // from not existing format string in old docs OUString sTextStyleName; OUString sNumFormat; OUString sNumLetterSync; @@ -298,6 +301,10 @@ SvxXMLListLevelStyleContext_Impl::SvxXMLListLevelStyleContext_Impl( case XML_ELEMENT(STYLE, XML_NUM_SUFFIX): sSuffix = aIter.toString(); break; + case XML_ELEMENT(STYLE, XML_NUM_LIST_FORMAT): + case XML_ELEMENT(LO_EXT, XML_NUM_LIST_FORMAT): + sListFormat = std::make_optional(aIter.toString()); + break; case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC): if( bNum ) sNumLetterSync = aIter.toString(); @@ -392,12 +399,32 @@ Sequence<beans::PropertyValue> SvxXMLListLevelStyleContext_Impl::GetProperties() } } + if (!sListFormat.has_value()) + { + // This is older document: it has no list format, but can probably contain prefix and/or suffix + // Generate list format string, based on this + sListFormat = std::make_optional(sPrefix); + + for (int i = 1; i <= nNumDisplayLevels; i++) + { + *sListFormat += "%"; + *sListFormat += OUString::number(nLevel - nNumDisplayLevels + i + 1); + *sListFormat += "%"; + if (i != nNumDisplayLevels) + *sListFormat += "."; // Default separator for older ODT + } + + *sListFormat += sSuffix; + } + aProperties.push_back(comphelper::makePropertyValue("NumberingType", eType)); aProperties.push_back(comphelper::makePropertyValue("Prefix", sPrefix)); aProperties.push_back(comphelper::makePropertyValue("Suffix", sSuffix)); + aProperties.push_back(comphelper::makePropertyValue("ListFormat", *sListFormat)); + aProperties.push_back(comphelper::makePropertyValue("Adjust", eAdjust)); sal_Int32 nLeftMargin = nSpaceBefore + nMinLabelWidth; diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index de859d508fb8..403482cce9ab 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -1283,6 +1283,7 @@ null-date null-year num-format num-letter-sync +num-list-format num-prefix num-suffix numalign |