[Libreoffice-commits] core.git: include/svl include/xmloff svl/source xmloff/source

Laurent Balland-Poirier laurent.balland-poirier at laposte.net
Wed Jul 27 13:13:01 UTC 2016


 include/svl/zformat.hxx          |    1 +
 include/xmloff/xmlnumfe.hxx      |    2 +-
 include/xmloff/xmltoken.hxx      |    1 +
 svl/source/numbers/zformat.cxx   |   20 ++++++++++++++++++++
 xmloff/source/core/xmltoken.cxx  |    1 +
 xmloff/source/style/xmlnumfe.cxx |   17 ++++++++++++++---
 xmloff/source/style/xmlnumfi.cxx |   14 +++++++++++++-
 7 files changed, 51 insertions(+), 5 deletions(-)

New commits:
commit f06a3503b69819e1d018ee4f587655173dff503e
Author: Laurent Balland-Poirier <laurent.balland-poirier at laposte.net>
Date:   Sat Jul 16 22:39:32 2016 +0200

    tdf#100834 Extend ODF for integer/fraction delimiter
    
    Any string can be used as delimiter between integer and fraction.
    It is now saved/loaded to/from ODF, as it was from XLS.
    
    Change-Id: Ie6364d1cdefc020ea615c18099118135c619f96b
    Reviewed-on: https://gerrit.libreoffice.org/27262
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx
index ab82bcc..57245a9 100644
--- a/include/svl/zformat.hxx
+++ b/include/svl/zformat.hxx
@@ -251,6 +251,7 @@ public:
 
     OUString GetDenominatorString( sal_uInt16 nNumFor ) const;
     OUString GetNumeratorString( sal_uInt16 nNumFor ) const;
+    OUString GetIntegerFractionDelimiterString( sal_uInt16 nNumFor ) const;
     /** If the count of string elements (substrings, ignoring [modifiers] and
         so on) in a subformat code nNumFor (0..3) is equal to the given number.
         Used by ImpSvNumberInputScan::IsNumberFormatMain() to detect a matched
diff --git a/include/xmloff/xmlnumfe.hxx b/include/xmloff/xmlnumfe.hxx
index be72e4b..c04b8e4 100644
--- a/include/xmloff/xmlnumfe.hxx
+++ b/include/xmloff/xmlnumfe.hxx
@@ -70,7 +70,7 @@ private:
     SAL_DLLPRIVATE void WriteScientificElement_Impl( sal_Int32 nDecimals, sal_Int32 nMinDecimals, sal_Int32 nInteger,
                                         bool bGrouping, sal_Int32 nExp, sal_Int32 nExpInterval, bool bExpSign );
     SAL_DLLPRIVATE void WriteFractionElement_Impl( sal_Int32 nInteger, bool bGrouping,
-                                                   const OUString& aNumeratorString, const OUString& aDenominatorString );
+                                                   const SvNumberformat& rFormat, sal_uInt16 nPart );
     SAL_DLLPRIVATE void WriteCurrencyElement_Impl( const OUString& rString,
                                         const OUString& rExt );
     SAL_DLLPRIVATE void WriteBooleanElement_Impl();
diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
index aa462c3..0a56591 100644
--- a/include/xmloff/xmltoken.hxx
+++ b/include/xmloff/xmltoken.hxx
@@ -3271,6 +3271,7 @@ namespace xmloff { namespace token {
         XML_MAX_NUMERATOR_DIGITS,
         XML_ZEROS_NUMERATOR_DIGITS,
         XML_ZEROS_DENOMINATOR_DIGITS,
+        XML_INTEGER_FRACTION_DELIMITER,
 
         XML_TOKEN_END
     };
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 5e37a70..ce018a1 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -2020,6 +2020,19 @@ OUString lcl_GetFractionIntegerString(const ImpSvNumberformatInfo &rInfo, sal_uI
     return aIntegerString.makeStringAndClear();
 }
 
+OUString lcl_GetIntegerFractionDelimiterString(const ImpSvNumberformatInfo &rInfo, sal_uInt16 nAnz)
+{
+    sal_Int16 i;
+    for( i = 0; i < nAnz; i++ )
+    {
+        if( rInfo.nTypeArray[i] == NF_SYMBOLTYPE_FRACBLANK )
+        {
+            return rInfo.sStrArray[i];
+        }
+    }
+    return OUString();
+}
+
 }
 
 OUString SvNumberformat::GetDenominatorString( sal_uInt16 nNumFor ) const
@@ -2036,6 +2049,13 @@ OUString SvNumberformat::GetNumeratorString( sal_uInt16 nNumFor ) const
     return lcl_GetNumeratorString( rInfo, nAnz );
 }
 
+OUString SvNumberformat::GetIntegerFractionDelimiterString( sal_uInt16 nNumFor ) const
+{
+    const ImpSvNumberformatInfo& rInfo = NumFor[nNumFor].Info();
+    sal_uInt16 nAnz = NumFor[nNumFor].GetCount();
+    return lcl_GetIntegerFractionDelimiterString( rInfo, nAnz );
+}
+
 bool SvNumberformat::GetOutputString(double fNumber, sal_uInt16 nCharCount, OUString& rOutString) const
 {
     using namespace std;
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index 6f7caaa..f6924bb 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -3267,6 +3267,7 @@ namespace xmloff { namespace token {
         TOKEN( "max-numerator-digits",            XML_MAX_NUMERATOR_DIGITS ),
         TOKEN( "zeros-numerator-digits",          XML_ZEROS_NUMERATOR_DIGITS ),
         TOKEN( "zeros-denominator-digits",        XML_ZEROS_DENOMINATOR_DIGITS ),
+        TOKEN( "integer-fraction-delimiter",      XML_INTEGER_FRACTION_DELIMITER ),
 
 #if OSL_DEBUG_LEVEL > 0
         { 0, nullptr, nullptr,                       XML_TOKEN_END }
diff --git a/xmloff/source/style/xmlnumfe.cxx b/xmloff/source/style/xmlnumfe.cxx
index 20b416c..f449331 100644
--- a/xmloff/source/style/xmlnumfe.cxx
+++ b/xmloff/source/style/xmlnumfe.cxx
@@ -727,9 +727,12 @@ void SvXMLNumFmtExport::WriteScientificElement_Impl(
 
 void SvXMLNumFmtExport::WriteFractionElement_Impl(
                             sal_Int32 nInteger, bool bGrouping,
-                            const OUString& aNumeratorString , const OUString& aDenominatorString )
+                            const SvNumberformat& rFormat, sal_uInt16 nPart )
 {
     FinishTextElement_Impl();
+    const OUString aNumeratorString = rFormat.GetNumeratorString( nPart );
+    const OUString aDenominatorString = rFormat.GetDenominatorString( nPart );
+    const OUString aIntegerFractionDelimiterString = rFormat.GetIntegerFractionDelimiterString( nPart );
     sal_Int32 nMaxNumeratorDigits = aNumeratorString.getLength();
     // Count '0' as '?'
     sal_Int32 nMinNumeratorDigits = aNumeratorString.replaceAll("0","?").indexOf('?');
@@ -768,13 +771,21 @@ void SvXMLNumFmtExport::WriteFractionElement_Impl(
         rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_GROUPING, XML_TRUE );
     }
 
+    // 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.
+        rExport.AddAttribute( XML_NAMESPACE_LO_EXT, XML_INTEGER_FRACTION_DELIMITER,
+                              aIntegerFractionDelimiterString );
+    }
+
     //  numerator digits
     if ( nMinNumeratorDigits == 0 ) // at least one digit to keep compatibility with previous versions
         nMinNumeratorDigits++;
     rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_MIN_NUMERATOR_DIGITS,
                           OUString::number( nMinNumeratorDigits ) );
     // Export only for 1.2 with extensions or 1.3 and later.
-    SvtSaveOptions::ODFSaneDefaultVersion eVersion = rExport.getSaneDefaultVersion();
     if ((eVersion & SvtSaveOptions::ODFSVER_EXTENDED) != 0)
     {
         // For extended ODF use loext namespace
@@ -1540,7 +1551,7 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt
                                         //  min-integer-digits attribute must be written.
                                         nInteger = -1;
                                     }
-                                    WriteFractionElement_Impl( nInteger, bThousand,  rFormat.GetNumeratorString( nPart ), rFormat.GetDenominatorString( nPart ) );
+                                    WriteFractionElement_Impl( nInteger, bThousand,  rFormat, nPart );
                                     bAnyContent = true;
                                 }
                                 break;
diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx
index c9da66a..7dc053f 100644
--- a/xmloff/source/style/xmlnumfi.cxx
+++ b/xmloff/source/style/xmlnumfi.cxx
@@ -108,6 +108,7 @@ struct SvXMLNumberInfo
     bool        bExpSign;
     bool        bDecAlign;
     double      fDisplayFactor;
+    OUString    aIntegerFractionDelimiter;
     std::map<sal_Int32, OUString> m_EmbeddedElements;
 
     SvXMLNumberInfo()
@@ -270,6 +271,7 @@ enum SvXMLStyleElemAttrTokens
     XML_TOK_ELEM_ATTR_MAX_DENOMINATOR_VALUE,
     XML_TOK_ELEM_ATTR_ZEROS_NUMERATOR_DIGITS,
     XML_TOK_ELEM_ATTR_ZEROS_DENOMINATOR_DIGITS,
+    XML_TOK_ELEM_ATTR_INTEGER_FRACTION_DELIMITER,
     XML_TOK_ELEM_ATTR_RFC_LANGUAGE_TAG,
     XML_TOK_ELEM_ATTR_LANGUAGE,
     XML_TOK_ELEM_ATTR_SCRIPT,
@@ -577,6 +579,8 @@ const SvXMLTokenMap& SvXMLNumImpData::GetStyleElemAttrTokenMap()
             { XML_NAMESPACE_NUMBER, XML_ZEROS_NUMERATOR_DIGITS,  XML_TOK_ELEM_ATTR_ZEROS_NUMERATOR_DIGITS },
             { XML_NAMESPACE_LO_EXT, XML_ZEROS_DENOMINATOR_DIGITS,XML_TOK_ELEM_ATTR_ZEROS_DENOMINATOR_DIGITS },
             { XML_NAMESPACE_NUMBER, XML_ZEROS_DENOMINATOR_DIGITS,XML_TOK_ELEM_ATTR_ZEROS_DENOMINATOR_DIGITS },
+            { XML_NAMESPACE_LO_EXT, XML_INTEGER_FRACTION_DELIMITER, XML_TOK_ELEM_ATTR_INTEGER_FRACTION_DELIMITER },
+            { XML_NAMESPACE_NUMBER, XML_INTEGER_FRACTION_DELIMITER, XML_TOK_ELEM_ATTR_INTEGER_FRACTION_DELIMITER },
             { XML_NAMESPACE_NUMBER, XML_RFC_LANGUAGE_TAG,        XML_TOK_ELEM_ATTR_RFC_LANGUAGE_TAG     },
             { XML_NAMESPACE_NUMBER, XML_LANGUAGE,                XML_TOK_ELEM_ATTR_LANGUAGE             },
             { XML_NAMESPACE_NUMBER, XML_SCRIPT,                  XML_TOK_ELEM_ATTR_SCRIPT               },
@@ -1019,6 +1023,9 @@ SvXMLNumFmtElementContext::SvXMLNumFmtElementContext( SvXMLImport& rImport,
             case XML_TOK_ELEM_ATTR_ZEROS_DENOMINATOR_DIGITS:
                 if (::sax::Converter::convertNumber( nAttrVal, sValue, 0 ))
                     aNumInfo.nZerosDenomDigits = nAttrVal;
+                 break;
+            case XML_TOK_ELEM_ATTR_INTEGER_FRACTION_DELIMITER:
+                aNumInfo.aIntegerFractionDelimiter = sValue;
                 break;
             case XML_TOK_ELEM_ATTR_RFC_LANGUAGE_TAG:
                 aLanguageTagODF.maRfcLanguageTag = sValue;
@@ -1091,6 +1098,9 @@ SvXMLNumFmtElementContext::SvXMLNumFmtElementContext( SvXMLImport& rImport,
         if ( nElementLang == LANGUAGE_DONTKNOW )
             nElementLang = LANGUAGE_SYSTEM;         //! error handling for unknown locales?
     }
+
+    if ( aNumInfo.aIntegerFractionDelimiter.isEmpty() )
+        aNumInfo.aIntegerFractionDelimiter = " ";
 }
 
 SvXMLNumFmtElementContext::~SvXMLNumFmtElementContext()
@@ -1274,7 +1284,9 @@ void SvXMLNumFmtElementContext::EndElement()
                     // add integer part only if min-integer-digits attribute is there
                     aNumInfo.nDecimals = 0;
                     rParent.AddNumber( aNumInfo );      // number without decimals
-                    rParent.AddToCode( ' ' );
+                    OUStringBuffer sIntegerFractionDelimiter = aNumInfo.aIntegerFractionDelimiter;
+                    lcl_EnquoteIfNecessary( sIntegerFractionDelimiter, rParent );
+                    rParent.AddToCode( sIntegerFractionDelimiter.makeStringAndClear() ); // default is ' '
                 }
 
                 //! build string and add at once


More information about the Libreoffice-commits mailing list