From c3ea956837c31492b956cd9ab4b34ec6ac512628 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Sun, 14 Jul 2024 08:55:30 +0100 Subject: [PATCH] Disable pango glyph position rounding Chase https://github.com/swaywm/sway/commit/8c5b23e592d2334b3324227dd9d1311e46c5fd69 Pango rounds glyph position and widths to nearest integer, which leads to font dimensions jumping around when rendering with a scale, causing text geometry to jump around when changing scale. Disable this rounding to make the geometry stable. --- src/common/font.c | 2 ++ src/osd.c | 1 + src/workspaces.c | 1 + 3 files changed, 4 insertions(+) diff --git a/src/common/font.c b/src/common/font.c index c9e6166c..6e12e780 100644 --- a/src/common/font.c +++ b/src/common/font.c @@ -40,6 +40,7 @@ font_extents(struct font *font, const char *string) surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); c = cairo_create(surface); layout = pango_cairo_create_layout(c); + pango_context_set_round_glyph_positions(pango_layout_get_context(layout), false); PangoFontDescription *desc = font_to_pango_desc(font); pango_layout_set_font_description(layout, desc); @@ -137,6 +138,7 @@ font_buffer_create(struct lab_data_buffer **buffer, int max_width, cairo_move_to(cairo, 0, 0); PangoLayout *layout = pango_cairo_create_layout(cairo); + pango_context_set_round_glyph_positions(pango_layout_get_context(layout), false); pango_layout_set_width(layout, text_extents.width * PANGO_SCALE); pango_layout_set_text(layout, text, -1); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); diff --git a/src/osd.c b/src/osd.c index 9555d913..91dbd270 100644 --- a/src/osd.c +++ b/src/osd.c @@ -225,6 +225,7 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h, /* Set up text rendering */ set_cairo_color(cairo, theme->osd_label_text_color); PangoLayout *layout = pango_cairo_create_layout(cairo); + pango_context_set_round_glyph_positions(pango_layout_get_context(layout), false); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); PangoFontDescription *desc = font_to_pango_desc(&rc.font_osd); diff --git a/src/workspaces.c b/src/workspaces.c index 0fcef01a..76dc93d6 100644 --- a/src/workspaces.c +++ b/src/workspaces.c @@ -124,6 +124,7 @@ _osd_update(struct server *server) /* Text */ set_cairo_color(cairo, server->theme->osd_label_text_color); PangoLayout *layout = pango_cairo_create_layout(cairo); + pango_context_set_round_glyph_positions(pango_layout_get_context(layout), false); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); /* Center workspace indicator on the x axis */