summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-05-25 12:14:12 +0200
committerLuboš Luňák <l.lunak@collabora.com>2022-05-26 07:08:16 +0200
commit13762c1ec222b6235bbef39eed9bb1037e082a1e (patch)
tree92a5019aa83526fa5a4cf28d52a8f082987c6fda /vcl
parent28a8746ad86907491b428f5fac7e1be4f5bfcf2c (diff)
test also SalLayoutGlyphsCache in glyphs caching unittest
Change-Id: Ic0e5ea44525e7cf76a6de1f64f77b943b8347dfc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134948 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/qa/cppunit/complextext.cxx45
1 files changed, 29 insertions, 16 deletions
diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx
index aaea5785c2c4..6a37ed1713ad 100644
--- a/vcl/qa/cppunit/complextext.cxx
+++ b/vcl/qa/cppunit/complextext.cxx
@@ -13,6 +13,7 @@
#include <ostream>
#include <vector>
#include <tools/long.hxx>
+#include <vcl/glyphitemcache.hxx>
#if HAVE_MORE_FONTS
// must be declared before inclusion of test/bootstrapfixture.hxx
@@ -160,23 +161,9 @@ void VclComplexTextTest::testTdf95650()
pOutDev->ImplLayout(aTxt, 9, 1, Point(), 0, {}, SalLayoutFlags::BiDiRtl);
}
-static void testCachedGlyphs( const OUString& aText, const OUString& aFontName = OUString())
+static void checkCompareGlyphs( const SalLayoutGlyphs& aGlyphs1, const SalLayoutGlyphs& aGlyphs2,
+ const std::string& message )
{
- 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, {}, SalLayoutFlags::GlyphItemsOnly);
- SalLayoutGlyphs aGlyphs1 = pLayout1->GetGlyphs();
- // Reuse the cached glyphs to get glyphs again.
- std::unique_ptr<SalLayout> pLayout2 = pOutputDevice->ImplLayout(
- aText, 0, aText.getLength(), Point(0, 0), 0, {}, SalLayoutFlags::GlyphItemsOnly, nullptr, &aGlyphs1);
- SalLayoutGlyphs aGlyphs2 = pLayout2->GetGlyphs();
CPPUNIT_ASSERT_EQUAL_MESSAGE(message, aGlyphs1.IsValid(), aGlyphs2.IsValid());
// And check it's the same.
for( int level = 0; level < MAX_FALLBACK; ++level )
@@ -200,6 +187,32 @@ static void testCachedGlyphs( const OUString& aText, const OUString& aFontName =
}
}
+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 );
+ }
+ SalLayoutGlyphsCache::self()->clear();
+ // Get the glyphs for the text.
+ std::unique_ptr<SalLayout> pLayout1 = pOutputDevice->ImplLayout(
+ aText, 0, aText.getLength(), Point(0, 0), 0, {}, SalLayoutFlags::GlyphItemsOnly);
+ SalLayoutGlyphs aGlyphs1 = pLayout1->GetGlyphs();
+ // Reuse the cached glyphs to get glyphs again.
+ std::unique_ptr<SalLayout> pLayout2 = pOutputDevice->ImplLayout(
+ aText, 0, aText.getLength(), Point(0, 0), 0, {}, SalLayoutFlags::GlyphItemsOnly, nullptr, &aGlyphs1);
+ SalLayoutGlyphs aGlyphs2 = pLayout2->GetGlyphs();
+ checkCompareGlyphs(aGlyphs1, aGlyphs2, message + " (reuse)");
+ // Get cached glyphs from SalLayoutGlyphsCache.
+ const SalLayoutGlyphs* aGlyphs3 = SalLayoutGlyphsCache::self()->GetLayoutGlyphs(
+ pOutputDevice, aText, 0, aText.getLength(), 0);
+ CPPUNIT_ASSERT_MESSAGE(message, aGlyphs3 != nullptr);
+ checkCompareGlyphs(aGlyphs1, *aGlyphs3, message + " (cache)");
+}
+
// Check that caching using SalLayoutGlyphs gives same results as without caching.
// This should preferably use fonts that come with LO.
void VclComplexTextTest::testCaching()