From 6cf86d67d9fafe6ac4efc2626e2f0174c938f35f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 3 Oct 2020 22:41:20 +0200 Subject: term: re-calculate sixel images’ rows/cols values when cell size changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- terminal.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 077d15f0..a286161f 100644 --- a/terminal.c +++ b/terminal.c @@ -1526,6 +1526,20 @@ term_font_size_adjust(struct terminal *term, double amount) * So we delete them. */ sixel_destroy_all(term); + } else if (term->cell_width != old_cell_width || + term->cell_height != old_cell_height) + { + tll_foreach(term->normal.sixel_images, it) { + struct sixel *six = &it->item; + six->rows = (six->height + term->cell_height - 1) / term->cell_height; + six->cols = (six->width + term->cell_width - 1) / term->cell_width; + } + + tll_foreach(term->alt.sixel_images, it) { + struct sixel *six = &it->item; + six->rows = (six->height + term->cell_height - 1) / term->cell_height; + six->cols = (six->width + term->cell_width - 1) / term->cell_width; + } } return true; } -- cgit v1.3 From 892730e5b94723304f9ee8a01c681733e02b2e1e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 4 Oct 2020 13:10:56 +0200 Subject: term: update sixel rows/cols *after* cell dimension change, *before* resize This fixes an issue where we resized+reflowed with bad rows/cols values in the sixels. --- terminal.c | 66 +++++++++++++++++++++++++------------------------------------- 1 file changed, 27 insertions(+), 39 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index a286161f..0afe39d5 100644 --- a/terminal.c +++ b/terminal.c @@ -605,12 +605,38 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4]) term->fonts[i] = fonts[i]; } + const int old_cell_width = term->cell_width; + const int old_cell_height = term->cell_height; + term->cell_width = term->fonts[0]->space_advance.x > 0 ? term->fonts[0]->space_advance.x : term->fonts[0]->max_advance.x; term->cell_height = max(term->fonts[0]->height, term->fonts[0]->ascent + term->fonts[0]->descent); LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height); + if (term->cell_width < old_cell_width || + term->cell_height < old_cell_height) + { + /* + * The cell size has decreased. + * + * This means sixels, which we cannot resize, no longer fit + * into their "allocated" grid space. + * + * To be able to fit them, we would have to change the grid + * content. Inserting empty lines _might_ seem acceptable, but + * we'd also need to insert empty columns, which would break + * existing layout completely. + * + * So we delete them. + */ + sixel_destroy_all(term); + } else if (term->cell_width != old_cell_width || + term->cell_height != old_cell_height) + { + sixel_cell_size_changed(term); + } + /* Use force, since cell-width/height may have changed */ render_resize_force(term, term->width / term->scale, term->height / term->scale); return true; @@ -1503,45 +1529,7 @@ term_font_size_adjust(struct terminal *term, double amount) term->font_sizes[i].px_size = -1; } - const int old_cell_width = term->cell_width; - const int old_cell_height = term->cell_height; - - if (!reload_fonts(term)) - return false; - - if (term->cell_width < old_cell_width || - term->cell_height < old_cell_height) - { - /* - * The cell size has decreased. - * - * This means sixels, which we cannot resize, no longer fit - * into their "allocated" grid space. - * - * To be able to fit them, we would have to change the grid - * content. Inserting empty lines _might_ seem acceptable, but - * we'd also need to insert empty columns, which would break - * existing layout completely. - * - * So we delete them. - */ - sixel_destroy_all(term); - } else if (term->cell_width != old_cell_width || - term->cell_height != old_cell_height) - { - tll_foreach(term->normal.sixel_images, it) { - struct sixel *six = &it->item; - six->rows = (six->height + term->cell_height - 1) / term->cell_height; - six->cols = (six->width + term->cell_width - 1) / term->cell_width; - } - - tll_foreach(term->alt.sixel_images, it) { - struct sixel *six = &it->item; - six->rows = (six->height + term->cell_height - 1) / term->cell_height; - six->cols = (six->width + term->cell_width - 1) / term->cell_width; - } - } - return true; + return reload_fonts(term); } bool -- cgit v1.3