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, double width = cairo_image_surface_get_width(image); double height = cairo_image_surface_get_height(image); + cairo_save(cairo); switch (mode) { case BACKGROUND_MODE_STRETCH: cairo_scale(cairo, @@ -116,4 +117,5 @@ void render_background_image(cairo_t *cairo, cairo_surface_t *image, break; } cairo_paint(cairo); + cairo_restore(cairo); } 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) { (color >> (0*8) & 0xFF) / 255.0); } +cairo_subpixel_order_t to_cairo_subpixel_order(enum wl_output_subpixel subpixel) { + switch (subpixel) { + case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB: + return CAIRO_SUBPIXEL_ORDER_RGB; + case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR: + return CAIRO_SUBPIXEL_ORDER_BGR; + case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB: + return CAIRO_SUBPIXEL_ORDER_VRGB; + case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR: + return CAIRO_SUBPIXEL_ORDER_VBGR; + default: + return CAIRO_SUBPIXEL_ORDER_DEFAULT; + } + return CAIRO_SUBPIXEL_ORDER_DEFAULT; +} + cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image, int width, int height) { 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 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "cairo.h" #include "log.h" +#include "stringop.h" -int escape_markup_text(const char *src, char *dest, int dest_length) { - int length = 0; +size_t escape_markup_text(const char *src, char *dest) { + size_t length = 0; + if (dest) { + dest[0] = '\0'; + } while (src[0]) { switch (src[0]) { case '&': length += 5; - if (dest && dest_length - length >= 0) { - dest += sprintf(dest, "%s", "&"); - } else { - dest_length = -1; - } + lenient_strcat(dest, "&"); break; case '<': length += 4; - if (dest && dest_length - length >= 0) { - dest += sprintf(dest, "%s", "<"); - } else { - dest_length = -1; - } + lenient_strcat(dest, "<"); break; case '>': length += 4; - if (dest && dest_length - length >= 0) { - dest += sprintf(dest, "%s", ">"); - } else { - dest_length = -1; - } + lenient_strcat(dest, ">"); break; case '\'': length += 6; - if (dest && dest_length - length >= 0) { - dest += sprintf(dest, "%s", "'"); - } else { - dest_length = -1; - } + lenient_strcat(dest, "'"); break; case '"': length += 6; - if (dest && dest_length - length >= 0) { - dest += sprintf(dest, "%s", """); - } else { - dest_length = -1; - } + lenient_strcat(dest, """); break; default: - length += 1; - if (dest && dest_length - length >= 0) { - *(dest++) = *src; - } else { - dest_length = -1; + if (dest) { + dest[length] = *src; + dest[length + 1] = '\0'; } + length += 1; } src++; } - // if we could not fit the escaped string in dest, return -1 - if (dest && dest_length == -1) { - return -1; - } return length; } @@ -78,7 +58,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, char *buf; GError *error = NULL; if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) { - pango_layout_set_markup(layout, buf, -1); + pango_layout_set_text(layout, buf, -1); free(buf); } else { wlr_log(WLR_ERROR, "pango_parse_markup '%s' -> error %s", text, @@ -134,6 +114,10 @@ void pango_printf(cairo_t *cairo, const char *font, va_end(args); PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); + cairo_font_options_t *fo = cairo_font_options_create(); + cairo_get_font_options(cairo, fo); + pango_cairo_context_set_font_options(pango_layout_get_context(layout), fo); + cairo_font_options_destroy(fo); pango_cairo_update_layout(cairo, layout); pango_cairo_show_layout(cairo, layout); g_object_unref(layout); |