diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2023-10-01 18:08:49 +1100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-12-28 02:33:50 +0100 |
commit | 938d3b35b83093de4e310d32de5137f6bdbcf22b (patch) | |
tree | a50d65c7f47243f3c10f7a093959b4323d5fdc29 /vcl/qa | |
parent | 9157281deb81522bb02af73a08c4d7beed7aab75 (diff) |
vcl: test BreakLinesWithIterator with hyphens
Change-Id: Ied5e688b9eec19c2f1b3d1289cc4a6605703c3e4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157904
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/cppunit/textlayout.cxx | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/vcl/qa/cppunit/textlayout.cxx b/vcl/qa/cppunit/textlayout.cxx index 147826f19842..3ace6a8b836d 100644 --- a/vcl/qa/cppunit/textlayout.cxx +++ b/vcl/qa/cppunit/textlayout.cxx @@ -12,6 +12,8 @@ #include <test/bootstrapfixture.hxx> +#include <comphelper/processfactory.hxx> + #include <vcl/unohelp.hxx> #include <vcl/virdev.hxx> @@ -28,7 +30,7 @@ public: #if HAVE_MORE_FONTS -CPPUNIT_TEST_FIXTURE(VclTextLayoutTest, testBreakLinesWithIterator_invalid_softbreak) +CPPUNIT_TEST_FIXTURE(VclTextLayoutTest, testBreakLines_invalid_softbreak) { ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::WITHOUT_ALPHA); device->SetOutputSizePixel(Size(1000, 1000)); @@ -46,9 +48,63 @@ CPPUNIT_TEST_FIXTURE(VclTextLayoutTest, testBreakLinesWithIterator_invalid_softb const auto nTextLen = 13; - CPPUNIT_ASSERT_EQUAL( - static_cast<sal_Int32>(13), - aTextLayout.BreakLinesWithIterator(nTextWidth, sTestStr, xHyph, xBI, false, nTextLen, 15)); + auto[nBreakPos, nLineWidth] + = aTextLayout.BreakLines(nTextWidth, sTestStr, xHyph, xBI, false, nTextWidth, nTextLen, 15); + + const sal_Int32 nExpectedBreakPos = 13; + CPPUNIT_ASSERT_EQUAL(nExpectedBreakPos, nBreakPos); +} + +CPPUNIT_TEST_FIXTURE(VclTextLayoutTest, testBreakLines_hyphens) +{ + 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-moretext"_ustr; + const auto nTextWidth = device->GetTextWidth("textline text-moretex"); + + css::uno::Reference<css::uno::XComponentContext> xContext( + comphelper::getProcessComponentContext()); + css::uno::Reference<css::linguistic2::XLinguServiceManager2> xLinguMgr + = css::linguistic2::LinguServiceManager::create(xContext); + + css::uno::Reference<css::linguistic2::XHyphenator> xHyph = xLinguMgr->getHyphenator(); + css::uno::Reference<css::i18n::XBreakIterator> xBI = vcl::unohelper::CreateBreakIterator(); + + auto[nBreakPos, nLineWidth] + = aTextLayout.BreakLines(nTextWidth, sTestStr, xHyph, xBI, true, nTextWidth, 13, 12); + + const sal_Int32 nExpectedBreakPos = 13; + CPPUNIT_ASSERT_EQUAL(nExpectedBreakPos, nBreakPos); +} + +CPPUNIT_TEST_FIXTURE(VclTextLayoutTest, testBreakLines_hyphen_word_under_two_chars) +{ + 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-moretext"_ustr; + const auto nTextWidth = device->GetTextWidth("te-moretex"); + + css::uno::Reference<css::uno::XComponentContext> xContext( + comphelper::getProcessComponentContext()); + css::uno::Reference<css::linguistic2::XLinguServiceManager2> xLinguMgr + = css::linguistic2::LinguServiceManager::create(xContext); + + css::uno::Reference<css::linguistic2::XHyphenator> xHyph = xLinguMgr->getHyphenator(); + css::uno::Reference<css::i18n::XBreakIterator> xBI = vcl::unohelper::CreateBreakIterator(); + + auto[nBreakPos, nLineWidth] + = aTextLayout.BreakLines(nTextWidth, sTestStr, xHyph, xBI, true, nTextWidth, 2, 10); + + const sal_Int32 nExpectedBreakPos = 2; + CPPUNIT_ASSERT_EQUAL(nExpectedBreakPos, nBreakPos); } #endif |