From c16b2a26ed2c2f718cb8a2084fa93636fabed95f Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Fri, 17 Sep 2021 17:32:29 +0200 Subject: Avoid unecessary font metric calculations Prior to 62d90a8e, titlebar's font height (and other related values) would change any time any titlebar's content changed, so these values were recalculated each time any titlebar's content changed (or a new titlebar was created). However, since the above was merge, these values no longer change so often and we only need to recalculate them when the configured font changes (and stop calling `config_update_font_height` each time titlebars are rendered). This commit removes all the unecessary calls to this function and avoids all those unecessary calculations. Whenever the font strays from the default value, the `font` command is called, and it calls `config_update_font_height`, which is enough to keep the value always up to date. I've also added a default value to the `font_baseline` config, since otherwise that's zero for setups that don't explicitly specify a font. --- common/pango.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'common') diff --git a/common/pango.c b/common/pango.c index 89b1ac41..abc18281 100644 --- a/common/pango.c +++ b/common/pango.c @@ -113,10 +113,8 @@ void get_text_metrics(const char *font, int *height, int *baseline) { cairo_t *cairo = cairo_create(NULL); PangoContext *pango = pango_cairo_create_context(cairo); PangoFontDescription *description = pango_font_description_from_string(font); - PangoFontMetrics *metrics; - // When passing NULL as a language, pango uses the current locale. - metrics = pango_context_get_metrics(pango, description, NULL); + PangoFontMetrics *metrics = pango_context_get_metrics(pango, description, NULL); *baseline = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; *height = *baseline + pango_font_metrics_get_descent(metrics) / PANGO_SCALE; -- cgit v1.2.3-54-g00ecf