libi3/font: Draw the text at the expected place
Patch status: merged
Patch by Quentin Glidic
Long description:
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>
To apply this patch, use:
curl http://cr.i3wm.org/patch/241/raw.patch | git am
b/libi3/font.c
18 |
@@ -86,16 +86,20 @@ static void draw_text_pango(const char *text, size_t text_len, |
19 |
root_visual_type, x + max_width, y + savedFont->height); |
20 |
cairo_t *cr = cairo_create(surface); |
21 |
PangoLayout *layout = pango_cairo_create_layout(cr); |
22 |
+ gint height; |
23 |
+ |
24 |
pango_layout_set_font_description(layout, savedFont->specific.pango_desc); |
25 |
pango_layout_set_width(layout, max_width * PANGO_SCALE); |
26 |
pango_layout_set_wrap(layout, PANGO_WRAP_CHAR); |
27 |
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); |
28 |
|
29 |
+ pango_layout_set_text(layout, text, text_len); |
30 |
+ |
31 |
/* Do the drawing */ |
32 |
cairo_set_source_rgb(cr, pango_font_red, pango_font_green, pango_font_blue); |
33 |
- cairo_move_to(cr, x, y); |
34 |
- pango_layout_set_text(layout, text, text_len); |
35 |
pango_cairo_update_layout(cr, layout); |
36 |
+ pango_layout_get_pixel_size(layout, NULL, &height); |
37 |
+ cairo_move_to(cr, x, y - (height - savedFont->height)); |
38 |
pango_cairo_show_layout(cr, layout); |
39 |
|
40 |
/* Free resources */ |