term: font_size_adjust: use DPI=96 when font is *not* scaled by DPI

Closes #842
This commit is contained in:
Daniel Eklöf 2021-12-14 17:45:12 +01:00
parent 3e5a9aa904
commit a098fad004
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 14 additions and 8 deletions

View file

@ -48,6 +48,12 @@
### Deprecated
### Removed
### Fixed
* Font size adjustment (“zooming”) when font is configured with a
**pixelsize**, and `dpi-aware=no`
(https://codeberg.org/dnkl/foot/issues/842).
### Security
### Contributors

View file

@ -1917,11 +1917,13 @@ term_font_size_adjust(struct terminal *term, double amount)
{
const struct config *conf = term->conf;
const float dpi = term->font_is_sized_by_dpi ? term->font_dpi : 96.;
for (size_t i = 0; i < 4; i++) {
const struct config_font_list *font_list = &conf->fonts[i];
for (size_t j = 0; j < font_list->count; j++) {
double old_pt_size = term->font_sizes[i][j].pt_size;
float old_pt_size = term->font_sizes[i][j].pt_size;
/*
* To ensure primary and user-configured fallback fonts are
@ -1929,23 +1931,21 @@ term_font_size_adjust(struct terminal *term, double amount)
* sizes, and to the adjustment on point sizes only.
*/
if (term->font_sizes[i][j].px_size > 0) {
double dpi = term->font_dpi;
if (term->font_sizes[i][j].px_size > 0)
old_pt_size = term->font_sizes[i][j].px_size * 72. / dpi;
}
term->font_sizes[i][j].pt_size = fmax(old_pt_size + amount, 0);
term->font_sizes[i][j].pt_size = fmaxf(old_pt_size + amount, 0.);
term->font_sizes[i][j].px_size = -1;
}
}
if (term->font_line_height.px >= 0) {
double old_pt_size = term->font_line_height.px > 0
? term->font_line_height.px * 72. / term->font_dpi
float old_pt_size = term->font_line_height.px > 0
? term->font_line_height.px * 72. / dpi
: term->font_line_height.pt;
term->font_line_height.px = 0;
term->font_line_height.pt = fmax(old_pt_size + amount, 0);
term->font_line_height.pt = fmaxf(old_pt_size + amount, 0.);
}
return reload_fonts(term);