diff options
author | Noel Grandin <noel@peralex.com> | 2018-04-24 08:36:58 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-26 08:48:06 +0200 |
commit | 13a1bc409d9b2f0d14f4d316b7977b1fc2eb3c8a (patch) | |
tree | 97c8f08726749007311263dad8280480bde449b9 /vcl/win/gdi/salfont.cxx | |
parent | 96c1aad92b40a14d0d4af662e276b6967560ec20 (diff) |
tdf#113643 Editing tables in Impress lags terribly
Despite my previous commit here, the time was still being spent building
bound rect's for font glyphs, so improve the caching so we don't need to
clear it when we change the font selected into the DC.
Change-Id: Iee8230fc76d9d809f3521d016e4ce9a6555e6f65
Reviewed-on: https://gerrit.libreoffice.org/53371
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/win/gdi/salfont.cxx')
-rw-r--r-- | vcl/win/gdi/salfont.cxx | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx index 6fe84173c710..0acdbd666bef 100644 --- a/vcl/win/gdi/salfont.cxx +++ b/vcl/win/gdi/salfont.cxx @@ -57,10 +57,22 @@ using namespace vcl; +using BoundRectCacheKey = std::pair<PhysicalFontFace const *,sal_GlyphId>; +namespace std +{ + template<> struct hash<BoundRectCacheKey> + { + std::size_t operator()(const BoundRectCacheKey & key ) const + { + return std::hash<PhysicalFontFace const *>()(key.first) + ^ std::hash<sal_GlyphId>()(key.second); + } + }; +}; // GetGlyphOutlineW() seems to be a little slow, and doesn't seem to do it's own caching (tested on Windows10). // TODO include the font as part of the cache key, then we won't need to clear it on font change // The cache limit is set by the rough number of characters needed to read your average Asian newspaper. -static o3tl::lru_map<sal_GlyphId, tools::Rectangle> g_BoundRectCache(3000); +static o3tl::lru_map<BoundRectCacheKey, tools::Rectangle> g_BoundRectCache(3000); static const int MAXFONTHEIGHT = 2048; @@ -840,10 +852,9 @@ void ImplGetLogFontFromFontSelect( HDC hDC, HFONT WinSalGraphics::ImplDoSetFont(FontSelectPattern const * i_pFont, float& o_rFontScale, HFONT& o_rOldFont) { - // clear the cache on font change - g_BoundRectCache.clear(); - HFONT hNewFont = nullptr; + mpCurrentPhysicalFontFace = i_pFont->mpFontData; + HFONT hNewFont = nullptr; HDC hdcScreen = nullptr; if( mbVirDev ) // only required for virtual devices, see below for details @@ -1355,7 +1366,7 @@ void WinSalGraphics::ClearDevFontCache() bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& rRect) { - auto it = g_BoundRectCache.find(rGlyph.maGlyphId); + auto it = g_BoundRectCache.find({mpCurrentPhysicalFontFace,rGlyph.maGlyphId}); if (it != g_BoundRectCache.end()) { rRect = it->second; @@ -1386,8 +1397,7 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle rRect.SetTop(static_cast<int>( mfCurrentFontScale * rRect.Top() )); rRect.SetBottom(static_cast<int>( mfCurrentFontScale * rRect.Bottom() ) + 1); - g_BoundRectCache.insert({rGlyph.maGlyphId, rRect}); - + g_BoundRectCache.insert({{mpCurrentPhysicalFontFace,rGlyph.maGlyphId}, rRect}); return true; } |