summaryrefslogtreecommitdiffstats
path: root/lingucomponent
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2018-02-20 11:38:24 +0100
committerLászló Németh <nemeth@numbertext.org>2018-05-03 11:42:20 +0200
commitf1579d3d6c5f5f3a651825e035b93bee7a4f43c6 (patch)
tree302e93db63f5029f521a0dba446e2c7b91d08a10 /lingucomponent
parentRevert "Resolves: tdf#116579 consider both work locale and format locale date... (diff)
downloadcore-f1579d3d6c5f5f3a651825e035b93bee7a4f43c6.tar.gz
core-f1579d3d6c5f5f3a651825e035b93bee7a4f43c6.zip
tdf#117171 support localized number name numbering styles
in page number, chapter and outline numbering in ~30 languages by integrating libnumbertext library. - offapi: add linguistic2::NumberText New NumberingType constants: - ordinal indicators (1st, 2nd, 3rd...) - cardinal number names (One, Two, Three...) - ordinal number names (First, Second, Third...) Note: these numberings are parts of OOXML, too. Plain text files of Libnumbertext's language data are installed in share/numbertext (similar to share/fingerprint), allowing further customization. Change-Id: I4034da0a40a8c926f14a3f591749a89a8d807d5a Reviewed-on: https://gerrit.libreoffice.org/53313 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'lingucomponent')
-rw-r--r--lingucomponent/Library_numbertext.mk34
-rw-r--r--lingucomponent/Module_lingucomponent.mk1
-rw-r--r--lingucomponent/source/numbertext/numbertext.component25
-rw-r--r--lingucomponent/source/numbertext/numbertext.cxx207
4 files changed, 267 insertions, 0 deletions
diff --git a/lingucomponent/Library_numbertext.mk b/lingucomponent/Library_numbertext.mk
new file mode 100644
index 000000000000..68c50e209fba
--- /dev/null
+++ b/lingucomponent/Library_numbertext.mk
@@ -0,0 +1,34 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+#
+# 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/.
+#
+
+$(eval $(call gb_Library_Library,numbertext))
+
+$(eval $(call gb_Library_set_componentfile,numbertext,lingucomponent/source/numbertext/numbertext))
+
+$(eval $(call gb_Library_use_externals,numbertext,\
+ libnumbertext \
+))
+
+$(eval $(call gb_Library_use_sdk_api,numbertext))
+
+$(eval $(call gb_Library_use_libraries,numbertext,\
+ cppu \
+ cppuhelper \
+ i18nlangtag \
+ sal \
+ tl \
+ utl \
+))
+
+$(eval $(call gb_Library_add_exception_objects,numbertext,\
+ lingucomponent/source/numbertext/numbertext \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/lingucomponent/Module_lingucomponent.mk b/lingucomponent/Module_lingucomponent.mk
index 92d582cc346a..4f3d2424f992 100644
--- a/lingucomponent/Module_lingucomponent.mk
+++ b/lingucomponent/Module_lingucomponent.mk
@@ -17,6 +17,7 @@ $(eval $(call gb_Module_add_targets,lingucomponent,\
$(if $(filter MACOSX,$(OS)),Library_MacOSXSpell) \
Library_spell \
StaticLibrary_ulingu \
+ Library_numbertext \
))
# vim: set noet sw=4 ts=4:
diff --git a/lingucomponent/source/numbertext/numbertext.component b/lingucomponent/source/numbertext/numbertext.component
new file mode 100644
index 000000000000..b17cc31e0840
--- /dev/null
+++ b/lingucomponent/source/numbertext/numbertext.component
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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 .
+ -->
+
+<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
+ prefix="numbertext" xmlns="http://openoffice.org/2010/uno-components">
+ <implementation name="com.sun.star.lingu2.NumberText">
+ <service name="com.sun.star.linguistic2.NumberText"/>
+ </implementation>
+</component>
diff --git a/lingucomponent/source/numbertext/numbertext.cxx b/lingucomponent/source/numbertext/numbertext.cxx
new file mode 100644
index 000000000000..e86278d851f4
--- /dev/null
+++ b/lingucomponent/source/numbertext/numbertext.cxx
@@ -0,0 +1,207 @@
+/* -*- 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 .
+ */
+
+#include <iostream>
+
+#include <osl/file.hxx>
+#include <tools/debug.hxx>
+
+#include <sal/config.h>
+#include <cppuhelper/factory.hxx>
+#include <cppuhelper/implementationentry.hxx>
+#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/supportsservice.hxx>
+
+#include <i18nlangtag/languagetag.hxx>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/linguistic2/XNumberText.hpp>
+#include <unotools/pathoptions.hxx>
+#include <osl/thread.h>
+
+#include <sal/macros.h>
+
+#ifdef SYSTEM_LIBNUMBERTEXT
+#include <libnumbertext/Numbertext.hxx>
+#else
+#ifdef ENABLE_LIBNUMBERTEXT
+#include <Numbertext.hxx>
+#endif
+#endif
+
+using namespace ::osl;
+using namespace ::cppu;
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::linguistic2;
+
+#define SERVICENAME "com.sun.star.linguistic2.NumberText"
+#define IMPLNAME "com.sun.star.lingu2.NumberText"
+
+static Sequence<OUString> getSupportedServiceNames_NumberText_Impl()
+{
+ Sequence<OUString> names{ SERVICENAME };
+ return names;
+}
+
+static OUString getImplementationName_NumberText_Impl() { return OUString(IMPLNAME); }
+
+static osl::Mutex& GetNumberTextMutex()
+{
+ static osl::Mutex aMutex;
+ return aMutex;
+}
+
+class NumberText_Impl : public ::cppu::WeakImplHelper<XNumberText, XServiceInfo>
+{
+#if defined(ENABLE_LIBNUMBERTEXT) || defined(SYSTEM_LIBNUMBERTEXT)
+ Numbertext m_aNumberText;
+#endif
+ bool m_bInitialized;
+
+ virtual ~NumberText_Impl() override {}
+ void EnsureInitialized();
+
+public:
+ NumberText_Impl();
+ NumberText_Impl(const NumberText_Impl&) = delete;
+ NumberText_Impl& operator=(const NumberText_Impl&) = delete;
+
+ // XServiceInfo implementation
+ virtual OUString SAL_CALL getImplementationName() override;
+ virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
+ virtual Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
+ static Sequence<OUString> getSupportedServiceNames_Static();
+
+ // XNumberText implementation
+ virtual OUString SAL_CALL getNumberText(const OUString& aText,
+ const ::css::lang::Locale& rLocale) override;
+ virtual css::uno::Sequence<css::lang::Locale> SAL_CALL getAvailableLanguages() override;
+};
+
+NumberText_Impl::NumberText_Impl()
+ : m_bInitialized(false)
+{
+}
+
+void NumberText_Impl::EnsureInitialized()
+{
+ if (!m_bInitialized)
+ {
+ // set this to true at the very start to prevent loops because of
+ // implicitly called functions below
+ m_bInitialized = true;
+
+ // set default numbertext path to where those get installed
+ OUString aPhysPath;
+ OUString aURL(SvtPathOptions().GetNumbertextPath());
+ osl::FileBase::getSystemPathFromFileURL(aURL, aPhysPath);
+#ifdef _WIN32
+ aPhysPath += "\\";
+#else
+ aPhysPath += "/";
+#endif
+#if defined(ENABLE_LIBNUMBERTEXT) || defined(SYSTEM_LIBNUMBERTEXT)
+ OString path = OUStringToOString(aPhysPath, osl_getThreadTextEncoding());
+ m_aNumberText.set_prefix(path.getStr());
+#endif
+ }
+}
+
+OUString SAL_CALL NumberText_Impl::getNumberText(const OUString& rText, const Locale&
+#if defined(ENABLE_LIBNUMBERTEXT) || defined(SYSTEM_LIBNUMBERTEXT)
+ rLocale)
+#else
+)
+#endif
+{
+ osl::MutexGuard aGuard(GetNumberTextMutex());
+ EnsureInitialized();
+#if defined(ENABLE_LIBNUMBERTEXT) || defined(SYSTEM_LIBNUMBERTEXT)
+ // libnumbertext supports Language + Country tags (separated by "_" or "-")
+ LanguageTag aLanguageTag(rLocale);
+ OUString aCode(aLanguageTag.getLanguage());
+ OUString aCountry(aLanguageTag.getCountry());
+ if (!aCountry.isEmpty())
+ aCode += "-" + aCountry;
+ OString aLangCode(OUStringToOString(aCode, RTL_TEXTENCODING_ASCII_US));
+ OString aInput(OUStringToOString(rText, RTL_TEXTENCODING_UTF8));
+ std::wstring aResult = m_aNumberText.string2wstring(aInput.getStr());
+ bool result = m_aNumberText.numbertext(aResult, aLangCode.getStr());
+ DBG_ASSERT(result, "numbertext: false");
+ OString aResult2(m_aNumberText.wstring2string(aResult).c_str());
+ return OUString::fromUtf8(aResult2);
+#else
+ return rText;
+#endif
+}
+
+uno::Sequence<Locale> SAL_CALL NumberText_Impl::getAvailableLanguages()
+{
+ osl::MutexGuard aGuard(GetNumberTextMutex());
+ // TODO
+ Sequence<css::lang::Locale> aRes;
+ return aRes;
+}
+
+OUString SAL_CALL NumberText_Impl::getImplementationName() { return OUString(IMPLNAME); }
+
+sal_Bool SAL_CALL NumberText_Impl::supportsService(const OUString& ServiceName)
+{
+ return cppu::supportsService(this, ServiceName);
+}
+
+Sequence<OUString> SAL_CALL NumberText_Impl::getSupportedServiceNames()
+{
+ return getSupportedServiceNames_Static();
+}
+
+Sequence<OUString> NumberText_Impl::getSupportedServiceNames_Static()
+{
+ OUString aName(SERVICENAME);
+ return Sequence<OUString>(&aName, 1);
+}
+
+/**
+ * Function to create a new component instance; is needed by factory helper implementation.
+ * @param xMgr service manager to if the components needs other component instances
+ */
+Reference<XInterface> NumberText_Impl_create(Reference<XComponentContext> const&)
+{
+ return static_cast<::cppu::OWeakObject*>(new NumberText_Impl);
+}
+
+//#### EXPORTED ### functions to allow for registration and creation of the UNO component
+static const struct ::cppu::ImplementationEntry s_component_entries[]
+ = { { NumberText_Impl_create, getImplementationName_NumberText_Impl,
+ getSupportedServiceNames_NumberText_Impl, ::cppu::createSingleComponentFactory, nullptr,
+ 0 },
+ { nullptr, nullptr, nullptr, nullptr, nullptr, 0 } };
+
+extern "C" {
+
+SAL_DLLPUBLIC_EXPORT void* numbertext_component_getFactory(sal_Char const* implName, void* xMgr,
+ void* xRegistry)
+{
+ return ::cppu::component_getFactoryHelper(implName, xMgr, xRegistry, s_component_entries);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */