summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-03-03 09:27:01 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-04-02 09:06:03 +0200
commit2d86cf3155e1b09a758474517dceae8ee3a199ac (patch)
tree66a6e09b4f1733b25535811872f55989afca3793
parentcb1a5aa51adfebe6ca5e0d39a3ed84daf8d6dd39 (diff)
sw padded numbering: add layout
lcl_formatArabicZero() looks a bit over-complicated with its hardcoded limit of 2. Word supports limits of 3, 4 and 5 as well, so prepare for handling them in a generic way. (cherry picked from commit 642b7706101a991efc7e312f59dece640d8bfb60) Change-Id: If6e5634b11616f0ac05e1387016e22f4b171bbfb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91501 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk44
-rw-r--r--i18npool/Module_i18npool.mk1
-rw-r--r--i18npool/qa/cppunit/test_defaultnumberingprovider.cxx57
-rw-r--r--i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx28
4 files changed, 130 insertions, 0 deletions
diff --git a/i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk b/i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk
new file mode 100644
index 000000000000..421affb90b35
--- /dev/null
+++ b/i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk
@@ -0,0 +1,44 @@
+# -*- 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_CppunitTest_CppunitTest,i18npool_defaultnumberingprovider))
+
+$(eval $(call gb_CppunitTest_use_externals,i18npool_defaultnumberingprovider,\
+ boost_headers \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,i18npool_defaultnumberingprovider, \
+ i18npool/qa/cppunit/test_defaultnumberingprovider \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,i18npool_defaultnumberingprovider, \
+ comphelper \
+ cppu \
+ sal \
+ test \
+ unotest \
+ utl \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,i18npool_defaultnumberingprovider))
+
+$(eval $(call gb_CppunitTest_use_ure,i18npool_defaultnumberingprovider))
+$(eval $(call gb_CppunitTest_use_vcl,i18npool_defaultnumberingprovider))
+
+$(eval $(call gb_CppunitTest_use_rdb,i18npool_defaultnumberingprovider,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,i18npool_defaultnumberingprovider,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,i18npool_defaultnumberingprovider))
+
+# vim: set noet sw=4 ts=4:
diff --git a/i18npool/Module_i18npool.mk b/i18npool/Module_i18npool.mk
index 0e1f5e6cef72..8a770bb4f0e3 100644
--- a/i18npool/Module_i18npool.mk
+++ b/i18npool/Module_i18npool.mk
@@ -43,6 +43,7 @@ $(eval $(call gb_Module_add_check_targets,i18npool,\
CppunitTest_i18npool_test_characterclassification \
CppunitTest_i18npool_test_ordinalsuffix \
CppunitTest_i18npool_test_textsearch \
+ CppunitTest_i18npool_defaultnumberingprovider \
))
# vim: set noet sw=4 ts=4:
diff --git a/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx b/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx
new file mode 100644
index 000000000000..2a1cb55502e2
--- /dev/null
+++ b/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx
@@ -0,0 +1,57 @@
+/* -*- 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/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+
+#include <com/sun/star/style/NumberingType.hpp>
+#include <com/sun/star/text/DefaultNumberingProvider.hpp>
+#include <com/sun/star/text/XNumberingFormatter.hpp>
+
+#include <comphelper/processfactory.hxx>
+#include <comphelper/propertyvalue.hxx>
+
+using namespace ::com::sun::star;
+
+/// i18npool defaultnumberingprovider tests.
+class I18npoolDefaultnumberingproviderTest : public test::BootstrapFixture
+{
+};
+
+CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest, testArabicZero)
+{
+ uno::Reference<uno::XComponentContext> xComponentContext
+ = comphelper::getComponentContext(getMultiServiceFactory());
+
+ // 1 -> "01"
+ uno::Reference<text::XNumberingFormatter> xFormatter(
+ text::DefaultNumberingProvider::create(xComponentContext), uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aProperties = {
+ comphelper::makePropertyValue("NumberingType",
+ static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO)),
+ comphelper::makePropertyValue("Value", static_cast<sal_Int32>(1)),
+ };
+ lang::Locale aLocale;
+ OUString aActual = xFormatter->makeNumberingString(aProperties, aLocale);
+ // Without the accompanying fix in place, this test would have failed with a
+ // lang.IllegalArgumentException, support for ARABIC_ZERO was missing.
+ CPPUNIT_ASSERT_EQUAL(OUString("01"), aActual);
+
+ // 10 -> "10"
+ aProperties = {
+ comphelper::makePropertyValue("NumberingType",
+ static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO)),
+ comphelper::makePropertyValue("Value", static_cast<sal_Int32>(10)),
+ };
+ aActual = xFormatter->makeNumberingString(aProperties, aLocale);
+ CPPUNIT_ASSERT_EQUAL(OUString("10"), aActual);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
index b7963de5c0b5..692289920eff 100644
--- a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
+++ b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
@@ -555,6 +555,30 @@ bool should_ignore( const OUString& s )
return s == " " || (!s.isEmpty() && s[0]==0);
}
+/**
+ * Turn nNumber into a string and pad the result to 2 using zero characters.
+ */
+static OUString lcl_formatArabicZero(sal_Int32 nNumber)
+{
+ sal_Int32 nLimit = 2;
+ OUString aRet = OUString::number(nNumber);
+ sal_Int32 nDiff = nLimit - aRet.getLength();
+
+ if (nDiff <= 0)
+ {
+ return aRet;
+ }
+
+ OUStringBuffer aBuffer;
+ aBuffer.setLength(nDiff);
+ for (sal_Int32 i = 0; i < nDiff; ++i)
+ {
+ aBuffer[i] = '0';
+ }
+ aBuffer.append(aRet);
+ return aBuffer.makeStringAndClear();
+}
+
static
Any getPropertyByName( const Sequence<beans::PropertyValue>& aProperties,
const char* name, bool bRequired )
@@ -915,6 +939,10 @@ DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyVal
lcl_formatChars1( table_Chicago, 4, number-1, result ); // *, +, |, S, **, ++, ...
break;
+ case ARABIC_ZERO:
+ result += lcl_formatArabicZero(number);
+ break;
+
default:
OSL_ASSERT(false);
throw IllegalArgumentException();