aboutsummaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-30 16:04:28 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-30 16:04:28 +0000
commit73b4d5d05ab3d3059017a0d3e2a5c798a241da87 (patch)
treef4d7bc75128f8cf061493467954a1805fedd9a03 /render.c
parentrender: add a 'clean' bit to each cell; only render cells that aren't clean (diff)
font: add support for fallback fonts
A top-level font now has a list of fallback fonts. When a glyph cannot be found, we try each fallback font in turn, until we either find one that has the glyph, or until we've exhausted the list. To make this actually work in practise (read: to make performance acceptable), the cache is re-worked and is now populated on demand. It also supports non-ASCII characters, by using the 4-byte unicode character as index instead. Since having an array that can be indexed by a 4-byte value isn't really viable, we now have a simple hash table instead of an array.
Diffstat (limited to 'render.c')
-rw-r--r--render.c50
1 files changed, 14 insertions, 36 deletions
diff --git a/render.c b/render.c
index 60aa43b4..b2d6c16e 100644
--- a/render.c
+++ b/render.c
@@ -273,38 +273,12 @@ render_cell(struct terminal *term, struct buffer *buf, size_t buf_idx,
}
struct font *font = attrs_to_font(term, &cell->attrs);
-
- struct glyph *glyph = NULL;
- if (strnlen(cell->c, 4) == 1) {
- if (font->cache[(unsigned char)cell->c[0]].surf != NULL)
- glyph = &font->cache[(unsigned char)cell->c[0]];
- }
-
- struct glyph _glyph;
- if (glyph == NULL) {
- if (!font_glyph_for_utf8(font, cell->c, &_glyph)) {
- LOG_ERR("FAILED: %.4s", cell->c);
- return;
- }
- glyph = &_glyph;
- }
-
- assert(glyph != NULL);
- cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
- cairo_set_source_rgb(cr, fg.r, fg.g, fg.b);
-
-#if 0
- cairo_surface_t *surf = cairo_image_surface_create_for_data(
- glyph->data, glyph->format, glyph->width, glyph->height, glyph->stride);
- cairo_mask_surface(cr, surf, x + glyph->left, y + term->fextents.ascent - glyph->top);
- cairo_surface_destroy(surf);
-#else
- cairo_mask_surface(cr, glyph->surf, x + glyph->left, y + term->fextents.ascent - glyph->top);
-#endif
-
- if (glyph == &_glyph) {
- cairo_surface_destroy(_glyph.surf);
- free(_glyph.data);
+ const struct glyph *glyph = font_glyph_for_utf8(font, cell->c);
+ if (glyph != NULL) {
+ cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+ cairo_set_source_rgb(cr, fg.r, fg.g, fg.b);
+ cairo_mask_surface(
+ cr, glyph->surf, x + glyph->left, y + term->fextents.ascent - glyph->top);
}
}
@@ -456,9 +430,12 @@ grid_render(struct terminal *term)
/* Erase old cursor (if we rendered a cursor last time) */
if (term->render.last_cursor.cell != NULL) {
+ struct cell *hack = (struct cell *)term->render.last_cursor.cell;
+ hack->attrs.clean = 0;
render_cell(
term, buf, 0,
- term->render.last_cursor.cell,
+ //term->render.last_cursor.cell,
+ hack,
term->render.last_cursor.in_view.col,
term->render.last_cursor.in_view.row, false);
@@ -622,11 +599,12 @@ grid_render(struct terminal *term)
term->cursor.col, view_aligned_row};
struct row *row = grid_row_in_view(term->grid, view_aligned_row);
+ struct cell *cell = &row->cells[term->cursor.col];
- term->render.last_cursor.cell = &row->cells[term->cursor.col];
+ cell->attrs.clean = 0;
+ term->render.last_cursor.cell = cell;
render_cell(
- term, buf, 0, term->render.last_cursor.cell,
- term->cursor.col, view_aligned_row, true);
+ term, buf, 0, cell, term->cursor.col, view_aligned_row, true);
wl_surface_damage_buffer(
term->wl.surface,