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. Change-Id: If6e5634b11616f0ac05e1387016e22f4b171bbfb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89864 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
This commit is contained in:
parent
b23183af90
commit
642b770610
4 changed files with 126 additions and 0 deletions
44
i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk
Normal file
44
i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk
Normal file
|
@ -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:
|
|
@ -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:
|
||||
|
|
53
i18npool/qa/cppunit/test_defaultnumberingprovider.cxx
Normal file
53
i18npool/qa/cppunit/test_defaultnumberingprovider.cxx
Normal file
|
@ -0,0 +1,53 @@
|
|||
/* -*- 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/propertyvalue.hxx>
|
||||
|
||||
using namespace ::com::sun::star;
|
||||
|
||||
/// i18npool defaultnumberingprovider tests.
|
||||
class I18npoolDefaultnumberingproviderTest : public test::BootstrapFixture
|
||||
{
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest, testArabicZero)
|
||||
{
|
||||
// 1 -> "01"
|
||||
uno::Reference<text::XNumberingFormatter> xFormatter(
|
||||
text::DefaultNumberingProvider::create(mxComponentContext), 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: */
|
|
@ -552,6 +552,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 )
|
||||
|
@ -913,6 +937,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();
|
||||
|
|
Loading…
Reference in a new issue