From 90bfcc1fbd8bb53508dc93405add1d8aacb4e7ed Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 30 Nov 2019 14:53:22 +0100 Subject: render: fix underline/strikeout positioning There were two errors: * We subtracted half the line width instead of adding it to the baseline * We rounded the line positioning and thickness before the positioning calculation. In particular, rounding the thickness before using it to adjust the position was wrong. Now we round just before the pixman call. --- render.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index f74c5fac..b90b27e8 100644 --- a/render.c +++ b/render.c @@ -105,12 +105,13 @@ draw_underline(const struct terminal *term, pixman_image_t *pix, const pixman_color_t *color, int x, int y, int cols) { int baseline = y + font_baseline(term); - int width = font->underline.thickness; - int y_under = baseline - font->underline.position - width / 2; + double width = font->underline.thickness; + int y_under = floor(baseline - font->underline.position + width / 2.); pixman_image_fill_rectangles( PIXMAN_OP_SRC, pix, color, - 1, &(pixman_rectangle16_t){x, y_under, cols * term->cell_width, width}); + 1, &(pixman_rectangle16_t){ + x, y_under, cols * term->cell_width, round(max(1., width))}); } static void @@ -119,12 +120,13 @@ draw_strikeout(const struct terminal *term, pixman_image_t *pix, const pixman_color_t *color, int x, int y, int cols) { int baseline = y + font_baseline(term); - int width = font->strikeout.thickness; - int y_strike = baseline - font->strikeout.position - width / 2; + double width = font->strikeout.thickness; + int y_strike = floor(baseline - font->strikeout.position + width / 2.); pixman_image_fill_rectangles( PIXMAN_OP_SRC, pix, color, - 1, &(pixman_rectangle16_t){x, y_strike, cols * term->cell_width, width}); + 1, &(pixman_rectangle16_t){ + x, y_strike, cols * term->cell_width, round(max(1., width))}); } static bool -- cgit v1.3