diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2021-03-07 13:19:55 +1100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-08-28 15:09:12 +0200 |
commit | 9ca9faabd4009698096ccde03c45e9c203804c80 (patch) | |
tree | 458966017e413f5b58ef3fdcd814443f6f5e07e1 | |
parent | 9a58ec3f6f65da27e3b26e1173b6661b743e66a4 (diff) |
vcl: move TextLayoutCache to own module header
Add a unit test for TextLayoutClass - it basically tests that script
runs work as intended.
Change-Id: Ie65acf06f13c89c182d93b20fc9a28866db2330c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115470
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | vcl/CppunitTest_vcl_text.mk | 1 | ||||
-rw-r--r-- | vcl/inc/TextLayoutCache.hxx | 63 | ||||
-rw-r--r-- | vcl/inc/scrptrun.h | 4 | ||||
-rw-r--r-- | vcl/qa/cppunit/text.cxx | 28 | ||||
-rw-r--r-- | vcl/source/gdi/CommonSalLayout.cxx | 59 |
5 files changed, 104 insertions, 51 deletions
diff --git a/vcl/CppunitTest_vcl_text.mk b/vcl/CppunitTest_vcl_text.mk index 0b07e5df02a7..ffc307e094f1 100644 --- a/vcl/CppunitTest_vcl_text.mk +++ b/vcl/CppunitTest_vcl_text.mk @@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,vcl_text, \ $(eval $(call gb_CppunitTest_use_externals,vcl_text,\ boost_headers \ harfbuzz \ + icu_headers \ )) $(eval $(call gb_CppunitTest_use_libraries,vcl_text, \ diff --git a/vcl/inc/TextLayoutCache.hxx b/vcl/inc/TextLayoutCache.hxx new file mode 100644 index 000000000000..0118ba32fed8 --- /dev/null +++ b/vcl/inc/TextLayoutCache.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 . + */ + +#pragma once + +#include <sal/types.h> + +#include <vcl/dllapi.h> + +#include "scrptrun.h" + +#include <hb-icu.h> + +#include <vector> + +namespace vcl +{ +struct Run +{ + int32_t nStart; + int32_t nEnd; + UScriptCode nCode; + Run(int32_t nStart_, int32_t nEnd_, UScriptCode nCode_) + : nStart(nStart_) + , nEnd(nEnd_) + , nCode(nCode_) + { + } +}; + +class TextLayoutCache +{ +public: + std::vector<vcl::Run> runs; + TextLayoutCache(sal_Unicode const* pStr, sal_Int32 const nEnd) + { + vcl::ScriptRun aScriptRun(reinterpret_cast<const UChar*>(pStr), nEnd); + while (aScriptRun.next()) + { + runs.emplace_back(aScriptRun.getScriptStart(), aScriptRun.getScriptEnd(), + aScriptRun.getScriptCode()); + } + } +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/inc/scrptrun.h b/vcl/inc/scrptrun.h index 0d64109b6fe9..d2dee3e155a7 100644 --- a/vcl/inc/scrptrun.h +++ b/vcl/inc/scrptrun.h @@ -39,6 +39,8 @@ #include <sal/config.h> +#include <vcl/dllapi.h> + #include <unicode/uobject.h> #include <unicode/uscript.h> #include <vector> @@ -56,7 +58,7 @@ struct ParenStackEntry } }; -class ScriptRun final : public icu::UObject +class VCL_DLLPUBLIC ScriptRun final : public icu::UObject { public: ScriptRun(const UChar chars[], int32_t length); diff --git a/vcl/qa/cppunit/text.cxx b/vcl/qa/cppunit/text.cxx index 19e5da942932..0db15435a675 100644 --- a/vcl/qa/cppunit/text.cxx +++ b/vcl/qa/cppunit/text.cxx @@ -8,14 +8,16 @@ */ #include <test/bootstrapfixture.hxx> +#include <sal/log.hxx> #include <tools/stream.hxx> + #include <vcl/BitmapReadAccess.hxx> #include <vcl/graphicfilter.hxx> -#include <vcl/virdev.hxx> -#include <vcl/svapp.hxx> #include <vcl/settings.hxx> -#include <sal/log.hxx> +#include <vcl/svapp.hxx> +#include <vcl/virdev.hxx> +#include <TextLayoutCache.hxx> #include <salgdi.hxx> class VclTextTest : public test::BootstrapFixture @@ -42,10 +44,12 @@ public: void testSimpleText(); void testVerticalText(); + void testTextLayoutCache(); CPPUNIT_TEST_SUITE(VclTextTest); CPPUNIT_TEST(testSimpleText); CPPUNIT_TEST(testVerticalText); + CPPUNIT_TEST(testTextLayoutCache); CPPUNIT_TEST_SUITE_END(); }; @@ -375,6 +379,24 @@ void VclTextTest::testVerticalText() CPPUNIT_ASSERT_DOUBLES_EQUAL(width36, width36pct50, 2); } +void VclTextTest::testTextLayoutCache() +{ + OUString sTestString = u"The quick brown fox\n jumped over the lazy dogالعاشر"; + vcl::TextLayoutCache cache(sTestString.getStr(), sTestString.getLength()); + + vcl::Run run1 = cache.runs[0]; + vcl::Run run2 = cache.runs[1]; + + bool bCorrectRuns = (cache.runs.size() == 2); + CPPUNIT_ASSERT_MESSAGE("Wrong number of runs", bCorrectRuns); + CPPUNIT_ASSERT_EQUAL(USCRIPT_LATIN, run1.nCode); + CPPUNIT_ASSERT_EQUAL(0, run1.nStart); + CPPUNIT_ASSERT_EQUAL(45, run1.nEnd); + CPPUNIT_ASSERT_EQUAL(USCRIPT_ARABIC, run2.nCode); + CPPUNIT_ASSERT_EQUAL(45, run2.nStart); + CPPUNIT_ASSERT_EQUAL(51, run2.nEnd); +} + CPPUNIT_TEST_SUITE_REGISTRATION(VclTextTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx index 50ad02843887..4adf864a933b 100644 --- a/vcl/source/gdi/CommonSalLayout.cxx +++ b/vcl/source/gdi/CommonSalLayout.cxx @@ -17,26 +17,26 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include <memory> - -#include <hb-icu.h> -#include <hb-ot.h> -#include <hb-graphite2.h> - -#include <sallayout.hxx> - -#include <o3tl/temporary.hxx> #include <sal/log.hxx> #include <unotools/configmgr.hxx> +#include <o3tl/temporary.hxx> + #include <vcl/unohelp.hxx> #include <vcl/font/Feature.hxx> #include <vcl/font/FeatureParser.hxx> -#include <scrptrun.h> -#include <com/sun/star/i18n/CharacterIteratorMode.hpp> + +#include <TextLayoutCache.hxx> +#include <fontselect.hxx> #include <salgdi.hxx> +#include <sallayout.hxx> + +#include <com/sun/star/i18n/CharacterIteratorMode.hpp> + #include <unicode/uchar.h> +#include <hb-ot.h> +#include <hb-graphite2.h> -#include <fontselect.hxx> +#include <memory> #if !HB_VERSION_ATLEAST(1, 1, 0) // Disabled Unicode compatibility decomposition, see fdo#66715 @@ -93,41 +93,6 @@ struct SubRun } -namespace vcl { - namespace { - - struct Run - { - int32_t nStart; - int32_t nEnd; - UScriptCode nCode; - Run(int32_t nStart_, int32_t nEnd_, UScriptCode nCode_) - : nStart(nStart_) - , nEnd(nEnd_) - , nCode(nCode_) - {} - }; - - } - - class TextLayoutCache - { - public: - std::vector<vcl::Run> runs; - TextLayoutCache(sal_Unicode const* pStr, sal_Int32 const nEnd) - { - vcl::ScriptRun aScriptRun( - reinterpret_cast<const UChar *>(pStr), - nEnd); - while (aScriptRun.next()) - { - runs.emplace_back(aScriptRun.getScriptStart(), - aScriptRun.getScriptEnd(), aScriptRun.getScriptCode()); - } - } - }; -} // namespace vcl - namespace { #if U_ICU_VERSION_MAJOR_NUM >= 63 enum class VerticalOrientation { |