diff options
author | 2018-09-22 11:25:07 +0200 | |
---|---|---|
committer | 2018-09-22 11:25:07 +0200 | |
commit | b148da848ae9075822cd8ddd743532f3ce78f923 (patch) | |
tree | 0f0e3cf936553aeb28f39c5506eb94b8abcadc8f /common/pango.c | |
parent | Merge pull request #2678 from RyanDwyer/reconfigure-on-reposition (diff) | |
parent | Use pango_layout_set_text instead of pango_layout_set_markup (diff) | |
download | sway-b148da848ae9075822cd8ddd743532f3ce78f923.tar.gz sway-b148da848ae9075822cd8ddd743532f3ce78f923.tar.zst sway-b148da848ae9075822cd8ddd743532f3ce78f923.zip |
Merge pull request #2679 from RyanDwyer/fix-pango-escaping
Fix pango escaping and refactor escape_markup_text
Diffstat (limited to 'common/pango.c')
-rw-r--r-- | common/pango.c | 53 |
1 files changed, 16 insertions, 37 deletions
diff --git a/common/pango.c b/common/pango.c index ea71ac4a..5afd72d8 100644 --- a/common/pango.c +++ b/common/pango.c | |||
@@ -7,66 +7,45 @@ | |||
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include "log.h" | 9 | #include "log.h" |
10 | #include "stringop.h" | ||
10 | 11 | ||
11 | int escape_markup_text(const char *src, char *dest, int dest_length) { | 12 | size_t escape_markup_text(const char *src, char *dest) { |
12 | int length = 0; | 13 | size_t length = 0; |
14 | if (dest) { | ||
15 | dest[0] = '\0'; | ||
16 | } | ||
13 | 17 | ||
14 | while (src[0]) { | 18 | while (src[0]) { |
15 | switch (src[0]) { | 19 | switch (src[0]) { |
16 | case '&': | 20 | case '&': |
17 | length += 5; | 21 | length += 5; |
18 | if (dest && dest_length - length >= 0) { | 22 | lenient_strcat(dest, "&"); |
19 | dest += sprintf(dest, "%s", "&"); | ||
20 | } else { | ||
21 | dest_length = -1; | ||
22 | } | ||
23 | break; | 23 | break; |
24 | case '<': | 24 | case '<': |
25 | length += 4; | 25 | length += 4; |
26 | if (dest && dest_length - length >= 0) { | 26 | lenient_strcat(dest, "<"); |
27 | dest += sprintf(dest, "%s", "<"); | ||
28 | } else { | ||
29 | dest_length = -1; | ||
30 | } | ||
31 | break; | 27 | break; |
32 | case '>': | 28 | case '>': |
33 | length += 4; | 29 | length += 4; |
34 | if (dest && dest_length - length >= 0) { | 30 | lenient_strcat(dest, ">"); |
35 | dest += sprintf(dest, "%s", ">"); | ||
36 | } else { | ||
37 | dest_length = -1; | ||
38 | } | ||
39 | break; | 31 | break; |
40 | case '\'': | 32 | case '\'': |
41 | length += 6; | 33 | length += 6; |
42 | if (dest && dest_length - length >= 0) { | 34 | lenient_strcat(dest, "'"); |
43 | dest += sprintf(dest, "%s", "'"); | ||
44 | } else { | ||
45 | dest_length = -1; | ||
46 | } | ||
47 | break; | 35 | break; |
48 | case '"': | 36 | case '"': |
49 | length += 6; | 37 | length += 6; |
50 | if (dest && dest_length - length >= 0) { | 38 | lenient_strcat(dest, """); |
51 | dest += sprintf(dest, "%s", """); | ||
52 | } else { | ||
53 | dest_length = -1; | ||
54 | } | ||
55 | break; | 39 | break; |
56 | default: | 40 | default: |
57 | length += 1; | 41 | if (dest) { |
58 | if (dest && dest_length - length >= 0) { | 42 | dest[length] = *src; |
59 | *(dest++) = *src; | 43 | dest[length + 1] = '\0'; |
60 | } else { | ||
61 | dest_length = -1; | ||
62 | } | 44 | } |
45 | length += 1; | ||
63 | } | 46 | } |
64 | src++; | 47 | src++; |
65 | } | 48 | } |
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; | 49 | return length; |
71 | } | 50 | } |
72 | 51 | ||
@@ -78,7 +57,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, | |||
78 | char *buf; | 57 | char *buf; |
79 | GError *error = NULL; | 58 | GError *error = NULL; |
80 | if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) { | 59 | if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) { |
81 | pango_layout_set_markup(layout, buf, -1); | 60 | pango_layout_set_text(layout, buf, -1); |
82 | free(buf); | 61 | free(buf); |
83 | } else { | 62 | } else { |
84 | wlr_log(WLR_ERROR, "pango_parse_markup '%s' -> error %s", text, | 63 | wlr_log(WLR_ERROR, "pango_parse_markup '%s' -> error %s", text, |