diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/background-image.c | 2 | ||||
-rw-r--r-- | common/cairo.c | 16 | ||||
-rw-r--r-- | common/pango.c | 58 |
3 files changed, 39 insertions, 37 deletions
diff --git a/common/background-image.c b/common/background-image.c index f3d2551e..5ede55e3 100644 --- a/common/background-image.c +++ b/common/background-image.c | |||
@@ -58,6 +58,7 @@ void render_background_image(cairo_t *cairo, cairo_surface_t *image, | |||
58 | double width = cairo_image_surface_get_width(image); | 58 | double width = cairo_image_surface_get_width(image); |
59 | double height = cairo_image_surface_get_height(image); | 59 | double height = cairo_image_surface_get_height(image); |
60 | 60 | ||
61 | cairo_save(cairo); | ||
61 | switch (mode) { | 62 | switch (mode) { |
62 | case BACKGROUND_MODE_STRETCH: | 63 | case BACKGROUND_MODE_STRETCH: |
63 | cairo_scale(cairo, | 64 | cairo_scale(cairo, |
@@ -116,4 +117,5 @@ void render_background_image(cairo_t *cairo, cairo_surface_t *image, | |||
116 | break; | 117 | break; |
117 | } | 118 | } |
118 | cairo_paint(cairo); | 119 | cairo_paint(cairo); |
120 | cairo_restore(cairo); | ||
119 | } | 121 | } |
diff --git a/common/cairo.c b/common/cairo.c index c267c77c..e8231484 100644 --- a/common/cairo.c +++ b/common/cairo.c | |||
@@ -13,6 +13,22 @@ void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { | |||
13 | (color >> (0*8) & 0xFF) / 255.0); | 13 | (color >> (0*8) & 0xFF) / 255.0); |
14 | } | 14 | } |
15 | 15 | ||
16 | cairo_subpixel_order_t to_cairo_subpixel_order(enum wl_output_subpixel subpixel) { | ||
17 | switch (subpixel) { | ||
18 | case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB: | ||
19 | return CAIRO_SUBPIXEL_ORDER_RGB; | ||
20 | case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR: | ||
21 | return CAIRO_SUBPIXEL_ORDER_BGR; | ||
22 | case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB: | ||
23 | return CAIRO_SUBPIXEL_ORDER_VRGB; | ||
24 | case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR: | ||
25 | return CAIRO_SUBPIXEL_ORDER_VBGR; | ||
26 | default: | ||
27 | return CAIRO_SUBPIXEL_ORDER_DEFAULT; | ||
28 | } | ||
29 | return CAIRO_SUBPIXEL_ORDER_DEFAULT; | ||
30 | } | ||
31 | |||
16 | cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image, | 32 | cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image, |
17 | int width, int height) { | 33 | int width, int height) { |
18 | int image_width = cairo_image_surface_get_width(image); | 34 | int image_width = cairo_image_surface_get_width(image); |
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 | ||
11 | int escape_markup_text(const char *src, char *dest, int dest_length) { | 13 | size_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, "&"); |
19 | dest += sprintf(dest, "%s", "&"); | ||
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, "<"); |
27 | dest += sprintf(dest, "%s", "<"); | ||
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, ">"); |
35 | dest += sprintf(dest, "%s", ">"); | ||
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, "'"); |
43 | dest += sprintf(dest, "%s", "'"); | ||
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, """); |
51 | dest += sprintf(dest, "%s", """); | ||
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); |