diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2018-10-04 14:03:07 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2018-10-06 15:17:52 +0200 |
commit | 612339e574293b248c44cc04a4fae0c77a64ad53 (patch) | |
tree | ebc9a280800f40e26ef32fa9189845ba74bc9c40 /vcl/source/font | |
parent | 4435135e68f7d1024875defc3df18de183607048 (diff) |
Add a glyph-bound-rect cache to the font cache
This way the font cache can correctly invalidate the cached glyph
rects when a font is dropped from the cache.
Change-Id: I050866099742334f01cac1b872228a017ddb5e9b
Reviewed-on: https://gerrit.libreoffice.org/61371
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/source/font')
-rw-r--r-- | vcl/source/font/fontcache.cxx | 38 | ||||
-rw-r--r-- | vcl/source/font/fontinstance.cxx | 13 |
2 files changed, 50 insertions, 1 deletions
diff --git a/vcl/source/font/fontcache.cxx b/vcl/source/font/fontcache.cxx index 82a6261c274c..0db997fe510f 100644 --- a/vcl/source/font/fontcache.cxx +++ b/vcl/source/font/fontcache.cxx @@ -84,11 +84,15 @@ bool ImplFontCache::IFSD_Equal::operator()(const FontSelectPattern& rA, const Fo } ImplFontCache::ImplFontCache() -: mpLastHitCacheEntry( nullptr ) + : mpLastHitCacheEntry( nullptr ) + // The cache limit is set by the rough number of characters needed to read your average Asian newspaper. + , m_aBoundRectCache(3000) {} ImplFontCache::~ImplFontCache() { + for (auto & rLFI : maFontInstanceList) + rLFI.second->mpFontCache = nullptr; } rtl::Reference<LogicalFontInstance> ImplFontCache::GetFontInstance( PhysicalFontCollection const * pFontList, @@ -174,6 +178,9 @@ rtl::Reference<LogicalFontInstance> ImplFontCache::GetFontInstance( PhysicalFont ++it_next; continue; } + m_aBoundRectCache.remove_if([&pFontEntry] (GlpyhBoundRectCachePair const& rPair) + { return rPair.first.m_pFont == pFontEntry; } ); + maFontInstanceList.erase(it_next); if (mpLastHitCacheEntry == pFontEntry) mpLastHitCacheEntry = nullptr; @@ -233,6 +240,35 @@ void ImplFontCache::Invalidate() for (auto const & pair : maFontInstanceList) pair.second->mpFontCache = nullptr; maFontInstanceList.clear(); + m_aBoundRectCache.clear(); +} + +bool ImplFontCache::GetCachedGlyphBoundRect(LogicalFontInstance *pFont, sal_GlyphId nID, tools::Rectangle &rRect) +{ + if (!pFont->GetFontCache()) + return false; + assert(pFont->GetFontCache() == this); + if (pFont->GetFontCache() != this) + return false; + + auto it = m_aBoundRectCache.find({pFont, nID}); + if (it != m_aBoundRectCache.end()) + { + rRect = it->second; + return true; + } + return false; +} + +void ImplFontCache::CacheGlyphBoundRect(LogicalFontInstance *pFont, sal_GlyphId nID, tools::Rectangle &rRect) +{ + if (!pFont->GetFontCache()) + return; + assert(pFont->GetFontCache() == this); + if (pFont->GetFontCache() != this) + return; + + m_aBoundRectCache.insert({{pFont, nID}, rRect}); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/font/fontinstance.cxx b/vcl/source/font/fontinstance.cxx index cf80428f61e2..7a889fa65a7c 100644 --- a/vcl/source/font/fontinstance.cxx +++ b/vcl/source/font/fontinstance.cxx @@ -147,5 +147,18 @@ void LogicalFontInstance::IgnoreFallbackForUnicode( sal_UCS4 cChar, FontWeight e mpUnicodeFallbackList->erase( it ); } +bool LogicalFontInstance::GetCachedGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &rRect) +{ + if (!mpFontCache) + return false; + return mpFontCache->GetCachedGlyphBoundRect(this, nID, rRect); +} + +void LogicalFontInstance::CacheGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &rRect) +{ + if (!mpFontCache) + return; + mpFontCache->CacheGlyphBoundRect(this, nID, rRect); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |