From 69c3e744983e37662fa7b4f61482fb1d142e257c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 1 May 2020 11:46:24 +0200 Subject: util.h: new header file defining commonly used macros --- render.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 36d93be6..ccca05f1 100644 --- a/render.c +++ b/render.c @@ -21,14 +21,11 @@ #include "quirks.h" #include "selection.h" #include "shm.h" +#include "util.h" #define TIME_FRAME_RENDERING 0 #define TIME_SCROLL_DAMAGE 0 -#define ALEN(v) (sizeof(v) / sizeof((v)[0])) -#define min(x, y) ((x) < (y) ? (x) : (y)) -#define max(x, y) ((x) > (y) ? (x) : (y)) - struct renderer { struct fdm *fdm; struct wayland *wayl; -- cgit v1.3 From 76567e9ef0945c5ce86bb55097e6112a9b866948 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 1 May 2020 11:56:13 +0200 Subject: render: render combining characters This is basically just a loop that renders additional glyphs on top off the base glyph. Since we now need access to the row struct, for the combining characters, the function prototype for 'render_cell()' has changed. When rendering the combining characters we also need to deal with broken fonts; some fonts use positive offsets (as if the combining character was a regular character), while others use a negative offset (to be used as if you had already advanced the pen position). We handle both - a positive offset is rendered just like a regular glyph. When we see a negative offset we simply add the width of a cell first. --- render.c | 43 +++++++++++++++++++++++++++++++++---------- terminal.c | 2 +- terminal.h | 2 +- 3 files changed, 35 insertions(+), 12 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index ccca05f1..a87601d2 100644 --- a/render.c +++ b/render.c @@ -356,8 +356,9 @@ draw_cursor(const struct terminal *term, const struct cell *cell, static int render_cell(struct terminal *term, pixman_image_t *pix, - struct cell *cell, int col, int row, bool has_cursor) + struct row *row, int col, int row_no, bool has_cursor) { + struct cell *cell = &row->cells[col]; if (cell->attrs.clean) return 0; @@ -366,7 +367,7 @@ render_cell(struct terminal *term, pixman_image_t *pix, int width = term->cell_width; int height = term->cell_height; int x = term->margins.left + col * width; - int y = term->margins.top + row * height; + int y = term->margins.top + row_no * height; assert(cell->attrs.selected == 0 || cell->attrs.selected == 1); bool is_selected = cell->attrs.selected; @@ -441,6 +442,26 @@ render_cell(struct terminal *term, pixman_image_t *pix, } } + /* Combining characters */ + const struct combining_chars *comb_chars = &row->comb_chars[col]; + for (size_t i = 0; i < comb_chars->count; i++) { + const struct fcft_glyph *g = fcft_glyph_rasterize( + font, comb_chars->chars[i], term->font_subpixel); + + if (g == NULL) + continue; + + pixman_image_t *src = pixman_image_create_solid_fill(&fg); + pixman_image_composite32( + PIXMAN_OP_OVER, src, g->pix, pix, 0, 0, 0, 0, + /* Some fonts use a negative offset, while others use a + * "normal" offset */ + x + (g->x < 0 ? term->cell_width : 0) + g->x, + y + font_baseline(term) - g->y, + g->width, g->height); + pixman_image_unref(src); + } + /* Underline */ if (cell->attrs.underline) { draw_underline(term, pix, attrs_to_font(term, &cell->attrs), @@ -760,7 +781,7 @@ static void render_row(struct terminal *term, pixman_image_t *pix, struct row *row, int row_no) { for (int col = term->cols - 1; col >= 0; col--) - render_cell(term, pix, &row->cells[col], col, row_no, false); + render_cell(term, pix, row, col, row_no, false); } int @@ -1271,16 +1292,18 @@ grid_render(struct terminal *term) pixman_image_set_clip_region(buf->pix, &clip); /* Erase old cursor (if we rendered a cursor last time) */ - if (term->render.last_cursor.cell != NULL) { + if (term->render.last_cursor.row != NULL) { - struct cell *cell = term->render.last_cursor.cell; + struct row *row = term->render.last_cursor.row; struct coord at = term->render.last_cursor.in_view; - term->render.last_cursor.cell = NULL; + term->render.last_cursor.row = NULL; + + struct cell *cell = &row->cells[at.col]; /* If cell is already dirty, it will be rendered anyway */ if (cell->attrs.clean) { cell->attrs.clean = 0; - int cols = render_cell(term, buf->pix, cell, at.col, at.row, false); + int cols = render_cell(term, buf->pix, row, at.col, at.row, false); wl_surface_damage_buffer( term->window->surface, @@ -1408,9 +1431,9 @@ grid_render(struct terminal *term) struct cell *cell = &row->cells[term->grid->cursor.point.col]; cell->attrs.clean = 0; - term->render.last_cursor.cell = cell; + term->render.last_cursor.row = row; int cols_updated = render_cell( - term, buf->pix, cell, term->grid->cursor.point.col, view_aligned_row, true); + term, buf->pix, row, term->grid->cursor.point.col, view_aligned_row, true); wl_surface_damage_buffer( term->window->surface, @@ -1804,7 +1827,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) if (term->scroll_region.end >= old_rows) term->scroll_region.end = term->rows; - term->render.last_cursor.cell = NULL; + term->render.last_cursor.row = NULL; damage_view: if (!term->window->is_maximized && !term->window->is_fullscreen) { diff --git a/terminal.c b/terminal.c index 8e859a1e..bbbf2127 100644 --- a/terminal.c +++ b/terminal.c @@ -1319,7 +1319,7 @@ term_reset(struct terminal *term, bool hard) tll_free(term->normal.scroll_damage); tll_free(term->alt.damage); tll_free(term->alt.scroll_damage); - term->render.last_cursor.cell = NULL; + term->render.last_cursor.row = NULL; term->render.was_flashing = false; term_damage_all(term); } diff --git a/terminal.h b/terminal.h index e653e9be..27188cba 100644 --- a/terminal.h +++ b/terminal.h @@ -374,7 +374,7 @@ struct terminal { struct { struct coord actual; /* Absolute */ struct coord in_view; /* Offset by view */ - struct cell *cell; /* For easy access to content */ + struct row *row; /* Actual row TODO: remove */ } last_cursor; struct buffer *last_buf; /* Buffer we rendered to last time */ -- cgit v1.3 From 3474624c2c17058f0fd9f3f1821971e7213d285b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 1 May 2020 12:05:38 +0200 Subject: unicode-combining: completely remove unicode combining characters when feature is disabled --- grid.c | 8 ++++++++ render.c | 2 ++ selection.c | 10 ++++++++-- terminal.c | 3 +++ terminal.h | 5 +++++ 5 files changed, 26 insertions(+), 2 deletions(-) (limited to 'render.c') diff --git a/grid.c b/grid.c index 2a6b1073..22e4ecaf 100644 --- a/grid.c +++ b/grid.c @@ -34,12 +34,16 @@ grid_row_alloc(int cols, bool initialize) if (initialize) { row->cells = calloc(cols, sizeof(row->cells[0])); +#if FOOT_UNICODE_COMBINING row->comb_chars = calloc(cols, sizeof(row->comb_chars[0])); +#endif for (size_t c = 0; c < cols; c++) row->cells[c].attrs.clean = 1; } else { row->cells = malloc(cols * sizeof(row->cells[0])); +#if FOOT_UNICODE_COMBINING row->comb_chars = malloc(cols * sizeof(row->comb_chars[0])); +#endif } return row; @@ -51,7 +55,9 @@ grid_row_free(struct row *row) if (row == NULL) return; +#if FOOT_UNICODE_COMBINING free(row->comb_chars); +#endif free(row->cells); free(row); } @@ -208,6 +214,7 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols, new_row->cells[new_col_idx] = *old_cell; new_row->cells[new_col_idx].attrs.clean = 1; +#if FOOT_UNICODE_COMBINING struct combining_chars *old_comb_chars = &old_row->comb_chars[c - empty_count + i]; struct combining_chars *new_comb_chars @@ -216,6 +223,7 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols, new_comb_chars->count = old_comb_chars->count; for (size_t j = 0; j < ALEN(new_comb_chars->chars); j++) new_comb_chars->chars[j] = old_comb_chars->chars[j]; +#endif /* Translate tracking point(s) */ if (is_tracking_point && i >= empty_count) { diff --git a/render.c b/render.c index a87601d2..41b5c5b7 100644 --- a/render.c +++ b/render.c @@ -442,6 +442,7 @@ render_cell(struct terminal *term, pixman_image_t *pix, } } + #if FOOT_UNICODE_COMBINING /* Combining characters */ const struct combining_chars *comb_chars = &row->comb_chars[col]; for (size_t i = 0; i < comb_chars->count; i++) { @@ -461,6 +462,7 @@ render_cell(struct terminal *term, pixman_image_t *pix, g->width, g->height); pixman_image_unref(src); } +#endif /* Underline */ if (cell->attrs.underline) { diff --git a/selection.c b/selection.c index b84f4228..f9f7f6cd 100644 --- a/selection.c +++ b/selection.c @@ -142,8 +142,12 @@ min_bufsize_for_extraction(const struct terminal *term) { const struct coord *start = &term->selection.start; const struct coord *end = &term->selection.end; - const size_t chars_per_cell - = 1 + ALEN(term->grid->cur_row->comb_chars[0].chars); + const size_t chars_per_cell = +#if FOOT_UNICODE_COMBINING + 1 + ALEN(term->grid->cur_row->comb_chars[0].chars); +#else + 1; +#endif switch (term->selection.kind) { case SELECTION_NONE: @@ -237,12 +241,14 @@ extract_one(struct terminal *term, struct row *row, struct cell *cell, assert(ctx->idx + 1 <= ctx->size); ctx->buf[ctx->idx++] = cell->wc; +#if FOOT_UNICODE_COMBINING const struct combining_chars *comb_chars = &row->comb_chars[col]; assert(cell->wc != 0); assert(ctx->idx + comb_chars->count <= ctx->size); for (size_t i = 0; i < comb_chars->count; i++) ctx->buf[ctx->idx++] = comb_chars->chars[i]; +#endif ctx->last_row = row; ctx->last_cell = cell; diff --git a/terminal.c b/terminal.c index bbbf2127..9c3c24e8 100644 --- a/terminal.c +++ b/terminal.c @@ -2295,7 +2295,10 @@ term_print(struct terminal *term, wchar_t wc, int width) cell->wc = term->vt.last_printed = wc; cell->attrs = term->vt.attrs; +#if FOOT_UNICODE_COMBINING row->comb_chars[term->grid->cursor.point.col].count = 0; +#endif + row->dirty = true; cell->attrs.clean = 0; diff --git a/terminal.h b/terminal.h index b1f7ac8e..62c7e707 100644 --- a/terminal.h +++ b/terminal.h @@ -77,16 +77,21 @@ struct damage { int lines; }; +#if FOOT_UNICODE_COMBINING struct combining_chars { uint8_t count; wchar_t chars[2]; /* TODO: how many do we need? */ }; +#endif struct row { struct cell *cells; bool dirty; bool linebreak; + +#if FOOT_UNICODE_COMBINING struct combining_chars *comb_chars; +#endif }; struct sixel { -- cgit v1.3