diff options
author | Laurent BP <laurent.balland-poirier@laposte.net> | 2018-06-23 13:03:08 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2018-07-10 14:53:52 +0200 |
commit | c290f692dd28094d41dff686f3faa1c4e14b556e (patch) | |
tree | 93b1d746ac3d550e54a1831eacf96fb470182fd1 /xmloff/source/style/xmlnumfe.cxx | |
parent | 1f66bd9cbd961d1923c260b2d74249e363a0c217 (diff) |
tdf#118324 Extend ODF for blank in integer
Following resolution of tdf#117575, this commit add
disambiguation between '0' and '?' in integer part
XML_MAX_BLANK_INTEGER_DIGITS is added for the number of '?'
XML_MIN_INTEGER_DIGITS is the number of '?' and '0'
This preserve compatibility with previous versions:
in previous versions '?' will be transformed in '0'
It also applies to scientific and fraction numbers.
Change-Id: I6e1185bbece9c615240425cc973d59052b22aa34
Reviewed-on: https://gerrit.libreoffice.org/56352
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'xmloff/source/style/xmlnumfe.cxx')
-rw-r--r-- | xmloff/source/style/xmlnumfe.cxx | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/xmloff/source/style/xmlnumfe.cxx b/xmloff/source/style/xmlnumfe.cxx index 52847a6a8784..96cd44061b3f 100644 --- a/xmloff/source/style/xmlnumfe.cxx +++ b/xmloff/source/style/xmlnumfe.cxx @@ -542,7 +542,7 @@ void SvXMLNumFmtExport::WriteAMPMElement_Impl() void SvXMLNumFmtExport::WriteNumberElement_Impl( sal_Int32 nDecimals, sal_Int32 nMinDecimals, - sal_Int32 nInteger, const OUString& rDashStr, + sal_Int32 nInteger, sal_Int32 nBlankInteger, const OUString& rDashStr, bool bGrouping, sal_Int32 nTrailingThousands, const SvXMLEmbeddedTextEntryArr& rEmbeddedEntries ) { @@ -555,10 +555,10 @@ void SvXMLNumFmtExport::WriteNumberElement_Impl( OUString::number( nDecimals ) ); } + SvtSaveOptions::ODFSaneDefaultVersion eVersion = rExport.getSaneDefaultVersion(); if ( nMinDecimals >= 0 ) // negative = automatic { // Export only for 1.2 with extensions or 1.3 and later. - SvtSaveOptions::ODFSaneDefaultVersion eVersion = rExport.getSaneDefaultVersion(); if (eVersion > SvtSaveOptions::ODFSVER_012) { // For 1.2+ use loext namespace, for 1.3 use number namespace. @@ -569,13 +569,20 @@ void SvXMLNumFmtExport::WriteNumberElement_Impl( } } - // integer digits + // integer digits: '0' and '?' if ( nInteger >= 0 ) // negative = automatic { rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_MIN_INTEGER_DIGITS, OUString::number( nInteger ) ); } + // blank integer digits: '?' + if ( nBlankInteger > 0 && ( (eVersion & SvtSaveOptions::ODFSVER_EXTENDED) != 0 ) ) + { + rExport.AddAttribute( XML_NAMESPACE_LO_EXT, XML_MAX_BLANK_INTEGER_DIGITS, + OUString::number( nBlankInteger ) ); + } + // decimal replacement (dashes) or variable decimals (#) if ( !rDashStr.isEmpty() || nMinDecimals < nDecimals ) { @@ -632,7 +639,7 @@ void SvXMLNumFmtExport::WriteNumberElement_Impl( } void SvXMLNumFmtExport::WriteScientificElement_Impl( - sal_Int32 nDecimals, sal_Int32 nMinDecimals, sal_Int32 nInteger, + sal_Int32 nDecimals, sal_Int32 nMinDecimals, sal_Int32 nInteger, sal_Int32 nBlankInteger, bool bGrouping, sal_Int32 nExp, sal_Int32 nExpInterval, bool bExpSign ) { FinishTextElement_Impl(); @@ -665,6 +672,13 @@ void SvXMLNumFmtExport::WriteScientificElement_Impl( OUString::number( nInteger ) ); } + // blank integer digits '?' + if ( nBlankInteger > 0 && ( (eVersion & SvtSaveOptions::ODFSVER_EXTENDED) != 0 ) ) + { + rExport.AddAttribute( XML_NAMESPACE_LO_EXT, XML_MAX_BLANK_INTEGER_DIGITS, + OUString::number( nBlankInteger ) ); + } + // (automatic) grouping separator if ( bGrouping ) { @@ -708,7 +722,7 @@ void SvXMLNumFmtExport::WriteScientificElement_Impl( } void SvXMLNumFmtExport::WriteFractionElement_Impl( - sal_Int32 nInteger, bool bGrouping, + sal_Int32 nInteger, sal_Int32 nBlankInteger, bool bGrouping, const SvNumberformat& rFormat, sal_uInt16 nPart ) { FinishTextElement_Impl(); @@ -747,6 +761,14 @@ void SvXMLNumFmtExport::WriteFractionElement_Impl( OUString::number( nInteger ) ); } + SvtSaveOptions::ODFSaneDefaultVersion eVersion = rExport.getSaneDefaultVersion(); + // blank integer digits '?' + if ( nBlankInteger > 0 && ( (eVersion & SvtSaveOptions::ODFSVER_EXTENDED) != 0 ) ) + { + rExport.AddAttribute( XML_NAMESPACE_LO_EXT, XML_MAX_BLANK_INTEGER_DIGITS, + OUString::number( nBlankInteger ) ); + } + // (automatic) grouping separator if ( bGrouping ) { @@ -754,7 +776,6 @@ void SvXMLNumFmtExport::WriteFractionElement_Impl( } // integer/fraction delimiter - SvtSaveOptions::ODFSaneDefaultVersion eVersion = rExport.getSaneDefaultVersion(); if ( !aIntegerFractionDelimiterString.isEmpty() && aIntegerFractionDelimiterString != " " && ((eVersion & SvtSaveOptions::ODFSVER_EXTENDED) != 0) ) { // Export only for 1.2 with extensions or 1.3 and later. @@ -1260,7 +1281,7 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt if ( eBuiltIn == NF_NUMBER_STANDARD ) { // default number format contains just one number element - WriteNumberElement_Impl( -1, -1, 1, OUString(), false, 0, aEmbeddedEntries ); + WriteNumberElement_Impl( -1, -1, 1, -1, OUString(), false, 0, aEmbeddedEntries ); bAnyContent = true; } else if ( eBuiltIn == NF_BOOLEAN ) @@ -1283,6 +1304,7 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt sal_Int32 nIntegerSymbols = 0; // for embedded-text, including "#" sal_Int32 nTrailingThousands = 0; // thousands-separators after all digits sal_Int32 nMinDecimals = nPrecision; + sal_Int32 nBlankInteger = 0; OUString sCurrExt; OUString aCalendar; sal_uInt16 nPos = 0; @@ -1305,7 +1327,7 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt bDecDashes = true; nMinDecimals = 0; } - else if ( !bInInteger && pElemStr ) + else if ( nFmtType != SvNumFormatType::FRACTION && !bInInteger && pElemStr ) { for ( sal_Int32 i = pElemStr->getLength()-1; i >= 0 ; i-- ) { @@ -1321,10 +1343,18 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt } } if ( bInInteger && pElemStr ) + { nIntegerSymbols += pElemStr->getLength(); + for ( sal_Int32 i = pElemStr->getLength()-1; i >= 0 ; i-- ) + { + if ( (*pElemStr)[i] == '?' ) + nBlankInteger ++; + } + } nTrailingThousands = 0; break; case NF_SYMBOLTYPE_DECSEP: + case NF_SYMBOLTYPE_FRACBLANK: bInInteger = false; break; case NF_SYMBOLTYPE_THSEP: @@ -1473,7 +1503,7 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt } break; case NF_KEY_GENERAL : - WriteNumberElement_Impl( -1, -1, 1, OUString(), false, 0, aEmbeddedEntries ); + WriteNumberElement_Impl( -1, -1, 1, -1, OUString(), false, 0, aEmbeddedEntries ); break; case NF_KEY_CCC: if (pElemStr) @@ -1531,7 +1561,10 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt // only one built-in format has automatic integer digits sal_Int32 nInteger = nLeading; if ( eBuiltIn == NF_NUMBER_SYSTEM ) + { nInteger = -1; + nBlankInteger = -1; + } // string for decimal replacement // has to be taken from nPrecision @@ -1543,16 +1576,17 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt if (bDecAlign && nPrecision > 0) sDashStr = " "; - WriteNumberElement_Impl(nDecimals, nMinDecimals, nInteger, sDashStr.makeStringAndClear(), + WriteNumberElement_Impl(nDecimals, nMinDecimals, nInteger, nBlankInteger, sDashStr.makeStringAndClear(), bThousand, nTrailingThousands, aEmbeddedEntries); bAnyContent = true; } break; case SvNumFormatType::SCIENTIFIC: - // #i43959# for scientific numbers, count all integer symbols ("0" and "#") + // #i43959# for scientific numbers, count all integer symbols ("0", "?" and "#") // as integer digits: use nIntegerSymbols instead of nLeading // nIntegerSymbols represents exponent interval (for engineering notation) - WriteScientificElement_Impl( nPrecision, nMinDecimals, nLeading, bThousand, nExpDigits, nIntegerSymbols, bExpSign ); + WriteScientificElement_Impl( nPrecision, nMinDecimals, nLeading, nBlankInteger, + bThousand, nExpDigits, nIntegerSymbols, bExpSign ); bAnyContent = true; break; case SvNumFormatType::FRACTION: @@ -1564,8 +1598,9 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt // the fraction doesn't have an integer part, and no // min-integer-digits attribute must be written. nInteger = -1; + nBlankInteger = -1; } - WriteFractionElement_Impl( nInteger, bThousand, rFormat, nPart ); + WriteFractionElement_Impl( nInteger, nBlankInteger, bThousand, rFormat, nPart ); bAnyContent = true; } break; |