diff options
author | John Chen <johnchen902@gmail.com> | 2018-12-30 21:29:37 +0800 |
---|---|---|
committer | Brian Ashworth <RedSoxFan@users.noreply.github.com> | 2018-12-31 01:37:33 -0500 |
commit | 54d0f3a40e3b65375046932b5cc21aba10b62f0f (patch) | |
tree | 0b295937f4254ca4c7d9fd3d58e05775e72c4e85 /sway/tree/container.c | |
parent | 828060af73dd2f3138ad9d1bf743f57dd567723c (diff) |
Set font options when computing text width.
Fix #2869
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 0a96088e..99262356 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -453,19 +453,26 @@ static void update_title_texture(struct sway_container *con, int width = 0; int height = con->title_height * scale; - cairo_t *c = cairo_create(NULL); + // We must use a non-nil cairo_t for cairo_set_font_options to work. + // Therefore, we cannot use cairo_create(NULL). + cairo_surface_t *dummy_surface = cairo_image_surface_create( + CAIRO_FORMAT_ARGB32, 0, 0); + cairo_t *c = cairo_create(dummy_surface); + cairo_set_antialias(c, CAIRO_ANTIALIAS_BEST); + cairo_font_options_t *fo = cairo_font_options_create(); + cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL); + cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_SUBPIXEL); + cairo_font_options_set_subpixel_order(fo, to_cairo_subpixel_order(output->wlr_output->subpixel)); + cairo_set_font_options(c, fo); get_text_size(c, config->font, &width, NULL, NULL, scale, config->pango_markup, "%s", con->formatted_title); + cairo_surface_destroy(dummy_surface); cairo_destroy(c); cairo_surface_t *surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width, height); cairo_t *cairo = cairo_create(surface); cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST); - cairo_font_options_t *fo = cairo_font_options_create(); - cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL); - cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_SUBPIXEL); - cairo_font_options_set_subpixel_order(fo, to_cairo_subpixel_order(output->wlr_output->subpixel)); cairo_set_font_options(cairo, fo); cairo_font_options_destroy(fo); cairo_set_source_rgba(cairo, class->background[0], class->background[1], |