vcl/source/gdi/impglyphitem.cxx | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
New commits: commit 04a36851aab1272c9c21ac97d0fc0f4ffe372fe0 Author: Luboš Luňák <[email protected]> AuthorDate: Fri May 20 09:02:27 2022 +0200 Commit: Luboš Luňák <[email protected]> CommitDate: Wed May 25 11:43:33 2022 +0200 verify that all results from SalLayoutGlyphsCache match The code used to do it only for computting glyph subsets, but some of the failures there show that bugs in font code elsewhere can make the cache returning different results, so check even for normal repeated cached calls. Change-Id: I8a18710546fe2557f69aaef4ab0bdb63c62a9253 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134659 Tested-by: Jenkins Reviewed-by: Luboš Luňák <[email protected]> diff --git a/vcl/source/gdi/impglyphitem.cxx b/vcl/source/gdi/impglyphitem.cxx index ffed4d56c743..7a4be20c4262 100644 --- a/vcl/source/gdi/impglyphitem.cxx +++ b/vcl/source/gdi/impglyphitem.cxx @@ -295,6 +295,24 @@ static void checkGlyphsEqual(const SalLayoutGlyphs& g1, const SalLayoutGlyphs& g assert(l1->isEqual(l2)); } } + +static void verifyGlyphs(const SalLayoutGlyphs& glyphs, VclPtr<const OutputDevice> outputDevice, + const OUString& text, sal_Int32 nIndex, sal_Int32 nLen, + tools::Long nLogicWidth, const vcl::text::TextLayoutCache* layoutCache) +{ + // Check if the cached result really matches what we would get normally. + std::shared_ptr<const vcl::text::TextLayoutCache> tmpLayoutCache; + if (layoutCache == nullptr) + { + tmpLayoutCache = vcl::text::TextLayoutCache::Create(text); + layoutCache = tmpLayoutCache.get(); + } + std::unique_ptr<SalLayout> layout + = outputDevice->ImplLayout(text, nIndex, nLen, Point(0, 0), nLogicWidth, {}, + SalLayoutFlags::GlyphItemsOnly, layoutCache); + assert(layout); + checkGlyphsEqual(glyphs, layout->GetGlyphs()); +} #endif const SalLayoutGlyphs* @@ -309,7 +327,12 @@ SalLayoutGlyphsCache::GetLayoutGlyphs(VclPtr<const OutputDevice> outputDevice, c if (it != mCachedGlyphs.end()) { if (it->second.IsValid()) + { +#ifdef DBG_UTIL + verifyGlyphs(it->second, outputDevice, text, nIndex, nLen, nLogicWidth, layoutCache); +#endif return &it->second; + } // Do not try to create the layout here. If a cache item exists, it's already // been attempted and the layout was invalid (this happens with MultiSalLayout). // So in that case this is a cached failure. @@ -378,19 +401,8 @@ SalLayoutGlyphsCache::GetLayoutGlyphs(VclPtr<const OutputDevice> outputDevice, c { mLastTemporaryKey = std::move(key); #ifdef DBG_UTIL - std::shared_ptr<const vcl::text::TextLayoutCache> tmpLayoutCache; - if (layoutCache == nullptr) - { - tmpLayoutCache = vcl::text::TextLayoutCache::Create(text); - layoutCache = tmpLayoutCache.get(); - } - // Check if the subset result really matches what we would get normally, - // to make sure corner cases are handled well (see SalLayoutGlyphsImpl::cloneCharRange()). - std::unique_ptr<SalLayout> layout - = outputDevice->ImplLayout(text, nIndex, nLen, Point(0, 0), nLogicWidth, {}, - SalLayoutFlags::GlyphItemsOnly, layoutCache); - assert(layout); - checkGlyphsEqual(mLastTemporaryGlyphs, layout->GetGlyphs()); + verifyGlyphs(mLastTemporaryGlyphs, outputDevice, text, nIndex, nLen, nLogicWidth, + layoutCache); #endif return &mLastTemporaryGlyphs; }
