From 75605491a54f8647740fdba75dd2ad7bae9e0ca7 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Wed, 29 Jun 2022 21:38:24 +0200 Subject: Reject font values that are invalid for pango Use pango to parse font configuration early, and reject the command as invalid if the value is invalid for pango. Since we're already parsing the font into a `PangoFontDescription`, keep that instance around and avoid re-parsing the font each time we render text. Fixes: https://github.com/swaywm/sway/issues/6805 --- 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 abc18281..e8e2678d 100644 --- a/common/pango.c +++ b/common/pango.c @@ -109,10 +109,9 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, free(buf); } -void get_text_metrics(const char *font, int *height, int *baseline) { +void get_text_metrics(const PangoFontDescription *description, 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); // When passing NULL as a language, pango uses the current locale. PangoFontMetrics *metrics = pango_context_get_metrics(pango, description, NULL); @@ -120,7 +119,6 @@ void get_text_metrics(const char *font, int *height, int *baseline) { *height = *baseline + pango_font_metrics_get_descent(metrics) / PANGO_SCALE; pango_font_metrics_unref(metrics); - pango_font_description_free(description); g_object_unref(pango); cairo_destroy(cairo); } -- cgit v1.2.3-54-g00ecf