vcl/win/gdi/salfont.cxx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
New commits: commit f58aec2788ab5675cb6ffe411bd5e55a7f2a156d Author: Thorsten Behrens <thorsten.behr...@cib.de> AuthorDate: Mon May 11 23:47:21 2020 +0200 Commit: Thorsten Behrens <thorsten.behr...@cib.de> CommitDate: Tue May 12 16:38:02 2020 +0200 tdf#108608 more Draw text editing responsiveness fixes Turns out Windows is rather slow at calculating glyph outlines (compared to Linux), I'm guessing it does no caching at all, so just add our own little cache. This re-introduces the initial, simple glyph rect cache from https://gerrit.libreoffice.org/52623, but amended with fixes for: - tdf#120204 and duplicates - tdf#119829 and duplicates This partially reverts commit ac39aba9b2d08b061b0eef651f5ebc7a84391171. Change-Id: I9445604139a2d7242969a225d9cf2967316c3608 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94029 Tested-by: Thorsten Behrens <thorsten.behr...@cib.de> Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx index 11957c7043dc..378fd287fc9f 100644 --- a/vcl/win/gdi/salfont.cxx +++ b/vcl/win/gdi/salfont.cxx @@ -58,6 +58,11 @@ using namespace vcl; +// GetGlyphOutlineW() seems to be a little slow, and doesn't seem to do its 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 const int MAXFONTHEIGHT = 2048; inline FIXED FixedFromDouble( double d ) @@ -848,6 +853,8 @@ HFONT WinSalGraphics::ImplDoSetFont(FontSelectPattern const * i_pFont, float& o_rFontScale, HFONT& o_rOldFont) { + // clear the cache on font change - tdf#119829 + g_BoundRectCache.clear(); HFONT hNewFont = nullptr; LOGFONTW aLogFont; @@ -909,6 +916,9 @@ HFONT WinSalGraphics::ImplDoSetFont(FontSelectPattern const * i_pFont, void WinSalGraphics::SetFont( const FontSelectPattern* pFont, int nFallbackLevel ) { + // clear the cache on font change - tdf#119829 + g_BoundRectCache.clear(); + // return early if there is no new font if( !pFont ) { @@ -1380,6 +1390,13 @@ void WinSalGraphics::ClearDevFontCache() bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& rRect) { + auto it = g_BoundRectCache.find(rGlyph.maGlyphId); + if (it != g_BoundRectCache.end()) + { + rRect = it->second; + return true; + } + WinFontInstance* pFont = mpWinFontEntry[rGlyph.mnFallbackLevel]; HFONT hNewFont = pFont ? pFont->GetHFONT() : mhFonts[rGlyph.mnFallbackLevel]; float fFontScale = pFont ? pFont->GetScale() : mfFontScale[rGlyph.mnFallbackLevel]; @@ -1413,6 +1430,8 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle rRect.SetTop(static_cast<int>( fFontScale * rRect.Top() )); rRect.SetBottom(static_cast<int>( fFontScale * rRect.Bottom() ) + 1); + g_BoundRectCache.insert({rGlyph.maGlyphId, rRect}); + return true; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits