vcl/source/gdi/impglyphitem.cxx | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
New commits: commit 4fc3466d23010d9553c31c662650072483b81588 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Thu Apr 14 09:19:35 2022 +0200 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Thu Apr 14 11:31:30 2022 +0200 do not cache layout glyphs if fallback is involved In some rare cases (CppunitTest_writerperfect_writer can trigger them on Win/Mac) the fonts used for fallback change and it's not included in the cache key. Change-Id: I9611d500405d0dae7f95fa4469ccfaa39de672c5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132995 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/vcl/source/gdi/impglyphitem.cxx b/vcl/source/gdi/impglyphitem.cxx index ab615ae270b0..d581715dc9cd 100644 --- a/vcl/source/gdi/impglyphitem.cxx +++ b/vcl/source/gdi/impglyphitem.cxx @@ -173,8 +173,6 @@ static SalLayoutGlyphs makeGlyphsSubset(const SalLayoutGlyphs& source, sal_Int32 const SalLayoutGlyphsImpl* sourceLevel = source.Impl(level); if (sourceLevel == nullptr) break; - if (level > 0) // TODO: Fallbacks do not work reliably. - return SalLayoutGlyphs(); SalLayoutGlyphsImpl* cloned = sourceLevel->cloneCharRange(index, len); // If the glyphs range cannot be cloned, bail out. if (cloned == nullptr) @@ -265,16 +263,26 @@ SalLayoutGlyphsCache::GetLayoutGlyphs(VclPtr<const OutputDevice> outputDevice, c text, nIndex, nLen, Point(0, 0), nLogicWidth, {}, glyphItemsOnlyLayout, layoutCache); if (layout) { - mCachedGlyphs.insert(std::make_pair(key, layout->GetGlyphs())); - assert(mCachedGlyphs.find(key) == mCachedGlyphs.begin()); // newly inserted item is first - return &mCachedGlyphs.begin()->second; - } - else - { - // Failure, cache it too as invalid glyphs. - mCachedGlyphs.insert(std::make_pair(key, SalLayoutGlyphs())); - return nullptr; + SalLayoutGlyphs glyphs = layout->GetGlyphs(); + if (glyphs.IsValid()) + { + // TODO: Fallbacks do not work reliably (fallback font not included in the key), + // so do not cache (but still return once, using the temporary without a key set). + if (glyphs.Impl(1) != nullptr) + { + mLastTemporaryGlyphs = std::move(glyphs); + mLastTemporaryKey.reset(); + return &mLastTemporaryGlyphs; + } + mCachedGlyphs.insert(std::make_pair(key, layout->GetGlyphs())); + assert(mCachedGlyphs.find(key) + == mCachedGlyphs.begin()); // newly inserted item is first + return &mCachedGlyphs.begin()->second; + } } + // Failure, cache it too as invalid glyphs. + mCachedGlyphs.insert(std::make_pair(key, SalLayoutGlyphs())); + return nullptr; } SalLayoutGlyphsCache::CachedGlyphsKey::CachedGlyphsKey(const VclPtr<const OutputDevice>& d,