Kaydet (Commit) 807d4382 authored tarafından Eike Rathke's avatar Eike Rathke

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/55491Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
üst bada992c
......@@ -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
......
......@@ -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;
......
......@@ -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.
*/
......
......@@ -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();
}
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment