diff options
author | 2018-05-14 00:28:21 -0400 | |
---|---|---|
committer | 2018-05-14 00:28:21 -0400 | |
commit | 34b864fb1752fde2528db6aa86d53c23412a8f43 (patch) | |
tree | b387f1e1eb8f8fc16faeb4bf24a0ab6e8ba5787c /common | |
parent | Fix titles and detect edges for hide_edge_borders (diff) | |
parent | Actually fix swayidle (diff) | |
download | sway-34b864fb1752fde2528db6aa86d53c23412a8f43.tar.gz sway-34b864fb1752fde2528db6aa86d53c23412a8f43.tar.zst sway-34b864fb1752fde2528db6aa86d53c23412a8f43.zip |
Merge branch 'master' into fix-1975
Diffstat (limited to 'common')
-rw-r--r-- | common/pango.c | 81 |
1 files changed, 73 insertions, 8 deletions
diff --git a/common/pango.c b/common/pango.c index 658d2876..403bd9a8 100644 --- a/common/pango.c +++ b/common/pango.c | |||
@@ -8,6 +8,68 @@ | |||
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include "log.h" | 9 | #include "log.h" |
10 | 10 | ||
11 | int escape_markup_text(const char *src, char *dest, int dest_length) { | ||
12 | int length = 0; | ||
13 | |||
14 | while (src[0]) { | ||
15 | switch (src[0]) { | ||
16 | case '&': | ||
17 | length += 5; | ||
18 | if (dest && dest_length - length >= 0) { | ||
19 | dest += sprintf(dest, "%s", "&"); | ||
20 | } else { | ||
21 | dest_length = -1; | ||
22 | } | ||
23 | break; | ||
24 | case '<': | ||
25 | length += 4; | ||
26 | if (dest && dest_length - length >= 0) { | ||
27 | dest += sprintf(dest, "%s", "<"); | ||
28 | } else { | ||
29 | dest_length = -1; | ||
30 | } | ||
31 | break; | ||
32 | case '>': | ||
33 | length += 4; | ||
34 | if (dest && dest_length - length >= 0) { | ||
35 | dest += sprintf(dest, "%s", ">"); | ||
36 | } else { | ||
37 | dest_length = -1; | ||
38 | } | ||
39 | break; | ||
40 | case '\'': | ||
41 | length += 6; | ||
42 | if (dest && dest_length - length >= 0) { | ||
43 | dest += sprintf(dest, "%s", "'"); | ||
44 | } else { | ||
45 | dest_length = -1; | ||
46 | } | ||
47 | break; | ||
48 | case '"': | ||
49 | length += 6; | ||
50 | if (dest && dest_length - length >= 0) { | ||
51 | dest += sprintf(dest, "%s", """); | ||
52 | } else { | ||
53 | dest_length = -1; | ||
54 | } | ||
55 | break; | ||
56 | default: | ||
57 | length += 1; | ||
58 | if (dest && dest_length - length >= 0) { | ||
59 | *(dest++) = *src; | ||
60 | } else { | ||
61 | dest_length = -1; | ||
62 | } | ||
63 | } | ||
64 | src++; | ||
65 | } | ||
66 | // if we could not fit the escaped string in dest, return -1 | ||
67 | if (dest && dest_length == -1) { | ||
68 | return -1; | ||
69 | } | ||
70 | return length; | ||
71 | } | ||
72 | |||
11 | PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, | 73 | PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, |
12 | const char *text, int32_t scale, bool markup) { | 74 | const char *text, int32_t scale, bool markup) { |
13 | PangoLayout *layout = pango_cairo_create_layout(cairo); | 75 | PangoLayout *layout = pango_cairo_create_layout(cairo); |
@@ -15,18 +77,21 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, | |||
15 | if (markup) { | 77 | if (markup) { |
16 | char *buf; | 78 | char *buf; |
17 | GError *error = NULL; | 79 | GError *error = NULL; |
18 | if (!sway_assert(pango_parse_markup( | 80 | if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) { |
19 | text, -1, 0, &attrs, &buf, NULL, &error), | 81 | pango_layout_set_markup(layout, buf, -1); |
20 | "pango_parse_markup '%s' -> error %s", text, | 82 | free(buf); |
21 | error ? error->message : NULL)) { | 83 | } else { |
22 | return NULL; | 84 | wlr_log(L_ERROR, "pango_parse_markup '%s' -> error %s", text, |
85 | error->message); | ||
86 | g_error_free(error); | ||
87 | markup = false; // fallback to plain text | ||
23 | } | 88 | } |
24 | pango_layout_set_markup(layout, buf, -1); | 89 | } |
25 | free(buf); | 90 | if (!markup) { |
26 | } else { | ||
27 | attrs = pango_attr_list_new(); | 91 | attrs = pango_attr_list_new(); |
28 | pango_layout_set_text(layout, text, -1); | 92 | pango_layout_set_text(layout, text, -1); |
29 | } | 93 | } |
94 | |||
30 | pango_attr_list_insert(attrs, pango_attr_scale_new(scale)); | 95 | pango_attr_list_insert(attrs, pango_attr_scale_new(scale)); |
31 | PangoFontDescription *desc = pango_font_description_from_string(font); | 96 | PangoFontDescription *desc = pango_font_description_from_string(font); |
32 | pango_layout_set_font_description(layout, desc); | 97 | pango_layout_set_font_description(layout, desc); |