diff options
author | Laurent Balland-Poirier <laurent.balland-poirier@laposte.net> | 2015-03-15 19:22:56 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-03-22 15:44:55 +0000 |
commit | fdf8e5aaee49304df7f2f04fcdd932c3dd427703 (patch) | |
tree | c537fb338d736e4919dc41aa68372f0d007639b2 /xmloff | |
parent | 4cb902edc070282fd4a6eb84ae03d2fd066e7ca5 (diff) |
tdf#30716 start Engineering notation: implement exponent-interval
ODF1.3 implement a new attribute for engineering notation
https://issues.oasis-open.org/browse/OFFICE-1828
This commit only add this attribute to ODF import/export.
Engineering notation is not yet available.
Treat also thousand separator with exponent-interval
Change XML_NAMESPACE_NUMBER to XML_NAMESPACE_LO_EXT for
exponent-interval
Change-Id: Ia18f9e150ca32aa9bbe133c082c3f9330e949f11
Reviewed-on: https://gerrit.libreoffice.org/14875
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/style/xmlnumfe.cxx | 13 | ||||
-rw-r--r-- | xmloff/source/style/xmlnumfi.cxx | 46 |
3 files changed, 56 insertions, 5 deletions
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index e651e1bb8315..0a1835b743d6 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3242,6 +3242,8 @@ namespace xmloff { namespace token { TOKEN( "display-units-built-in-unit", XML_CHART_DUNITS_BUILTINUNIT ), TOKEN( "external-data", XML_EXTERNALDATA), + TOKEN( "exponent-interval", XML_EXPONENT_INTERVAL ), + #if OSL_DEBUG_LEVEL > 0 { 0, NULL, NULL, XML_TOKEN_END } #else diff --git a/xmloff/source/style/xmlnumfe.cxx b/xmloff/source/style/xmlnumfe.cxx index 4689e51ea787..f9402d2a6a28 100644 --- a/xmloff/source/style/xmlnumfe.cxx +++ b/xmloff/source/style/xmlnumfe.cxx @@ -634,7 +634,7 @@ void SvXMLNumFmtExport::WriteNumberElement_Impl( void SvXMLNumFmtExport::WriteScientificElement_Impl( sal_Int32 nDecimals, sal_Int32 nInteger, - bool bGrouping, sal_Int32 nExp ) + bool bGrouping, sal_Int32 nExp, sal_Int32 nExpInterval ) { FinishTextElement_Impl(); @@ -665,6 +665,13 @@ void SvXMLNumFmtExport::WriteScientificElement_Impl( OUString::number( nExp ) ); } + // exponent interval for engineering notation + if ( nExpInterval >= 0 ) + { // when exponent-interval will be part of ODF 1.3, change to XML_NAMESPACE_NUMBER + rExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_EXPONENT_INTERVAL, + OUString::number( nExpInterval ) ); + } + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_SCIENTIFIC_NUMBER, true, false ); @@ -1400,8 +1407,8 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt case css::util::NumberFormat::SCIENTIFIC: // #i43959# for scientific numbers, count all integer symbols ("0" and "#") // as integer digits: use nIntegerSymbols instead of nLeading - // (use of '#' to select multiples in exponent might be added later) - WriteScientificElement_Impl( nPrecision, nIntegerSymbols, bThousand, nExpDigits ); + // nIntegerSymbols represents exponent interval (for engineering notation) + WriteScientificElement_Impl( nPrecision, nLeading, bThousand, nExpDigits, nIntegerSymbols ); bAnyContent = true; break; case css::util::NumberFormat::FRACTION: diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx index 14d8bf3a5c90..c1e458a81848 100644 --- a/xmloff/source/style/xmlnumfi.cxx +++ b/xmloff/source/style/xmlnumfi.cxx @@ -110,6 +110,7 @@ struct SvXMLNumberInfo sal_Int32 nDecimals; sal_Int32 nInteger; sal_Int32 nExpDigits; + sal_Int32 nExpInterval; sal_Int32 nNumerDigits; sal_Int32 nDenomDigits; sal_Int32 nFracDenominator; @@ -121,7 +122,7 @@ struct SvXMLNumberInfo SvXMLNumberInfo() { - nDecimals = nInteger = nExpDigits = nNumerDigits = nDenomDigits = nFracDenominator = -1; + nDecimals = nInteger = nExpDigits = nExpInterval = nNumerDigits = nDenomDigits = nFracDenominator = -1; bGrouping = bDecReplace = bVarDecimals = false; fDisplayFactor = 1.0; } @@ -203,7 +204,7 @@ public: class SvXMLNumFmtPropContext : public SvXMLImportContext { SvXMLNumFormatContext& rParent; - sal_Int32 m_nColor; + sal_Int32 m_nColor; bool bColSet; public: @@ -276,6 +277,7 @@ enum SvXMLStyleElemAttrTokens XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT, XML_TOK_ELEM_ATTR_DENOMINATOR_VALUE, XML_TOK_ELEM_ATTR_MIN_EXPONENT_DIGITS, + XML_TOK_ELEM_ATTR_EXPONENT_INTERVAL, XML_TOK_ELEM_ATTR_MIN_NUMERATOR_DIGITS, XML_TOK_ELEM_ATTR_MIN_DENOMINATOR_DIGITS, XML_TOK_ELEM_ATTR_RFC_LANGUAGE_TAG, @@ -571,6 +573,8 @@ const SvXMLTokenMap& SvXMLNumImpData::GetStyleElemAttrTokenMap() { XML_NAMESPACE_NUMBER, XML_DECIMAL_REPLACEMENT, XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT }, { XML_NAMESPACE_NUMBER, XML_DENOMINATOR_VALUE, XML_TOK_ELEM_ATTR_DENOMINATOR_VALUE }, { XML_NAMESPACE_NUMBER, XML_MIN_EXPONENT_DIGITS, XML_TOK_ELEM_ATTR_MIN_EXPONENT_DIGITS }, + // number:exponent-interval will be supported in ODF 1.3 + { XML_NAMESPACE_LO_EXT, XML_EXPONENT_INTERVAL, XML_TOK_ELEM_ATTR_EXPONENT_INTERVAL }, { XML_NAMESPACE_NUMBER, XML_MIN_NUMERATOR_DIGITS, XML_TOK_ELEM_ATTR_MIN_NUMERATOR_DIGITS }, { XML_NAMESPACE_NUMBER, XML_MIN_DENOMINATOR_DIGITS, XML_TOK_ELEM_ATTR_MIN_DENOMINATOR_DIGITS }, { XML_NAMESPACE_NUMBER, XML_RFC_LANGUAGE_TAG, XML_TOK_ELEM_ATTR_RFC_LANGUAGE_TAG }, @@ -958,6 +962,10 @@ SvXMLNumFmtElementContext::SvXMLNumFmtElementContext( SvXMLImport& rImport, if (::sax::Converter::convertNumber( nAttrVal, sValue, 0 )) aNumInfo.nExpDigits = nAttrVal; break; + case XML_TOK_ELEM_ATTR_EXPONENT_INTERVAL: + if (::sax::Converter::convertNumber( nAttrVal, sValue, 0 )) + aNumInfo.nExpInterval = nAttrVal; + break; case XML_TOK_ELEM_ATTR_MIN_NUMERATOR_DIGITS: if (::sax::Converter::convertNumber( nAttrVal, sValue, 0 )) aNumInfo.nNumerDigits = nAttrVal; @@ -1219,6 +1227,14 @@ void SvXMLNumFmtElementContext::EndElement() case XML_TOK_STYLE_SCIENTIFIC_NUMBER: { + // exponential interval for engineering notation + if( !aNumInfo.bGrouping && aNumInfo.nExpInterval > aNumInfo.nInteger ) + { + for (sal_Int32 i=0; i<aNumInfo.nExpInterval-aNumInfo.nInteger; i++) + { + rParent.AddToCode( '#' ); + } + } rParent.AddNumber( aNumInfo ); // simple number rParent.AddToCode( OUString("E+") ); @@ -1792,6 +1808,32 @@ void SvXMLNumFormatContext::AddNumber( const SvXMLNumberInfo& rInfo ) aNumStr.stripStart('#'); } + if ( bGrouping && rInfo.nExpInterval > rInfo.nInteger ) + { + sal_Int32 nIndex = 0; + sal_Int32 nDigits = rInfo.nInteger; + sal_Int32 nIntegerEnd = aNumStr.indexOf( pFormatter->GetNumDecimalSep() ); + if ( nIntegerEnd < 0 ) + nIntegerEnd = aNumStr.getLength(); + while ( nIndex >= 0 && nIndex < nIntegerEnd ) + { + if ( ( nIndex = aNumStr.indexOf( '#', nIndex ) ) >= 0 ) + { + nDigits ++; + nIndex ++; + } + else + nIndex = -1; + } + if( rInfo.nExpInterval > nDigits ) + { + for (sal_Int32 i=0; i<rInfo.nExpInterval-nDigits; i++) + { + aNumStr.insert( 0, '#' ); + } + } + } + if ( nEmbeddedCount ) { // insert embedded strings into number string |