[Libreoffice-commits] core.git: vcl/CppunitTest_vcl_text.mk vcl/inc vcl/qa vcl/source

Chris Sherlock (via logerrit) logerrit at kemper.freedesktop.org
Sat Aug 28 13:09:50 UTC 2021


 vcl/CppunitTest_vcl_text.mk        |    1 
 vcl/inc/TextLayoutCache.hxx        |   63 +++++++++++++++++++++++++++++++++++++
 vcl/inc/scrptrun.h                 |    4 +-
 vcl/qa/cppunit/text.cxx            |   28 ++++++++++++++--
 vcl/source/gdi/CommonSalLayout.cxx |   59 +++++++---------------------------
 5 files changed, 104 insertions(+), 51 deletions(-)

New commits:
commit 9ca9faabd4009698096ccde03c45e9c203804c80
Author:     Chris Sherlock <chris.sherlock79 at gmail.com>
AuthorDate: Sun Mar 7 13:19:55 2021 +1100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sat Aug 28 15:09:12 2021 +0200

    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 at gmail.com>

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 {


More information about the Libreoffice-commits mailing list