]> git.sur5r.net Git - i3/i3/commitdiff
libi3/font: Draw the text at the expected place
authorQuentin Glidic <sardemff7+git@sardemff7.net>
Fri, 27 Sep 2013 13:55:49 +0000 (15:55 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 30 Sep 2013 20:51:52 +0000 (22:51 +0200)
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 <sardemff7+git@sardemff7.net>
libi3/font.c

index 8239b1f4414e8cc2ea6974c35da66c8042a7b6a4..c57009c062a686682c8f55e542cdcdbdd531d750 100644 (file)
@@ -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 */