summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2018-05-30 17:28:17 +0200
committerLászló Németh <nemeth@numbertext.org>2018-06-08 18:00:20 +0200
commit32f1c56d8ff5e6f87dbcf086fd3743d6d36182bc (patch)
tree47d51358300a5f425fa0bd4b504af0866ab3b0eb /xmloff
parent4328d181b670356c9dbd69f1ec1dedb473b59e8e (diff)
tdf#115007: add import/export to NatNum12 (spell out numbers,
dates and money amounts, supporting all the XNumberText/libnumbertext formatting codes, for example "ordinal", "ordinal-number", "ordinal-feminine", etc., and ISO 4217 currency codes, also their possible combinations. NatNum12 formatting codes are stored by using the newly introduced (yet, loext:)transliteration-spellout attribute. creator-initials also added to token list Change-Id: I20f93c9d16778f142067a56d53b336d0acbe2d92 Reviewed-on: https://gerrit.libreoffice.org/54673 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/core/xmltoken.cxx3
-rw-r--r--xmloff/source/style/xmlnumfe.cxx19
-rw-r--r--xmloff/source/style/xmlnumfi.cxx47
-rw-r--r--xmloff/source/token/tokens.txt2
4 files changed, 53 insertions, 18 deletions
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index 019c0bb19308..d9e221bf34b2 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -3308,6 +3308,9 @@ namespace xmloff { namespace token {
TOKEN( "newline", XML_NEWLINE ),
TOKEN( "creator-initials", XML_CREATOR_INITIALS ),
+ // tdf#115007 spell out numbers, dates, money amounts and cross references
+ TOKEN( "transliteration-spellout", XML_TRANSLITERATION_SPELLOUT ),
+
#if OSL_DEBUG_LEVEL > 0
{ 0, nullptr, nullptr, XML_TOKEN_END }
#else
diff --git a/xmloff/source/style/xmlnumfe.cxx b/xmloff/source/style/xmlnumfe.cxx
index 99366b9800fc..56a5d168cb64 100644
--- a/xmloff/source/style/xmlnumfe.cxx
+++ b/xmloff/source/style/xmlnumfe.cxx
@@ -33,6 +33,7 @@
#include <sax/tools/converter.hxx>
#include <com/sun/star/i18n/NativeNumberXmlAttributes.hpp>
+#include <com/sun/star/i18n/NativeNumberXmlAttributes2.hpp>
#include <xmloff/xmlnumfe.hxx>
#include <xmloff/xmlnmspe.hxx>
@@ -1191,7 +1192,8 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt
// Native number transliteration
css::i18n::NativeNumberXmlAttributes aAttr;
- rFormat.GetNatNumXml( aAttr, nPart );
+ css::i18n::NativeNumberXmlAttributes2 aAttr2;
+ rFormat.GetNatNumXml( aAttr, aAttr2, nPart );
if ( !aAttr.Format.isEmpty() )
{
/* FIXME-BCP47: ODF defines no transliteration-script or
@@ -1209,6 +1211,21 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt
aAttr.Style );
}
+ if ( !aAttr2.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 );
+ }
+
// The element
SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, eType,
true, true );
diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx
index 902e42171420..e611c144f290 100644
--- a/xmloff/source/style/xmlnumfi.cxx
+++ b/xmloff/source/style/xmlnumfi.cxx
@@ -244,7 +244,8 @@ enum SvXMLStyleAttrTokens
XML_TOK_STYLE_ATTR_TRANSL_FORMAT,
XML_TOK_STYLE_ATTR_TRANSL_LANGUAGE,
XML_TOK_STYLE_ATTR_TRANSL_COUNTRY,
- XML_TOK_STYLE_ATTR_TRANSL_STYLE
+ XML_TOK_STYLE_ATTR_TRANSL_STYLE,
+ XML_TOK_STYLE_ATTR_TRANSL_SPELLOUT
};
enum SvXMLStyleElemAttrTokens
@@ -522,6 +523,8 @@ const SvXMLTokenMap& SvXMLNumImpData::GetStyleAttrTokenMap()
// not defined in ODF { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_SCRIPT, XML_TOK_STYLE_ATTR_TRANSL_SCRIPT },
{ XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_COUNTRY, XML_TOK_STYLE_ATTR_TRANSL_COUNTRY },
{ XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_STYLE, XML_TOK_STYLE_ATTR_TRANSL_STYLE },
+ { XML_NAMESPACE_LO_EXT, XML_TRANSLITERATION_SPELLOUT, XML_TOK_STYLE_ATTR_TRANSL_SPELLOUT },
+ { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_SPELLOUT, XML_TOK_STYLE_ATTR_TRANSL_SPELLOUT },
XML_TOKEN_MAP_END
};
@@ -1393,6 +1396,7 @@ SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport,
{
LanguageTagODF aLanguageTagODF;
css::i18n::NativeNumberXmlAttributes aNatNumAttr;
+ OUString aSpellout;
bool bAttrBool(false);
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
@@ -1444,6 +1448,9 @@ SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport,
case XML_TOK_STYLE_ATTR_TRANSL_FORMAT:
aNatNumAttr.Format = sValue;
break;
+ case XML_TOK_STYLE_ATTR_TRANSL_SPELLOUT:
+ aSpellout = sValue;
+ break;
case XML_TOK_STYLE_ATTR_TRANSL_LANGUAGE:
aNatNumAttr.Locale.Language = sValue;
break;
@@ -1463,30 +1470,36 @@ SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport,
nFormatLang = LANGUAGE_SYSTEM; //! error handling for unknown locales?
}
- if ( !aNatNumAttr.Format.isEmpty() )
+ if ( !aNatNumAttr.Format.isEmpty() || !aSpellout.isEmpty() )
{
- SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
- if ( pFormatter )
- {
- LanguageTag aLanguageTag( OUString(), aNatNumAttr.Locale.Language,
+ LanguageTag aLanguageTag( OUString(), aNatNumAttr.Locale.Language,
OUString(), aNatNumAttr.Locale.Country);
- aNatNumAttr.Locale = aLanguageTag.getLocale( false);
+ aNatNumAttr.Locale = aLanguageTag.getLocale( false);
+
+ // NatNum12 spell out formula (cardinal, ordinal, ordinal-feminine etc.)
+ if ( !aSpellout.isEmpty() )
+ {
+ aFormatCode.append( "[NatNum12 " );
+ aFormatCode.append( aSpellout );
+ } else {
+ SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
+ if ( !pFormatter ) return;
sal_Int32 nNatNum = pFormatter->GetNatNum()->convertFromXmlAttributes( aNatNumAttr );
aFormatCode.append( "[NatNum" );
aFormatCode.append( nNatNum );
+ }
- LanguageType eLang = aLanguageTag.getLanguageType( false);
- if ( eLang == LANGUAGE_DONTKNOW )
- eLang = LANGUAGE_SYSTEM; //! error handling for unknown locales?
- if ( eLang != nFormatLang && eLang != LANGUAGE_SYSTEM )
- {
- aFormatCode.append( "][$-" );
- // language code in upper hex:
- aFormatCode.append(OUString::number(static_cast<sal_uInt16>(eLang), 16).toAsciiUpperCase());
- }
- aFormatCode.append( ']' );
+ LanguageType eLang = aLanguageTag.getLanguageType( false );
+ if ( eLang == LANGUAGE_DONTKNOW )
+ eLang = LANGUAGE_SYSTEM; //! error handling for unknown locales?
+ if ( eLang != nFormatLang && eLang != LANGUAGE_SYSTEM )
+ {
+ aFormatCode.append( "][$-" );
+ // language code in upper hex:
+ aFormatCode.append(OUString::number(static_cast<sal_uInt16>(eLang), 16).toAsciiUpperCase());
}
+ aFormatCode.append( ']' );
}
}
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
index 04275393f2bc..095b21a8c46f 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -3079,4 +3079,6 @@ zeros-denominator-digits
integer-fraction-delimiter
reference-language
newline
+creator-initials
+transliteration-spellout
TOKEN_END_DUMMY