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.
This commit is contained in:
Daniel Eklöf 2020-10-04 13:10:56 +02:00
parent 9102194846
commit 892730e5b9
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -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