From 1cba6ae0d947c1e3ac98f0e865096cbe1a4d6659 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 9 May 2016 23:55:13 -0400 Subject: fix glyphs in monospace fonts that are mysteriously not monospace really i should figure out how to scale these down, but this is sufficient for now --- src/display.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/display.c b/src/display.c index c140cb4..ffc5dac 100644 --- a/src/display.c +++ b/src/display.c @@ -22,6 +22,7 @@ static void runes_display_paint_rectangle( static void runes_display_draw_glyphs( RunesTerm *t, cairo_pattern_t *pattern, struct vt100_cell **cells, size_t len, int row, int col); +static int runes_display_glyphs_are_monospace(RunesTerm *t, int width); void runes_display_init(RunesDisplay *display, char *font_name) { @@ -392,6 +393,7 @@ static void runes_display_draw_glyphs( PangoAttrList *pango_attrs; char *buf; size_t buflen = 0, i; + int width = 0; for (i = 0; i < len; ++i) { buflen += cells[i]->len; @@ -401,10 +403,11 @@ static void runes_display_draw_glyphs( for (i = 0; i < len; ++i) { memcpy(&buf[buflen], cells[i]->contents, cells[i]->len); buflen += cells[i]->len; + width += cells[i]->is_wide ? 2 : 1; } pango_layout_set_text(display->layout, buf, buflen); - if (len > 1 && pango_layout_get_unknown_glyphs_count(display->layout)) { + if (len > 1 && !runes_display_glyphs_are_monospace(t, width)) { int c = col; for (i = 0; i < len; ++i) { runes_display_draw_glyphs(t, pattern, &cells[i], 1, row, c); @@ -433,3 +436,18 @@ static void runes_display_draw_glyphs( cairo_restore(display->cr); } } + +static int runes_display_glyphs_are_monospace(RunesTerm *t, int width) +{ + RunesDisplay *display = t->display; + int w, h; + + if (pango_layout_get_unknown_glyphs_count(display->layout) > 0) { + return 0; + } + pango_layout_get_pixel_size(display->layout, &w, &h); + if (w > display->fontx * width) { + return 0; + } + return 1; +} -- cgit v1.2.3-54-g00ecf