summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-03-19 19:14:31 +0100
committerLuboš Luňák <l.lunak@collabora.com>2021-03-21 16:21:35 +0100
commit160ff36d2593a24b6a933332ab5d66683528403c (patch)
tree53931a2c74deba9250e7f1a3c336e8a565a0fc73 /vcl
parentc3ffeb01a9f868c734ce235a6d38ce51b80ca05e (diff)
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@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/qa/cppunit/complextext.cxx55
-rw-r--r--vcl/source/gdi/CommonSalLayout.cxx3
2 files changed, 58 insertions, 0 deletions
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;