diff options
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/CppunitTest_vcl_textlayout.mk | 64 | ||||
-rw-r--r-- | vcl/Module_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/inc/textlayout.hxx | 4 | ||||
-rw-r--r-- | vcl/qa/cppunit/text.cxx | 15 | ||||
-rw-r--r-- | vcl/qa/cppunit/textlayout.cxx | 58 |
5 files changed, 140 insertions, 2 deletions
diff --git a/vcl/CppunitTest_vcl_textlayout.mk b/vcl/CppunitTest_vcl_textlayout.mk new file mode 100644 index 000000000000..d7ac49a9e6df --- /dev/null +++ b/vcl/CppunitTest_vcl_textlayout.mk @@ -0,0 +1,64 @@ +# -*- 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,vcl_textlayout)) + +$(eval $(call gb_CppunitTest_set_include,vcl_textlayout,\ + $$(INCLUDE) \ + -I$(SRCDIR)/vcl/inc \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,vcl_textlayout, \ + vcl/qa/cppunit/textlayout \ +)) + +$(eval $(call gb_CppunitTest_use_externals,vcl_textlayout,\ + boost_headers \ + harfbuzz \ +)) + +ifeq ($(SYSTEM_ICU),TRUE) +$(eval $(call gb_CppunitTest_use_externals,vcl_textlayout,\ + icuuc \ +)) +else +$(eval $(call gb_CppunitTest_use_externals,vcl_textlayout,\ + icu_headers \ +)) +endif + +$(eval $(call gb_CppunitTest_use_libraries,vcl_textlayout, \ + comphelper \ + cppu \ + cppuhelper \ + i18nlangtag \ + sal \ + svt \ + test \ + tl \ + unotest \ + vcl \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,vcl_textlayout)) + +$(eval $(call gb_CppunitTest_use_ure,vcl_textlayout)) +$(eval $(call gb_CppunitTest_use_vcl,vcl_textlayout)) + +$(eval $(call gb_CppunitTest_use_components,vcl_textlayout,\ + configmgr/source/configmgr \ + i18npool/util/i18npool \ + ucb/source/core/ucb1 \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,vcl_textlayout)) + +$(eval $(call gb_CppunitTest_use_more_fonts,vcl_textlayout)) + +# vim: set noet sw=4 ts=4: diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk index 19ab27106ad0..cc8667cad420 100644 --- a/vcl/Module_vcl.mk +++ b/vcl/Module_vcl.mk @@ -224,6 +224,7 @@ $(eval $(call gb_Module_add_check_targets,vcl,\ CppunitTest_vcl_fontfeature \ CppunitTest_vcl_fontmetric \ CppunitTest_vcl_text \ + CppunitTest_vcl_textlayout \ CppunitTest_vcl_filters_test \ CppunitTest_vcl_mnemonic \ CppunitTest_vcl_outdev \ diff --git a/vcl/inc/textlayout.hxx b/vcl/inc/textlayout.hxx index e90a7ec05858..58f3bb33469b 100644 --- a/vcl/inc/textlayout.hxx +++ b/vcl/inc/textlayout.hxx @@ -47,7 +47,7 @@ namespace vcl ~ITextLayout() COVERITY_NOEXCEPT_FALSE {} }; - class TextLayoutCommon : public ITextLayout + class VCL_DLLPUBLIC TextLayoutCommon : public ITextLayout { public: OUString GetEllipsisString(OUString const& rOrigStr, tools::Long nMaxWidth, DrawTextFlags nStyle); @@ -75,7 +75,7 @@ namespace vcl /** is an implementation of the ITextLayout interface which simply delegates its calls to the respective methods of an OutputDevice instance, without any inbetween magic. */ - class DefaultTextLayout final : public TextLayoutCommon + class VCL_DLLPUBLIC DefaultTextLayout final : public TextLayoutCommon { public: DefaultTextLayout( OutputDevice& _rTargetDevice ) diff --git a/vcl/qa/cppunit/text.cxx b/vcl/qa/cppunit/text.cxx index cabe502db462..371783759b65 100644 --- a/vcl/qa/cppunit/text.cxx +++ b/vcl/qa/cppunit/text.cxx @@ -719,6 +719,21 @@ CPPUNIT_TEST_FIXTURE(VclTextTest, testGetStringWithNewsEllpsis) device->GetEllipsisString(u"ab. cde. x y z"_ustr, 50, DrawTextFlags::NewsEllipsis)); } +CPPUNIT_TEST_FIXTURE(VclTextTest, testGetTextBreak_invalid_index) +{ + ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::WITHOUT_ALPHA); + device->SetOutputSizePixel(Size(1000, 1000)); + device->SetFont(vcl::Font("DejaVu Sans", "Book", Size(0, 11))); + + const OUString sTestStr(u"textline_ text_"_ustr); + const auto nLen = sTestStr.getLength(); + const auto nTextWidth = device->GetTextWidth("text"); + const auto nInvalidIndex = sTestStr.getLength() + 2; + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), + device->GetTextBreak(sTestStr, nTextWidth, nInvalidIndex, nLen)); +} + CPPUNIT_TEST_FIXTURE(VclTextTest, testGetTextBreak) { ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::WITHOUT_ALPHA); diff --git a/vcl/qa/cppunit/textlayout.cxx b/vcl/qa/cppunit/textlayout.cxx new file mode 100644 index 000000000000..147826f19842 --- /dev/null +++ b/vcl/qa/cppunit/textlayout.cxx @@ -0,0 +1,58 @@ +/* -*- 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 <config_features.h> +#include <config_fonts.h> + +#include <test/bootstrapfixture.hxx> + +#include <vcl/unohelp.hxx> +#include <vcl/virdev.hxx> + +#include <textlayout.hxx> + +class VclTextLayoutTest : public test::BootstrapFixture +{ +public: + VclTextLayoutTest() + : BootstrapFixture(true, false) + { + } +}; + +#if HAVE_MORE_FONTS + +CPPUNIT_TEST_FIXTURE(VclTextLayoutTest, testBreakLinesWithIterator_invalid_softbreak) +{ + ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::WITHOUT_ALPHA); + device->SetOutputSizePixel(Size(1000, 1000)); + device->SetFont(vcl::Font("DejaVu Sans", "Book", Size(0, 11))); + + vcl::DefaultTextLayout aTextLayout(*device); + + const OUString sTestStr = u"textline_ text_"_ustr; + const auto nTextWidth = device->GetTextWidth("text"); + + css::uno::Reference<css::linguistic2::XHyphenator> xHyph; + css::uno::Reference<css::i18n::XBreakIterator> xBI = vcl::unohelper::CreateBreakIterator(); + + // softbreak cannot be greater than the string length + + const auto nTextLen = 13; + + CPPUNIT_ASSERT_EQUAL( + static_cast<sal_Int32>(13), + aTextLayout.BreakLinesWithIterator(nTextWidth, sTestStr, xHyph, xBI, false, nTextLen, 15)); +} + +#endif + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |