summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2018-05-30 17:28:17 +0200
committerEike Rathke <erack@redhat.com>2018-06-11 22:59:23 +0200
commitecad621f6889e8af23baa4faee62d10f580ec074 (patch)
treeadcc0b02a45ebb26c5a2351566acc67e26018c55
parent90385c35cc6bea312eedeea2de33529e76cd6f2a (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> (cherry picked from commit 32f1c56d8ff5e6f87dbcf086fd3743d6d36182bc) Reviewed-on: https://gerrit.libreoffice.org/55625 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: László Németh <nemeth@numbertext.org>
-rw-r--r--i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx5
-rw-r--r--i18npool/source/nativenumber/nativenumbersupplier.cxx9
-rw-r--r--include/svl/zformat.hxx2
-rw-r--r--include/xmloff/xmltoken.hxx3
-rw-r--r--offapi/UnoApi_offapi.mk1
-rw-r--r--offapi/com/sun/star/i18n/NativeNumberXmlAttributes2.idl62
-rw-r--r--svl/source/numbers/zformat.cxx15
-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
11 files changed, 142 insertions, 26 deletions
diff --git a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
index 45a222ce9efd..d363407c19fe 100644
--- a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
+++ b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
@@ -642,12 +642,13 @@ DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyVal
locale = aLocale;
bCapitalize = true;
break;
- case TEXT_CARDINAL: // cardinal number names (one, two, three, ...)
+ case TEXT_CARDINAL: // cardinal number names (One, Two, Three, ...)
natNum = NativeNumberMode::NATNUM12;
+ sNatNumParams = "cardinal";
locale = aLocale;
bCapitalize = true;
break;
- case TEXT_ORDINAL: // ordinal number names (first, second, third, ...)
+ case TEXT_ORDINAL: // ordinal number names (First, Second, Third, ...)
natNum = NativeNumberMode::NATNUM12;
sNatNumParams = "ordinal";
locale = aLocale;
diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx b/i18npool/source/nativenumber/nativenumbersupplier.cxx
index 0de111165adc..a18d8c7c798a 100644
--- a/i18npool/source/nativenumber/nativenumbersupplier.cxx
+++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx
@@ -598,9 +598,10 @@ OUString getNumberText(const Locale& rLocale, const OUString& rNumberString,
static auto xNumberText
= css::linguistic2::NumberText::create(comphelper::getProcessComponentContext());
- OUString numbertext_prefix = sNumberTextParams;
- if (!numbertext_prefix.isEmpty())
- numbertext_prefix += " ";
+ OUString numbertext_prefix;
+ // default "cardinal" gets empty prefix
+ if (sNumberTextParams != "cardinal")
+ numbertext_prefix = sNumberTextParams + " ";
// Several hundreds of headings could result typing lags because
// of the continuous update of the multiple number names during typing.
// We fix this by buffering the result of the conversion.
@@ -777,7 +778,7 @@ sal_Bool SAL_CALL NativeNumberSupplierService::isValidNatNum( const Locale& rLoc
switch (nNativeNumberMode) {
case NativeNumberMode::NATNUM0: // Ascii
case NativeNumberMode::NATNUM3: // Char, FullWidth
- case NativeNumberMode::NATNUM12: // Spell number
+ case NativeNumberMode::NATNUM12: // spell out numbers, dates and money amounts
return true;
case NativeNumberMode::NATNUM1: // Char, Lower
return (langnum >= 0);
diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx
index 92a8080e3383..59c3a293d5b3 100644
--- a/include/svl/zformat.hxx
+++ b/include/svl/zformat.hxx
@@ -24,6 +24,7 @@
#include <svl/zforlist.hxx>
#include <svl/nfkeytab.hxx>
#include <vector>
+#include <com/sun/star/i18n/NativeNumberXmlAttributes2.hpp>
namespace utl {
class DigitGroupingIterator;
@@ -436,6 +437,7 @@ public:
// rAttr.Number not empty if NatNum attributes are to be stored
void GetNatNumXml(
css::i18n::NativeNumberXmlAttributes& rAttr,
+ css::i18n::NativeNumberXmlAttributes2& rAttr2,
sal_uInt16 nNumFor ) const;
/** Switches to the first non-"gregorian" calendar, but only if the current
diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
index 6ab3cdd217f5..5a1cd6157887 100644
--- a/include/xmloff/xmltoken.hxx
+++ b/include/xmloff/xmltoken.hxx
@@ -3316,6 +3316,9 @@ namespace xmloff { namespace token {
XML_CREATOR_INITIALS,
+ // tdf#115007
+ XML_TRANSLITERATION_SPELLOUT,
+
XML_TOKEN_END
};
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index bd8932463c12..93a76c5908a2 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -2753,6 +2753,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/i18n,\
MultipleCharsOutputException \
NativeNumberMode \
NativeNumberXmlAttributes \
+ NativeNumberXmlAttributes2 \
NumberFormatCode \
NumberFormatIndex \
ParseResult \
diff --git a/offapi/com/sun/star/i18n/NativeNumberXmlAttributes2.idl b/offapi/com/sun/star/i18n/NativeNumberXmlAttributes2.idl
new file mode 100644
index 000000000000..34dbc9cc6e1d
--- /dev/null
+++ b/offapi/com/sun/star/i18n/NativeNumberXmlAttributes2.idl
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef __com_sun_star_i18n_NativeNumberXmlAttributes_idl__
+#define __com_sun_star_i18n_NativeNumberXmlAttributes_idl__
+
+#include <com/sun/star/lang/Locale.idl>
+
+
+module com { module sun { module star { module i18n {
+
+
+/**
+ Attributes describing a native number mode for a specific locale,
+ stored in XML file format.
+
+ <p> Used later with
+ XNativeNumberSupplier2::convertToXmlAttributes() and
+ XNativeNumberSupplier2::convertFromXmlAttributes()
+ </p>
+
+ @since LibreOffice 6.1
+
+ @internal
+
+ ATTENTION: This service 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
+{
+ /// 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;
+
+};
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index c9bcf82a88c6..02ac08c7dfc5 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -952,8 +952,11 @@ SvNumberformat::SvNumberformat(OUString& rString,
}
sStr = "NatNum" + OUString::number(nNum);
NumFor[nIndex].SetNatNumNum( nNum, false );
- if (!sParams.isEmpty())
+ // NatNum12 supports arguments
+ if (nNum == 12)
{
+ if (sParams.isEmpty())
+ sParams = "cardinal"; // default NatNum12 format is "cardinal"
NumFor[nIndex].SetNatNumParams(sParams);
sStr += " " + sParams;
}
@@ -5390,6 +5393,7 @@ void SvNumberformat::impTransliterateImpl(OUStringBuffer& rStr,
}
void SvNumberformat::GetNatNumXml( css::i18n::NativeNumberXmlAttributes& rAttr,
+ css::i18n::NativeNumberXmlAttributes2& rAttr2,
sal_uInt16 nNumFor ) const
{
if ( nNumFor <= 3 )
@@ -5399,8 +5403,15 @@ void SvNumberformat::GetNatNumXml( css::i18n::NativeNumberXmlAttributes& rAttr,
{
css::lang::Locale aLocale(
LanguageTag( rNum.GetLang() ).getLocale() );
- rAttr = GetFormatter().GetNatNum()->convertToXmlAttributes(
+
+ 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() );
+ }
}
else
{
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 037d38c2d15a..63cb90af60a8 100644
--- a/xmloff/source/style/xmlnumfi.cxx
+++ b/xmloff/source/style/xmlnumfi.cxx
@@ -246,7 +246,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
@@ -524,6 +525,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
};
@@ -1395,6 +1398,7 @@ SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport,
{
LanguageTagODF aLanguageTagODF;
css::i18n::NativeNumberXmlAttributes aNatNumAttr;
+ OUString aSpellout;
bool bAttrBool(false);
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
@@ -1446,6 +1450,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;
@@ -1465,30 +1472,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