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

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Sun Mar 21 15:22:17 UTC 2021


 vcl/qa/cppunit/complextext.cxx     |   55 +++++++++++++++++++++++++++++++++++++
 vcl/source/gdi/CommonSalLayout.cxx |    3 ++
 2 files changed, 58 insertions(+)

New commits:
commit 160ff36d2593a24b6a933332ab5d66683528403c
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Fri Mar 19 19:14:31 2021 +0100
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Sun Mar 21 16:21:35 2021 +0100

    fix SalLayoutGlyphs caching with MultiSalLayout
    
    Writer's testTdf90069 was failing if there was the documents font
    actually installed. If glyphs for layout are cached, it is still
    necessary to do the fallback, and that needs setting the fallback
    as needed.
    
    Change-Id: I32bf453d2e46fd8f1cf53a1298d0bc4195a1b78c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112774
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx
index f953c3060eb4..dae468baadc7 100644
--- a/vcl/qa/cppunit/complextext.cxx
+++ b/vcl/qa/cppunit/complextext.cxx
@@ -46,11 +46,13 @@ public:
     void testArabic();
     void testKashida();
     void testTdf95650(); // Windows-only issue
+    void testCaching();
 
     CPPUNIT_TEST_SUITE(VclComplexTextTest);
     CPPUNIT_TEST(testArabic);
     CPPUNIT_TEST(testKashida);
     CPPUNIT_TEST(testTdf95650);
+    CPPUNIT_TEST(testCaching);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -153,6 +155,59 @@ void VclComplexTextTest::testTdf95650()
     pOutDev->ImplLayout(aTxt, 9, 1, Point(), 0, nullptr, SalLayoutFlags::BiDiRtl);
 }
 
+static void testCachedGlyphs( const OUString& aText, const OUString& aFontName = OUString())
+{
+    const std::string message = OUString("Font: " + aFontName + ", text: '" + aText + "'").toUtf8().getStr();
+    ScopedVclPtrInstance<VirtualDevice> pOutputDevice;
+    if(!aFontName.isEmpty())
+    {
+        vcl::Font aFont( aFontName, Size(0, 12));
+        pOutputDevice->SetFont( aFont );
+    }
+    // Get the glyphs for the text.
+    std::unique_ptr<SalLayout> pLayout1 = pOutputDevice->ImplLayout(
+        aText, 0, aText.getLength(), Point(0, 0), 0, nullptr, SalLayoutFlags::GlyphItemsOnly);
+    SalLayoutGlyphs aGlyphs1 = pLayout1->GetGlyphs();
+    CPPUNIT_ASSERT_MESSAGE(message, aGlyphs1.IsValid());
+    CPPUNIT_ASSERT_MESSAGE(message, aGlyphs1.Impl(0) != nullptr);
+    // Reuse the cached glyphs to get glyphs again.
+    std::unique_ptr<SalLayout> pLayout2 = pOutputDevice->ImplLayout(
+        aText, 0, aText.getLength(), Point(0, 0), 0, nullptr, SalLayoutFlags::GlyphItemsOnly, nullptr, &aGlyphs1);
+    SalLayoutGlyphs aGlyphs2 = pLayout2->GetGlyphs();
+    CPPUNIT_ASSERT_MESSAGE(message, aGlyphs2.IsValid());
+    // And check it's the same.
+    for( int level = 0; level < MAX_FALLBACK; ++level )
+    {
+        const std::string messageLevel = OString(message.c_str()
+            + OStringLiteral(", level: ") + OString::number(level)).getStr();
+        if( aGlyphs1.Impl(level) == nullptr)
+        {
+            CPPUNIT_ASSERT_MESSAGE(messageLevel, aGlyphs2.Impl(level) == nullptr);
+            continue;
+        }
+        const SalLayoutGlyphsImpl* g1 = aGlyphs1.Impl(level);
+        const SalLayoutGlyphsImpl* g2 = aGlyphs2.Impl(level);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(messageLevel, g1->GetFont().get(), g2->GetFont().get());
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(messageLevel, g1->size(), g2->size());
+        for( size_t i = 0; i < g1->size(); ++i )
+        {
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(messageLevel, (*g1)[i].glyphId(), (*g2)[i].glyphId());
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(messageLevel, (*g1)[i].IsRTLGlyph(), (*g2)[i].IsRTLGlyph());
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(messageLevel, (*g1)[i].IsVertical(), (*g2)[i].IsVertical());
+        }
+    }
+}
+
+// Check that caching using SalLayoutGlyphs gives same results as without caching.
+// This should preferably use fonts that come with LO.
+void VclComplexTextTest::testCaching()
+{
+    // Just something basic, no font fallback.
+    testCachedGlyphs( "test", "Dejavu Sans" );
+    // This font does not have latin characters, will need fallback.
+    testCachedGlyphs( "test", "KacstBook" );
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(VclComplexTextTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx
index 2ef3c98d2f9d..5565b3eb4d69 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -296,6 +296,9 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphsIm
     {
         // Work with pre-computed glyph items.
         m_GlyphItems = *pGlyphs;
+        for(const GlyphItem& item : m_GlyphItems)
+            if(!item.glyphId())
+                SetNeedFallback(rArgs, item.charPos(), item.IsRTLGlyph());
         // Some flags are set as a side effect of text layout, restore them here.
         rArgs.mnFlags |= pGlyphs->mnFlags;
         return true;


More information about the Libreoffice-commits mailing list