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

Laurent Balland-Poirier laurent.balland-poirier at laposte.net
Wed Jul 27 11:04:30 UTC 2016


 include/xmloff/xmltoken.hxx      |    2 +
 xmloff/source/core/xmltoken.cxx  |    2 +
 xmloff/source/style/xmlnumfe.cxx |   18 +++++++++++++++-
 xmloff/source/style/xmlnumfi.cxx |   42 +++++++++++++++++++++++++++++++++++----
 4 files changed, 59 insertions(+), 5 deletions(-)

New commits:
commit aab21302fa7ec76772456ad0cd8729a16e2a11e0
Author: Laurent Balland-Poirier <laurent.balland-poirier at laposte.net>
Date:   Sun Jul 17 11:06:41 2016 +0200

    tdf#100755 Extend ODF to allow 0 in fraction
    
    As '0' is now allowed in numerator/denominator
    this commit extend ODF to save/load this format
    
    Change-Id: I3bc897dcce5393453acd7a434a21ae305feeb919
    Reviewed-on: https://gerrit.libreoffice.org/27263
    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/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
index 5b0902d..aa462c3 100644
--- a/include/xmloff/xmltoken.hxx
+++ b/include/xmloff/xmltoken.hxx
@@ -3269,6 +3269,8 @@ namespace xmloff { namespace token {
         XML_MIN_DECIMAL_PLACES,
         XML_MAX_DENOMINATOR_VALUE,
         XML_MAX_NUMERATOR_DIGITS,
+        XML_ZEROS_NUMERATOR_DIGITS,
+        XML_ZEROS_DENOMINATOR_DIGITS,
 
         XML_TOKEN_END
     };
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index fe35e33..6f7caaa 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -3265,6 +3265,8 @@ namespace xmloff { namespace token {
         TOKEN( "min-decimal-places",              XML_MIN_DECIMAL_PLACES ),
         TOKEN( "max-denominator-value",           XML_MAX_DENOMINATOR_VALUE ),
         TOKEN( "max-numerator-digits",            XML_MAX_NUMERATOR_DIGITS ),
+        TOKEN( "zeros-numerator-digits",          XML_ZEROS_NUMERATOR_DIGITS ),
+        TOKEN( "zeros-denominator-digits",        XML_ZEROS_DENOMINATOR_DIGITS ),
 
 #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 70ac995..20b416c 100644
--- a/xmloff/source/style/xmlnumfe.cxx
+++ b/xmloff/source/style/xmlnumfe.cxx
@@ -731,18 +731,28 @@ void SvXMLNumFmtExport::WriteFractionElement_Impl(
 {
     FinishTextElement_Impl();
     sal_Int32 nMaxNumeratorDigits = aNumeratorString.getLength();
-    // As '0' cannot (yet) be saved in extended ODF, replace them by '?'
+    // Count '0' as '?'
     sal_Int32 nMinNumeratorDigits = aNumeratorString.replaceAll("0","?").indexOf('?');
+    sal_Int32 nZerosNumeratorDigits = aNumeratorString.indexOf('0');
     if ( nMinNumeratorDigits >= 0 )
         nMinNumeratorDigits = nMaxNumeratorDigits - nMinNumeratorDigits;
     else
         nMinNumeratorDigits = 0;
+    if ( nZerosNumeratorDigits >= 0 )
+        nZerosNumeratorDigits = nMaxNumeratorDigits - nZerosNumeratorDigits;
+    else
+        nZerosNumeratorDigits = 0;
     sal_Int32 nMaxDenominatorDigits = aDenominatorString.getLength();
     sal_Int32 nMinDenominatorDigits = aDenominatorString.replaceAll("0","?").indexOf('?');
+    sal_Int32 nZerosDenominatorDigits = aDenominatorString.indexOf('0');
     if ( nMinDenominatorDigits >= 0 )
         nMinDenominatorDigits = nMaxDenominatorDigits - nMinDenominatorDigits;
     else
         nMinDenominatorDigits = 0;
+    if ( nZerosDenominatorDigits >= 0 )
+        nZerosDenominatorDigits = nMaxDenominatorDigits - nZerosDenominatorDigits;
+    else
+        nZerosDenominatorDigits = 0;
     sal_Int32 nDenominator = aDenominatorString.toInt32();
 
     //  integer digits
@@ -771,6 +781,9 @@ void SvXMLNumFmtExport::WriteFractionElement_Impl(
         rExport.AddAttribute( XML_NAMESPACE_LO_EXT, XML_MAX_NUMERATOR_DIGITS,
                               OUString::number( nMaxNumeratorDigits ) );
     }
+    if ( nZerosNumeratorDigits && ((eVersion & SvtSaveOptions::ODFSVER_EXTENDED) != 0) )
+        rExport.AddAttribute( XML_NAMESPACE_LO_EXT, XML_ZEROS_NUMERATOR_DIGITS,
+                              OUString::number( nZerosNumeratorDigits ) );
 
     if ( nDenominator )
     {
@@ -793,6 +806,9 @@ void SvXMLNumFmtExport::WriteFractionElement_Impl(
                                  XML_MAX_DENOMINATOR_VALUE,
                                  OUString::number( pow ( 10.0, nMaxDenominatorDigits ) - 1 ) ); // 9, 99 or 999
         }
+        if ( nZerosDenominatorDigits && ((eVersion & SvtSaveOptions::ODFSVER_EXTENDED) != 0) )
+            rExport.AddAttribute( XML_NAMESPACE_LO_EXT, XML_ZEROS_DENOMINATOR_DIGITS,
+                                  OUString::number( nZerosDenominatorDigits ) );
     }
 
     SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_FRACTION,
diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx
index 7e9c501..c9da66a 100644
--- a/xmloff/source/style/xmlnumfi.cxx
+++ b/xmloff/source/style/xmlnumfi.cxx
@@ -101,6 +101,8 @@ struct SvXMLNumberInfo
     sal_Int32   nMaxDenomDigits;
     sal_Int32   nFracDenominator;
     sal_Int32   nMinDecimalDigits;
+    sal_Int32   nZerosNumerDigits;
+    sal_Int32   nZerosDenomDigits;
     bool        bGrouping;
     bool        bDecReplace;
     bool        bExpSign;
@@ -111,7 +113,7 @@ struct SvXMLNumberInfo
     SvXMLNumberInfo()
     {
         nDecimals = nInteger = nExpDigits = nExpInterval = nMinNumerDigits = nMinDenomDigits = nMaxNumerDigits = nMaxDenomDigits =
-            nFracDenominator = nMinDecimalDigits = -1;
+            nFracDenominator = nMinDecimalDigits = nZerosNumerDigits = nZerosDenomDigits = -1;
         bGrouping = bDecReplace = bDecAlign = false;
         bExpSign = true;
         fDisplayFactor = 1.0;
@@ -266,6 +268,8 @@ enum SvXMLStyleElemAttrTokens
     XML_TOK_ELEM_ATTR_MIN_DENOMINATOR_DIGITS,
     XML_TOK_ELEM_ATTR_MAX_NUMERATOR_DIGITS,
     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_RFC_LANGUAGE_TAG,
     XML_TOK_ELEM_ATTR_LANGUAGE,
     XML_TOK_ELEM_ATTR_SCRIPT,
@@ -569,6 +573,10 @@ const SvXMLTokenMap& SvXMLNumImpData::GetStyleElemAttrTokenMap()
             { XML_NAMESPACE_LO_EXT, XML_MAX_NUMERATOR_DIGITS,    XML_TOK_ELEM_ATTR_MAX_NUMERATOR_DIGITS },
             { XML_NAMESPACE_LO_EXT, XML_MAX_DENOMINATOR_VALUE,   XML_TOK_ELEM_ATTR_MAX_DENOMINATOR_VALUE },
             { XML_NAMESPACE_NUMBER, XML_MAX_DENOMINATOR_VALUE,   XML_TOK_ELEM_ATTR_MAX_DENOMINATOR_VALUE },
+            { XML_NAMESPACE_LO_EXT, XML_ZEROS_NUMERATOR_DIGITS,  XML_TOK_ELEM_ATTR_ZEROS_NUMERATOR_DIGITS },
+            { 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_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               },
@@ -1003,7 +1011,15 @@ SvXMLNumFmtElementContext::SvXMLNumFmtElementContext( SvXMLImport& rImport,
                     aNumInfo.nFracDenominator = nAttrVal;
                     bIsMaxDenominator = true;
                 }
-                 break;
+                break;
+            case XML_TOK_ELEM_ATTR_ZEROS_NUMERATOR_DIGITS:
+                if (::sax::Converter::convertNumber( nAttrVal, sValue, 0 ))
+                    aNumInfo.nZerosNumerDigits = nAttrVal;
+                break;
+            case XML_TOK_ELEM_ATTR_ZEROS_DENOMINATOR_DIGITS:
+                if (::sax::Converter::convertNumber( nAttrVal, sValue, 0 ))
+                    aNumInfo.nZerosDenomDigits = nAttrVal;
+                break;
             case XML_TOK_ELEM_ATTR_RFC_LANGUAGE_TAG:
                 aLanguageTagODF.maRfcLanguageTag = sValue;
                 break;
@@ -1036,9 +1052,23 @@ SvXMLNumFmtElementContext::SvXMLNumFmtElementContext( SvXMLImport& rImport,
         else
             aNumInfo.nMinDecimalDigits = aNumInfo.nDecimals;
     }
+    if ( aNumInfo.nZerosDenomDigits > 0 )
+    {   // nMin = count of '0' and '?'
+        if ( aNumInfo.nMinDenomDigits < aNumInfo.nZerosDenomDigits )
+            aNumInfo.nMinDenomDigits = aNumInfo.nZerosDenomDigits;
+    }
+    else
+        aNumInfo.nZerosDenomDigits = 0;
     if ( aNumInfo.nMinDenomDigits >= 0 )
         if ( aNumInfo.nMaxDenomDigits < aNumInfo.nMinDenomDigits )
             aNumInfo.nMaxDenomDigits = ( aNumInfo.nMinDenomDigits ? aNumInfo.nMinDenomDigits : 1 );
+    if ( aNumInfo.nZerosNumerDigits > 0 )
+    {
+        if ( aNumInfo.nMinNumerDigits < aNumInfo.nZerosNumerDigits )
+            aNumInfo.nMinNumerDigits = aNumInfo.nZerosNumerDigits;
+    }
+    else
+        aNumInfo.nZerosNumerDigits = 0;
     if ( aNumInfo.nMinNumerDigits >= 0 )
         if ( aNumInfo.nMaxNumerDigits < aNumInfo.nMinNumerDigits )
             aNumInfo.nMaxNumerDigits = ( aNumInfo.nMinNumerDigits ? aNumInfo.nMinNumerDigits : 1 );
@@ -1254,8 +1284,10 @@ void SvXMLNumFmtElementContext::EndElement()
                 {
                     if ( i > aNumInfo.nMinNumerDigits )
                         rParent.AddToCode( '#' );
-                    else
+                    else if ( i > aNumInfo.nZerosNumerDigits )
                         rParent.AddToCode( '?' );
+                    else
+                        rParent.AddToCode( '0' );
                 }
                 rParent.AddToCode( '/' );
                 if ( aNumInfo.nFracDenominator > 0 )
@@ -1268,8 +1300,10 @@ void SvXMLNumFmtElementContext::EndElement()
                     {
                         if ( i > aNumInfo.nMinDenomDigits )
                             rParent.AddToCode( '#' );
-                        else
+                        else if ( i > aNumInfo.nZerosDenomDigits )
                             rParent.AddToCode( '?' );
+                        else
+                            rParent.AddToCode( '0' );
                     }
                 }
             }


More information about the Libreoffice-commits mailing list