From a49dfaf26c5ad9b899c80a04c739571539d7efb6 Mon Sep 17 00:00:00 2001 From: Quentin Glidic Date: Fri, 27 Sep 2013 15:55:49 +0200 Subject: [PATCH] libi3/font: Draw the text at the expected place When drawing a text with Pango, shift it to the top according to the top if the glyph if taller than expected We always shift of (height - savedHeight) which is a no-op for normal glyphs Signed-off-by: Quentin Glidic --- libi3/font.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libi3/font.c b/libi3/font.c index 8239b1f4..c57009c0 100644 --- a/libi3/font.c +++ b/libi3/font.c @@ -86,16 +86,20 @@ static void draw_text_pango(const char *text, size_t text_len, root_visual_type, x + max_width, y + savedFont->height); cairo_t *cr = cairo_create(surface); PangoLayout *layout = pango_cairo_create_layout(cr); + gint height; + pango_layout_set_font_description(layout, savedFont->specific.pango_desc); pango_layout_set_width(layout, max_width * PANGO_SCALE); pango_layout_set_wrap(layout, PANGO_WRAP_CHAR); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); + pango_layout_set_text(layout, text, text_len); + /* Do the drawing */ cairo_set_source_rgb(cr, pango_font_red, pango_font_green, pango_font_blue); - cairo_move_to(cr, x, y); - pango_layout_set_text(layout, text, text_len); pango_cairo_update_layout(cr, layout); + pango_layout_get_pixel_size(layout, NULL, &height); + cairo_move_to(cr, x, y - (height - savedFont->height)); pango_cairo_show_layout(cr, layout); /* Free resources */ -- 2.39.5