aboutsummaryrefslogtreecommitdiffstats
path: root/common/pango.c
diff options
context:
space:
mode:
authorLibravatar Hugo Osvaldo Barrera <hugo@barrera.io>2022-06-29 21:38:24 +0200
committerLibravatar Simon Ser <contact@emersion.fr>2022-07-01 13:05:58 +0200
commit75605491a54f8647740fdba75dd2ad7bae9e0ca7 (patch)
treef1d7476fbc893517ea01ed0f92841219f8b4808a /common/pango.c
parentAvoid unecessary string copy (diff)
downloadsway-75605491a54f8647740fdba75dd2ad7bae9e0ca7.tar.gz
sway-75605491a54f8647740fdba75dd2ad7bae9e0ca7.tar.zst
sway-75605491a54f8647740fdba75dd2ad7bae9e0ca7.zip
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
Diffstat (limited to 'common/pango.c')
-rw-r--r--common/pango.c4
1 files changed, 1 insertions, 3 deletions
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,
109 free(buf); 109 free(buf);
110} 110}
111 111
112void get_text_metrics(const char *font, int *height, int *baseline) { 112void get_text_metrics(const PangoFontDescription *description, int *height, int *baseline) {
113 cairo_t *cairo = cairo_create(NULL); 113 cairo_t *cairo = cairo_create(NULL);
114 PangoContext *pango = pango_cairo_create_context(cairo); 114 PangoContext *pango = pango_cairo_create_context(cairo);
115 PangoFontDescription *description = pango_font_description_from_string(font);
116 // When passing NULL as a language, pango uses the current locale. 115 // When passing NULL as a language, pango uses the current locale.
117 PangoFontMetrics *metrics = pango_context_get_metrics(pango, description, NULL); 116 PangoFontMetrics *metrics = pango_context_get_metrics(pango, description, NULL);
118 117
@@ -120,7 +119,6 @@ void get_text_metrics(const char *font, int *height, int *baseline) {
120 *height = *baseline + pango_font_metrics_get_descent(metrics) / PANGO_SCALE; 119 *height = *baseline + pango_font_metrics_get_descent(metrics) / PANGO_SCALE;
121 120
122 pango_font_metrics_unref(metrics); 121 pango_font_metrics_unref(metrics);
123 pango_font_description_free(description);
124 g_object_unref(pango); 122 g_object_unref(pango);
125 cairo_destroy(cairo); 123 cairo_destroy(cairo);
126} 124}