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

Eike Rathke erack at redhat.com
Mon Jun 11 11:05:44 UTC 2018


 include/svl/zformat.hxx                                 |    3 -
 offapi/com/sun/star/i18n/NativeNumberXmlAttributes2.idl |    9 +--
 offapi/com/sun/star/i18n/XNativeNumberSupplier2.idl     |    2 
 svl/source/numbers/zformat.cxx                          |   29 +++++++---
 xmloff/source/style/xmlnumfe.cxx                        |   45 ++++++++++------
 5 files changed, 55 insertions(+), 33 deletions(-)

New commits:
commit 807d4382cb021d2ac3ea99d6757a7b368a32941d
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jun 8 23:44:13 2018 +0200

    Derive NativeNumberXmlAttributes2 from NativeNumberXmlAttributes, tdf#115007 follow-up
    
    Also ensure that transliteration-spellout and
    (transliteration-format,transliteration-style) are mutually
    exclusive and transliteration-spellout is only written if ODF
    version is >1.2, namespace 'loext' for 1.2 with extensions and
    namespace 'number' in anticipation of ODF 1.3 (may need to be
    adapted).
    
    Change-Id: I371dee8883ecb0d4638510c92b4bf59acd09f636
    Reviewed-on: https://gerrit.libreoffice.org/55491
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Eike Rathke <erack at redhat.com>

diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx
index 59c3a293d5b3..6357be2cea9d 100644
--- a/include/svl/zformat.hxx
+++ b/include/svl/zformat.hxx
@@ -436,8 +436,7 @@ public:
 
     // rAttr.Number not empty if NatNum attributes are to be stored
     void GetNatNumXml(
-            css::i18n::NativeNumberXmlAttributes& rAttr,
-            css::i18n::NativeNumberXmlAttributes2& rAttr2,
+            css::i18n::NativeNumberXmlAttributes2& rAttr,
             sal_uInt16 nNumFor ) const;
 
     /** Switches to the first non-"gregorian" calendar, but only if the current
diff --git a/offapi/com/sun/star/i18n/NativeNumberXmlAttributes2.idl b/offapi/com/sun/star/i18n/NativeNumberXmlAttributes2.idl
index 34dbc9cc6e1d..d8c8fb225dd2 100644
--- a/offapi/com/sun/star/i18n/NativeNumberXmlAttributes2.idl
+++ b/offapi/com/sun/star/i18n/NativeNumberXmlAttributes2.idl
@@ -20,7 +20,7 @@
 #ifndef __com_sun_star_i18n_NativeNumberXmlAttributes_idl__
 #define __com_sun_star_i18n_NativeNumberXmlAttributes_idl__
 
-#include <com/sun/star/lang/Locale.idl>
+#include <com/sun/star/i18n/NativeNumberXmlAttributes.idl>
 
 
 module com { module sun { module star { module i18n {
@@ -39,16 +39,13 @@ module com { module sun { module star { module i18n {
 
     @internal
 
-    ATTENTION: This service is marked <em>internal</em> and does not
+    ATTENTION: This struct is marked <em>internal</em> and does not
     have the <em>published</em> flag, which means it is subject to
     change without notice and should not be used outside the LibreOffice core.
  */
 
-struct NativeNumberXmlAttributes2
+struct NativeNumberXmlAttributes2 : com::sun::star::i18n::NativeNumberXmlAttributes
 {
-    /// The locale of the native number representation
-    ::com::sun::star::lang::Locale  Locale;
-
     /** The format of the number string, for example, "cardinal",
         "ordinal" or "ordinal-number". */
     string  Spellout;
diff --git a/offapi/com/sun/star/i18n/XNativeNumberSupplier2.idl b/offapi/com/sun/star/i18n/XNativeNumberSupplier2.idl
index 08c0d37ce663..17a1df082c9f 100644
--- a/offapi/com/sun/star/i18n/XNativeNumberSupplier2.idl
+++ b/offapi/com/sun/star/i18n/XNativeNumberSupplier2.idl
@@ -33,7 +33,7 @@ module com { module sun { module star { module i18n {
 
     @internal
 
-    ATTENTION: This service is marked <em>internal</em> and does not
+    ATTENTION: This interface is marked <em>internal</em> and does not
     have the <em>published</em> flag, which means it is subject to
     change without notice and should not be used outside the LibreOffice core.
  */
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index df789e59ab37..1bc63e4ecfec 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -5392,8 +5392,7 @@ void SvNumberformat::impTransliterateImpl(OUStringBuffer& rStr,
     rStr.append(sTemp);
 }
 
-void SvNumberformat::GetNatNumXml( css::i18n::NativeNumberXmlAttributes& rAttr,
-                                   css::i18n::NativeNumberXmlAttributes2& rAttr2,
+void SvNumberformat::GetNatNumXml( css::i18n::NativeNumberXmlAttributes2& rAttr,
                                    sal_uInt16 nNumFor ) const
 {
     if ( nNumFor <= 3 )
@@ -5404,23 +5403,37 @@ void SvNumberformat::GetNatNumXml( css::i18n::NativeNumberXmlAttributes& rAttr,
             css::lang::Locale aLocale(
                     LanguageTag( rNum.GetLang() ).getLocale() );
 
+            /* TODO: a new XNativeNumberSupplier2::convertToXmlAttributes()
+             * should rather return NativeNumberXmlAttributes2 and places
+             * adapted, and whether to fill Spellout or something different
+             * should be internal there. */
+            css::i18n::NativeNumberXmlAttributes aTmp(
+                    GetFormatter().GetNatNum()->convertToXmlAttributes(
+                        aLocale, rNum.GetNatNum()));
+            rAttr.Locale = aTmp.Locale;
+            rAttr.Format = aTmp.Format;
+            rAttr.Style = aTmp.Style;
             if ( NatNumTakesParameters(rNum.GetNatNum()) )
             {
                 // NatNum12 spell out numbers, dates and money amounts
-                rAttr2 = css::i18n::NativeNumberXmlAttributes2(aLocale, rNum.GetParams());
-            } else {
-                rAttr = GetFormatter().GetNatNum()->convertToXmlAttributes(
-                    aLocale, rNum.GetNatNum() );
+                rAttr.Spellout = rNum.GetParams();
+                // Mutually exclusive.
+                rAttr.Format.clear();
+                rAttr.Style.clear();
+            }
+            else
+            {
+                rAttr.Spellout.clear();
             }
         }
         else
         {
-            rAttr = css::i18n::NativeNumberXmlAttributes();
+            rAttr = css::i18n::NativeNumberXmlAttributes2();
         }
     }
     else
     {
-        rAttr = css::i18n::NativeNumberXmlAttributes();
+        rAttr = css::i18n::NativeNumberXmlAttributes2();
     }
 }
 
diff --git a/xmloff/source/style/xmlnumfe.cxx b/xmloff/source/style/xmlnumfe.cxx
index 56a5d168cb64..7001328ab196 100644
--- a/xmloff/source/style/xmlnumfe.cxx
+++ b/xmloff/source/style/xmlnumfe.cxx
@@ -32,7 +32,6 @@
 #include <tools/color.hxx>
 #include <sax/tools/converter.hxx>
 
-#include <com/sun/star/i18n/NativeNumberXmlAttributes.hpp>
 #include <com/sun/star/i18n/NativeNumberXmlAttributes2.hpp>
 
 #include <xmloff/xmlnumfe.hxx>
@@ -1191,11 +1190,12 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt
     }
 
     // Native number transliteration
-    css::i18n::NativeNumberXmlAttributes aAttr;
-    css::i18n::NativeNumberXmlAttributes2 aAttr2;
-    rFormat.GetNatNumXml( aAttr, aAttr2, nPart );
+    css::i18n::NativeNumberXmlAttributes2 aAttr;
+    rFormat.GetNatNumXml( aAttr, nPart );
     if ( !aAttr.Format.isEmpty() )
     {
+        assert(aAttr.Spellout.isEmpty());   // mutually exclusive
+
         /* FIXME-BCP47: ODF defines no transliteration-script or
          * transliteration-rfc-language-tag */
         LanguageTag aLanguageTag( aAttr.Locale);
@@ -1211,19 +1211,32 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt
                               aAttr.Style );
     }
 
-    if ( !aAttr2.Spellout.isEmpty() )
+    if ( !aAttr.Spellout.isEmpty() )
     {
-        /* FIXME-BCP47: ODF defines no transliteration-script or
-         * transliteration-rfc-language-tag */
-        LanguageTag aLanguageTag( aAttr2.Locale);
-        OUString aLanguage, aScript, aCountry;
-        aLanguageTag.getIsoLanguageScriptCountry( aLanguage, aScript, aCountry);
-        rExport.AddAttribute( XML_NAMESPACE_LO_EXT, XML_TRANSLITERATION_SPELLOUT,
-                              aAttr2.Spellout );
-        rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_LANGUAGE,
-                              aLanguage );
-        rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_COUNTRY,
-                              aCountry );
+        const bool bWriteSpellout = aAttr.Format.isEmpty();
+        assert(bWriteSpellout);     // mutually exclusive
+
+        // Export only for 1.2 with extensions or 1.3 and later.
+        SvtSaveOptions::ODFSaneDefaultVersion eVersion = rExport.getSaneDefaultVersion();
+        // Also ensure that duplicated transliteration-language and
+        // transliteration-country attributes never escape into the wild with
+        // releases.
+        if (eVersion > SvtSaveOptions::ODFSVER_012 && bWriteSpellout)
+        {
+            /* FIXME-BCP47: ODF defines no transliteration-script or
+             * transliteration-rfc-language-tag */
+            LanguageTag aLanguageTag( aAttr.Locale);
+            OUString aLanguage, aScript, aCountry;
+            aLanguageTag.getIsoLanguageScriptCountry( aLanguage, aScript, aCountry);
+            // For 1.2+ use loext namespace, for 1.3 use number namespace.
+            rExport.AddAttribute( ((eVersion < SvtSaveOptions::ODFSVER_013) ?
+                        XML_NAMESPACE_LO_EXT : XML_NAMESPACE_NUMBER),
+                    XML_TRANSLITERATION_SPELLOUT, aAttr.Spellout );
+            rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_LANGUAGE,
+                                  aLanguage );
+            rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_COUNTRY,
+                                  aCountry );
+        }
     }
 
     // The element


More information about the Libreoffice-commits mailing list