diff options
Diffstat (limited to 'vcl/inc/impfontcache.hxx')
-rw-r--r-- | vcl/inc/impfontcache.hxx | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/vcl/inc/impfontcache.hxx b/vcl/inc/impfontcache.hxx index 10a38540e67b..c96994300176 100644 --- a/vcl/inc/impfontcache.hxx +++ b/vcl/inc/impfontcache.hxx @@ -21,6 +21,11 @@ #define INCLUDED_VCL_INC_IMPFONTCACHE_HXX #include <unordered_map> +#include <boost/functional/hash.hpp> + +#include <o3tl/lru_map.hxx> +#include <tools/gen.hxx> +#include <vcl/vcllayout.hxx> #include "fontselect.hxx" @@ -28,25 +33,53 @@ class Size; namespace vcl { class Font; } class PhysicalFontCollection; - // TODO: closely couple with PhysicalFontCollection +struct GlpyhBoundRectCacheKey +{ + const LogicalFontInstance* m_pFont; + const sal_GlyphId m_nId; + + GlpyhBoundRectCacheKey(const LogicalFontInstance* pFont, sal_GlyphId nID) + : m_pFont(pFont), m_nId(nID) + {} + + bool operator==(GlpyhBoundRectCacheKey const& aOther) const + { return m_pFont == aOther.m_pFont && m_nId == aOther.m_nId; } +}; + +struct GlpyhBoundRectCacheHash +{ + std::size_t operator()(GlpyhBoundRectCacheKey const& aCache) const + { + std::size_t seed = 0; + boost::hash_combine(seed, aCache.m_pFont); + boost::hash_combine(seed, aCache.m_nId); + return seed; + } +}; + +typedef o3tl::lru_map<GlpyhBoundRectCacheKey, tools::Rectangle, + GlpyhBoundRectCacheHash> GlpyhBoundRectCache; +typedef GlpyhBoundRectCache::key_value_pair_t GlpyhBoundRectCachePair; + class ImplFontCache { private: - LogicalFontInstance* mpLastHitCacheEntry; ///< keeps the last hit cache entry - // cache of recently used font instances struct IFSD_Equal { bool operator()( const FontSelectPattern&, const FontSelectPattern& ) const; }; struct IFSD_Hash { size_t operator()( const FontSelectPattern& ) const; }; typedef std::unordered_map<FontSelectPattern, rtl::Reference<LogicalFontInstance>, IFSD_Hash, IFSD_Equal> FontInstanceList; - FontInstanceList maFontInstanceList; + + LogicalFontInstance* mpLastHitCacheEntry; ///< keeps the last hit cache entry + FontInstanceList maFontInstanceList; + GlpyhBoundRectCache m_aBoundRectCache; rtl::Reference<LogicalFontInstance> GetFontInstance(PhysicalFontCollection const*, FontSelectPattern&); public: - ImplFontCache(); - ~ImplFontCache(); + ImplFontCache(); + ~ImplFontCache(); rtl::Reference<LogicalFontInstance> GetFontInstance( PhysicalFontCollection const *, const vcl::Font&, const Size& rPixelSize, float fExactHeight); @@ -54,6 +87,9 @@ public: LogicalFontInstance* pLogicalFont, int nFallbackLevel, OUString& rMissingCodes ); + bool GetCachedGlyphBoundRect(LogicalFontInstance *, sal_GlyphId, tools::Rectangle &); + void CacheGlyphBoundRect(LogicalFontInstance *, sal_GlyphId, tools::Rectangle &); + void Invalidate(); }; |