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 | |
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>
-rw-r--r-- | include/xmloff/xmlnumfe.hxx | 6 | ||||
-rw-r--r-- | include/xmloff/xmlnumfi.hxx | 2 | ||||
-rw-r--r-- | include/xmloff/xmltoken.hxx | 1 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 3 | ||||
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 1 | ||||
-rw-r--r-- | xmloff/source/style/xmlnumfe.cxx | 61 | ||||
-rw-r--r-- | xmloff/source/style/xmlnumfi.cxx | 33 | ||||
-rw-r--r-- | xmloff/source/token/tokens.txt | 1 |
8 files changed, 88 insertions, 20 deletions
diff --git a/include/xmloff/xmlnumfe.hxx b/include/xmloff/xmlnumfe.hxx index 75c3b133c036..b52136b8d677 100644 --- a/include/xmloff/xmlnumfe.hxx +++ b/include/xmloff/xmlnumfe.hxx @@ -64,12 +64,12 @@ private: SAL_DLLPRIVATE void WriteColorElement_Impl( const Color& rColor ); SAL_DLLPRIVATE void 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 ); - SAL_DLLPRIVATE void WriteScientificElement_Impl( sal_Int32 nDecimals, sal_Int32 nMinDecimals, sal_Int32 nInteger, + SAL_DLLPRIVATE void WriteScientificElement_Impl( sal_Int32 nDecimals, sal_Int32 nMinDecimals, sal_Int32 nInteger, sal_Int32 nBlankInteger, bool bGrouping, sal_Int32 nExp, sal_Int32 nExpInterval, bool bExpSign ); - SAL_DLLPRIVATE void WriteFractionElement_Impl( sal_Int32 nInteger, bool bGrouping, + SAL_DLLPRIVATE void WriteFractionElement_Impl( sal_Int32 nInteger, sal_Int32 nBlankInteger, bool bGrouping, const SvNumberformat& rFormat, sal_uInt16 nPart ); SAL_DLLPRIVATE void WriteCurrencyElement_Impl( const OUString& rString, const OUString& rExt ); diff --git a/include/xmloff/xmlnumfi.hxx b/include/xmloff/xmlnumfi.hxx index 39d058fbaeed..7e01f6afb4f3 100644 --- a/include/xmloff/xmlnumfi.hxx +++ b/include/xmloff/xmlnumfi.hxx @@ -157,7 +157,7 @@ class XMLOFF_DLLPUBLIC SvXMLNumFormatContext : public SvXMLStyleContext public: SvXMLNumFormatContext( SvXMLImport& rImport, - sal_uInt16 nPrfx, + sal_uInt16 nPrfx, const OUString& rLName, SvXMLNumImpData* pNewData, sal_uInt16 nNewType, diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx index 862741d0a0eb..017af65a526b 100644 --- a/include/xmloff/xmltoken.hxx +++ b/include/xmloff/xmltoken.hxx @@ -3316,6 +3316,7 @@ namespace xmloff { namespace token { XML_ZEROS_NUMERATOR_DIGITS, XML_ZEROS_DENOMINATOR_DIGITS, XML_INTEGER_FRACTION_DELIMITER, + XML_MAX_BLANK_INTEGER_DIGITS, // tdf#115319 XML_REFERENCE_LANGUAGE, diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 53e7a02e9acf..9b4ef9da027e 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -4755,9 +4755,10 @@ void SvNumberformat::GetNumForInfo( sal_uInt16 nNumFor, SvNumFormatType& rScanne { p++; } - while ( *p++ == '0' ) + while ( *p == '0' || *p == '?' ) { nLeadingCnt++; + p++; } } else if (nType == NF_SYMBOLTYPE_DECSEP diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index f32309b3e1a1..13e58baea38a 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3309,6 +3309,7 @@ namespace xmloff { namespace token { TOKEN( "zeros-numerator-digits", XML_ZEROS_NUMERATOR_DIGITS ), TOKEN( "zeros-denominator-digits", XML_ZEROS_DENOMINATOR_DIGITS ), TOKEN( "integer-fraction-delimiter", XML_INTEGER_FRACTION_DELIMITER ), + TOKEN( "max-blank-integer-digits", XML_MAX_BLANK_INTEGER_DIGITS ), // for optional language-dependent reference formats TOKEN( "reference-language", XML_REFERENCE_LANGUAGE ), 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; diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx index e611c144f290..5d68358c2db5 100644 --- a/xmloff/source/style/xmlnumfi.cxx +++ b/xmloff/source/style/xmlnumfi.cxx @@ -92,7 +92,8 @@ public: struct SvXMLNumberInfo { sal_Int32 nDecimals; - sal_Int32 nInteger; + sal_Int32 nInteger; /// Total min number of digits in integer part ('0' + '?') + sal_Int32 nBlankInteger; /// Number of '?' in integer part sal_Int32 nExpDigits; sal_Int32 nExpInterval; sal_Int32 nMinNumerDigits; @@ -113,7 +114,7 @@ struct SvXMLNumberInfo SvXMLNumberInfo() { - nDecimals = nInteger = nExpDigits = nExpInterval = nMinNumerDigits = nMinDenomDigits = nMaxNumerDigits = nMaxDenomDigits = + nDecimals = nInteger = nBlankInteger = nExpDigits = nExpInterval = nMinNumerDigits = nMinDenomDigits = nMaxNumerDigits = nMaxDenomDigits = nFracDenominator = nMinDecimalDigits = nZerosNumerDigits = nZerosDenomDigits = -1; bGrouping = bDecReplace = bDecAlign = false; bExpSign = true; @@ -253,6 +254,7 @@ enum SvXMLStyleElemAttrTokens XML_TOK_ELEM_ATTR_DECIMAL_PLACES, XML_TOK_ELEM_ATTR_MIN_DECIMAL_PLACES, XML_TOK_ELEM_ATTR_MIN_INTEGER_DIGITS, + XML_TOK_ELEM_ATTR_MAX_BLANK_INTEGER_DIGITS, XML_TOK_ELEM_ATTR_GROUPING, XML_TOK_ELEM_ATTR_DISPLAY_FACTOR, XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT, @@ -544,6 +546,8 @@ const SvXMLTokenMap& SvXMLNumImpData::GetStyleElemAttrTokenMap() { XML_NAMESPACE_LO_EXT, XML_MIN_DECIMAL_PLACES, XML_TOK_ELEM_ATTR_MIN_DECIMAL_PLACES }, { XML_NAMESPACE_NUMBER, XML_MIN_DECIMAL_PLACES, XML_TOK_ELEM_ATTR_MIN_DECIMAL_PLACES }, { XML_NAMESPACE_NUMBER, XML_MIN_INTEGER_DIGITS, XML_TOK_ELEM_ATTR_MIN_INTEGER_DIGITS }, + { XML_NAMESPACE_LO_EXT, XML_MAX_BLANK_INTEGER_DIGITS,XML_TOK_ELEM_ATTR_MAX_BLANK_INTEGER_DIGITS }, + { XML_NAMESPACE_NUMBER, XML_MAX_BLANK_INTEGER_DIGITS,XML_TOK_ELEM_ATTR_MAX_BLANK_INTEGER_DIGITS }, { XML_NAMESPACE_NUMBER, XML_GROUPING, XML_TOK_ELEM_ATTR_GROUPING }, { XML_NAMESPACE_NUMBER, XML_DISPLAY_FACTOR, XML_TOK_ELEM_ATTR_DISPLAY_FACTOR }, { XML_NAMESPACE_NUMBER, XML_DECIMAL_REPLACEMENT, XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT }, @@ -931,6 +935,10 @@ SvXMLNumFmtElementContext::SvXMLNumFmtElementContext( SvXMLImport& rImport, if (::sax::Converter::convertNumber( nAttrVal, sValue, 0 )) aNumInfo.nInteger = nAttrVal; break; + case XML_TOK_ELEM_ATTR_MAX_BLANK_INTEGER_DIGITS: + if (::sax::Converter::convertNumber( nAttrVal, sValue, 0 )) + aNumInfo.nBlankInteger = nAttrVal; + break; case XML_TOK_ELEM_ATTR_GROUPING: if (::sax::Converter::convertBool( bAttrBool, sValue )) aNumInfo.bGrouping = bAttrBool; @@ -1024,6 +1032,8 @@ SvXMLNumFmtElementContext::SvXMLNumFmtElementContext( SvXMLImport& rImport, break; } } + if ( aNumInfo.nBlankInteger > aNumInfo.nInteger ) + aNumInfo.nInteger = aNumInfo.nBlankInteger; if ( aNumInfo.nMinDecimalDigits == -1) { if ( bVarDecimals || aNumInfo.bDecReplace ) @@ -1894,6 +1904,25 @@ void SvXMLNumFormatContext::AddNumber( const SvXMLNumberInfo& rInfo ) aNumStr.stripStart('#'); } + if ( rInfo.nBlankInteger > 0 ) + { + // Replace nBlankInteger '0' by '?' + sal_Int32 nIndex = 0; + sal_Int32 nBlanks = rInfo.nBlankInteger; + sal_Int32 nIntegerEnd = aNumStr.indexOf( pFormatter->GetNumDecimalSep() ); + if ( nIntegerEnd < 0 ) + nIntegerEnd = aNumStr.getLength(); + while ( nIndex < nIntegerEnd && nBlanks > 0 ) + { + if ( aNumStr[nIndex] == '0' ) + { + aNumStr[nIndex] = '?'; + nBlanks--; + } + nIndex++; + } + } + if ( bGrouping && rInfo.nExpInterval > rInfo.nInteger ) { sal_Int32 nIndex = 0; diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index 63e8b99015ab..4b1c8544b7a0 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -3084,6 +3084,7 @@ max-numerator-digits zeros-numerator-digits zeros-denominator-digits integer-fraction-delimiter +max-blank-integer-digits reference-language newline creator-initials |