summaryrefslogtreecommitdiffstats
path: root/common/pango.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/pango.c')
-rw-r--r--common/pango.c58
1 files changed, 21 insertions, 37 deletions
diff --git a/common/pango.c b/common/pango.c
index ea71ac4a..ba74692e 100644
--- a/common/pango.c
+++ b/common/pango.c
@@ -6,67 +6,47 @@
6#include <stdio.h> 6#include <stdio.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <string.h> 8#include <string.h>
9#include "cairo.h"
9#include "log.h" 10#include "log.h"
11#include "stringop.h"
10 12
11int escape_markup_text(const char *src, char *dest, int dest_length) { 13size_t escape_markup_text(const char *src, char *dest) {
12 int length = 0; 14 size_t length = 0;
15 if (dest) {
16 dest[0] = '\0';
17 }
13 18
14 while (src[0]) { 19 while (src[0]) {
15 switch (src[0]) { 20 switch (src[0]) {
16 case '&': 21 case '&':
17 length += 5; 22 length += 5;
18 if (dest && dest_length - length >= 0) { 23 lenient_strcat(dest, "&amp;");
19 dest += sprintf(dest, "%s", "&amp;");
20 } else {
21 dest_length = -1;
22 }
23 break; 24 break;
24 case '<': 25 case '<':
25 length += 4; 26 length += 4;
26 if (dest && dest_length - length >= 0) { 27 lenient_strcat(dest, "&lt;");
27 dest += sprintf(dest, "%s", "&lt;");
28 } else {
29 dest_length = -1;
30 }
31 break; 28 break;
32 case '>': 29 case '>':
33 length += 4; 30 length += 4;
34 if (dest && dest_length - length >= 0) { 31 lenient_strcat(dest, "&gt;");
35 dest += sprintf(dest, "%s", "&gt;");
36 } else {
37 dest_length = -1;
38 }
39 break; 32 break;
40 case '\'': 33 case '\'':
41 length += 6; 34 length += 6;
42 if (dest && dest_length - length >= 0) { 35 lenient_strcat(dest, "&apos;");
43 dest += sprintf(dest, "%s", "&apos;");
44 } else {
45 dest_length = -1;
46 }
47 break; 36 break;
48 case '"': 37 case '"':
49 length += 6; 38 length += 6;
50 if (dest && dest_length - length >= 0) { 39 lenient_strcat(dest, "&quot;");
51 dest += sprintf(dest, "%s", "&quot;");
52 } else {
53 dest_length = -1;
54 }
55 break; 40 break;
56 default: 41 default:
57 length += 1; 42 if (dest) {
58 if (dest && dest_length - length >= 0) { 43 dest[length] = *src;
59 *(dest++) = *src; 44 dest[length + 1] = '\0';
60 } else {
61 dest_length = -1;
62 } 45 }
46 length += 1;
63 } 47 }
64 src++; 48 src++;
65 } 49 }
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; 50 return length;
71} 51}
72 52
@@ -78,7 +58,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
78 char *buf; 58 char *buf;
79 GError *error = NULL; 59 GError *error = NULL;
80 if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) { 60 if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) {
81 pango_layout_set_markup(layout, buf, -1); 61 pango_layout_set_text(layout, buf, -1);
82 free(buf); 62 free(buf);
83 } else { 63 } else {
84 wlr_log(WLR_ERROR, "pango_parse_markup '%s' -> error %s", text, 64 wlr_log(WLR_ERROR, "pango_parse_markup '%s' -> error %s", text,
@@ -134,6 +114,10 @@ void pango_printf(cairo_t *cairo, const char *font,
134 va_end(args); 114 va_end(args);
135 115
136 PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); 116 PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup);
117 cairo_font_options_t *fo = cairo_font_options_create();
118 cairo_get_font_options(cairo, fo);
119 pango_cairo_context_set_font_options(pango_layout_get_context(layout), fo);
120 cairo_font_options_destroy(fo);
137 pango_cairo_update_layout(cairo, layout); 121 pango_cairo_update_layout(cairo, layout);
138 pango_cairo_show_layout(cairo, layout); 122 pango_cairo_show_layout(cairo, layout);
139 g_object_unref(layout); 123 g_object_unref(layout);