From e9b42e6c5863e343d676733c908dc502d3cf77fe Mon Sep 17 00:00:00 2001 From: Kurt Kartaltepe Date: Sun, 14 Apr 2024 21:45:40 -0700 Subject: [PATCH] text-freetype2: Use cached glyph advances We had these advances laying around but didn't use them here. Loading the glyphs from the fonts is extremely slow, so let's avoid that since we take the time to cache these already. --- plugins/text-freetype2/text-functionality.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/text-freetype2/text-functionality.c b/plugins/text-freetype2/text-functionality.c index 25772c50a..e20176a8f 100644 --- a/plugins/text-freetype2/text-functionality.c +++ b/plugins/text-freetype2/text-functionality.c @@ -570,12 +570,17 @@ uint32_t get_ft2_text_width(wchar_t *text, struct ft2_source *srcdata) const FT_UInt glyph_index = FT_Get_Char_Index(srcdata->font_face, text[i]); - load_glyph(srcdata, glyph_index, get_render_mode(srcdata)); - if (text[i] == L'\n') w = 0; else { - w += slot->advance.x >> 6; + if (src_glyph) { + // Use the cached values. + w += src_glyph->xadv; + } else { + load_glyph(srcdata, glyph_index, + get_render_mode(srcdata)); + w += slot->advance.x >> 6; + } if (w > max_w) max_w = w; }