diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-06-24 15:50:55 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-06-24 15:50:55 +0000 |
| commit | 80c2d9d89df11c5830de900f98b5d9f3f406a1c1 (patch) | |
| tree | a27132ebbd0940872c16afd3f48f4ee791820a0a /render.c | |
| parent | Merge branch 'sixel-heap-user-after-free-after-blending' (diff) | |
| parent | client: add +/-graphemes to version output (diff) | |
Merge branch 'harfbuzz'
Diffstat (limited to 'render.c')
| -rw-r--r-- | render.c | 137 |
1 files changed, 95 insertions, 42 deletions
@@ -449,8 +449,8 @@ 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_no * height; + const int x = term->margins.left + col * width; + const int y = term->margins.top + row_no * height; xassert(cell->attrs.selected == 0 || cell->attrs.selected == 1); bool is_selected = cell->attrs.selected; @@ -500,19 +500,16 @@ render_cell(struct terminal *term, pixman_image_t *pix, } struct fcft_font *font = attrs_to_font(term, &cell->attrs); - const struct fcft_glyph *glyph = NULL; const struct composed *composed = NULL; + const struct fcft_grapheme *grapheme = NULL; + const struct fcft_glyph *single = NULL; + const struct fcft_glyph **glyphs = NULL; + unsigned glyph_count = 0; wchar_t base = cell->wc; + int cell_cols = 1; if (base != 0) { - if (base >= CELL_COMB_CHARS_LO && - base < (CELL_COMB_CHARS_LO + term->composed_count)) - { - composed = &term->composed[base - CELL_COMB_CHARS_LO]; - base = composed->base; - } - if (unlikely( /* Classic box drawings */ (base >= 0x2500 && base <= 0x259f) || @@ -528,7 +525,7 @@ render_cell(struct terminal *term, pixman_image_t *pix, (base >= 0x1fb00 && base <= 0x1fb3b) || /* Unicode 13 partial blocks */ - /* TODO: there's more here! */ + /* TODO: there's more here! */ (base >= 0x1fb70 && base <= 0x1fb8b)) && likely(!term->conf->box_drawings_uses_font_glyphs)) @@ -542,7 +539,7 @@ render_cell(struct terminal *term, pixman_image_t *pix, xassert(idx < ALEN(term->box_drawing)); if (likely(term->box_drawing[idx] != NULL)) - glyph = term->box_drawing[idx]; + single = term->box_drawing[idx]; else { mtx_lock(&term->render.workers.lock); @@ -551,15 +548,54 @@ render_cell(struct terminal *term, pixman_image_t *pix, term->box_drawing[idx] = box_drawing(term, base); mtx_unlock(&term->render.workers.lock); - glyph = term->box_drawing[idx]; - xassert(glyph != NULL); + single = term->box_drawing[idx]; + xassert(single != NULL); } - } else - glyph = fcft_glyph_rasterize(font, base, term->font_subpixel); + + glyph_count = 1; + glyphs = &single; + cell_cols = single->cols; + } + + else if (base >= CELL_COMB_CHARS_LO && base <= CELL_COMB_CHARS_HI) + { + composed = composed_lookup(term->composed, base - CELL_COMB_CHARS_LO); + base = composed->chars[0]; + + if (term->conf->can_shape_grapheme && term->conf->tweak.grapheme_shaping) { + grapheme = fcft_grapheme_rasterize( + font, composed->count, composed->chars, + 0, NULL, term->font_subpixel); + } + + if (grapheme != NULL) { + cell_cols = composed->width; + + composed = NULL; + glyphs = grapheme->glyphs; + glyph_count = grapheme->count; + } + } + + + if (single == NULL && grapheme == NULL) { + xassert(base != 0); + single = fcft_glyph_rasterize(font, base, term->font_subpixel); + if (single == NULL) { + glyph_count = 0; + cell_cols = 1; + } else { + glyph_count = 1; + glyphs = &single; + cell_cols = single->cols; + } + } } + assert(glyph_count == 0 || glyphs != NULL); + const int cols_left = term->cols - col; - int cell_cols = glyph != NULL ? max(1, min(glyph->cols, cols_left)) : 1; + cell_cols = max(1, min(cell_cols, cols_left)); /* * Hack! @@ -580,10 +616,10 @@ render_cell(struct terminal *term, pixman_image_t *pix, * - *this* cells is followed by an empty cell, or a space */ if (term->conf->tweak.allow_overflowing_double_width_glyphs && - ((glyph != NULL && - glyph->cols == 1 && - glyph->width >= term->cell_width * 15 / 10 && - glyph->width < 3 * term->cell_width && + ((glyph_count > 0 && + glyphs[0]->cols == 1 && + glyphs[0]->width >= term->cell_width * 15 / 10 && + glyphs[0]->width < 3 * term->cell_width && col < term->cols - 1) || (term->conf->tweak.pua_double_width && ((base >= 0x00e000 && base <= 0x00f8ff) || @@ -632,33 +668,44 @@ render_cell(struct terminal *term, pixman_image_t *pix, pixman_image_t *clr_pix = pixman_image_create_solid_fill(&fg); - if (glyph != NULL) { - const int letter_x_ofs = term->font_x_ofs; + int pen_x = x; + for (unsigned i = 0; i < glyph_count; i++) { + const int letter_x_ofs = i == 0 ? term->font_x_ofs : 0; + + const struct fcft_glyph *glyph = glyphs[i]; + if (glyph == NULL) + continue; + + int g_x = glyph->x; + int g_y = glyph->y; + + if (i > 0 && glyph->x >= 0) + g_x -= term->cell_width; if (unlikely(pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8)) { /* Glyph surface is a pre-rendered image (typically a color emoji...) */ if (!(cell->attrs.blink && term->blink.state == BLINK_OFF)) { pixman_image_composite32( PIXMAN_OP_OVER, glyph->pix, NULL, pix, 0, 0, 0, 0, - x + letter_x_ofs + glyph->x, y + font_baseline(term) - glyph->y, + pen_x + letter_x_ofs + g_x, y + font_baseline(term) - g_y, glyph->width, glyph->height); } } else { pixman_image_composite32( PIXMAN_OP_OVER, clr_pix, glyph->pix, pix, 0, 0, 0, 0, - x + letter_x_ofs + glyph->x, y + font_baseline(term) - glyph->y, + pen_x + letter_x_ofs + g_x, y + font_baseline(term) - g_y, glyph->width, glyph->height); - } + /* Combining characters */ + if (composed != NULL) { + assert(glyph_count == 1); - /* Combining characters */ - if (composed != NULL) { - for (size_t i = 0; i < composed->count; i++) { - const struct fcft_glyph *g = fcft_glyph_rasterize( - font, composed->combining[i], term->font_subpixel); + for (size_t i = 1; i < composed->count; i++) { + const struct fcft_glyph *g = fcft_glyph_rasterize( + font, composed->chars[i], term->font_subpixel); - if (g == NULL) - continue; + if (g == NULL) + continue; /* * Fonts _should_ assume the pen position is now @@ -677,16 +724,22 @@ render_cell(struct terminal *term, pixman_image_t *pix, * somewhat deal with double-width glyphs we use * an offset of *one* cell. */ - int x_ofs = g->x < 0 - ? cell_cols * term->cell_width - : (cell_cols - 1) * term->cell_width; + int x_ofs = g->x < 0 + ? cell_cols * term->cell_width + : (cell_cols - 1) * term->cell_width; - pixman_image_composite32( - PIXMAN_OP_OVER, clr_pix, g->pix, pix, 0, 0, 0, 0, - x + letter_x_ofs + x_ofs + g->x, y + font_baseline(term) - g->y, - g->width, g->height); + pixman_image_composite32( + PIXMAN_OP_OVER, clr_pix, g->pix, pix, 0, 0, 0, 0, + /* Some fonts use a negative offset, while others use a + * "normal" offset */ + pen_x + x_ofs + g->x, + y + font_baseline(term) - g->y, + g->width, g->height); + } } } + + pen_x += glyph->advance.x; } pixman_image_unref(clr_pix); @@ -3285,8 +3338,8 @@ maybe_resize(struct terminal *term, int width, int height, bool force) /* Resize grids */ grid_resize_and_reflow( &term->normal, new_normal_grid_rows, new_cols, old_rows, new_rows, - term->selection.end.row >= 0 ? ALEN(tracking_points) : 0, tracking_points, - term->composed_count, term->composed); + term->selection.end.row >= 0 ? ALEN(tracking_points) : 0, + tracking_points); grid_resize_without_reflow( &term->alt, new_alt_grid_rows, new_cols, old_rows, new_rows); |
