aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-05-09 23:55:13 -0400
committerJesse Luehrs <doy@tozt.net>2016-05-09 23:55:13 -0400
commit1cba6ae0d947c1e3ac98f0e865096cbe1a4d6659 (patch)
tree700712564419684c3ffddeccb5573f6c21d1d631
parentdfd052f13e1deb1b9a42a24a7d698286c5aff1d4 (diff)
downloadrunes-1cba6ae0d947c1e3ac98f0e865096cbe1a4d6659.tar.gz
runes-1cba6ae0d947c1e3ac98f0e865096cbe1a4d6659.zip
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
-rw-r--r--src/display.c20
1 files changed, 19 insertions, 1 deletions
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;
+}