summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-05-13 16:52:02 +0100
committerLibravatar emersion <contact@emersion.fr>2018-05-13 16:52:02 +0100
commit6eda10e4ca1bfd0afe25f1255c42c0328b330a02 (patch)
tree5cdcaf054fe4d483307b5e6a005838ebcad93fdc /common
parentMerge pull request #1935 from heghe/heghe/fix-pango-markup-crash (diff)
downloadsway-6eda10e4ca1bfd0afe25f1255c42c0328b330a02.tar.gz
sway-6eda10e4ca1bfd0afe25f1255c42c0328b330a02.tar.zst
sway-6eda10e4ca1bfd0afe25f1255c42c0328b330a02.zip
Fix pango markup
The condition checking if the markup is valid was inverted. This commit also adds better error handling: if the markup cannot be parsed, it fallbacks to plain text.
Diffstat (limited to 'common')
-rw-r--r--common/pango.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/common/pango.c b/common/pango.c
index 9437c60d..403bd9a8 100644
--- a/common/pango.c
+++ b/common/pango.c
@@ -77,19 +77,21 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
77 if (markup) { 77 if (markup) {
78 char *buf; 78 char *buf;
79 GError *error = NULL; 79 GError *error = NULL;
80 bool result = pango_parse_markup(text, -1, 0, &attrs, &buf, 80 if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) {
81 NULL, &error); 81 pango_layout_set_markup(layout, buf, -1);
82 if (result) { 82 free(buf);
83 } else {
83 wlr_log(L_ERROR, "pango_parse_markup '%s' -> error %s", text, 84 wlr_log(L_ERROR, "pango_parse_markup '%s' -> error %s", text,
84 error->message); 85 error->message);
85 return NULL; 86 g_error_free(error);
87 markup = false; // fallback to plain text
86 } 88 }
87 pango_layout_set_markup(layout, text, -1); 89 }
88 free(buf); 90 if (!markup) {
89 } else {
90 attrs = pango_attr_list_new(); 91 attrs = pango_attr_list_new();
91 pango_layout_set_text(layout, text, -1); 92 pango_layout_set_text(layout, text, -1);
92 } 93 }
94
93 pango_attr_list_insert(attrs, pango_attr_scale_new(scale)); 95 pango_attr_list_insert(attrs, pango_attr_scale_new(scale));
94 PangoFontDescription *desc = pango_font_description_from_string(font); 96 PangoFontDescription *desc = pango_font_description_from_string(font);
95 pango_layout_set_font_description(layout, desc); 97 pango_layout_set_font_description(layout, desc);