term: store current font DPI as a float instead of an integer

FontConfig's DPI is a double, and using a float instead of an integer
results in higher resolution.
This commit is contained in:
Daniel Eklöf 2020-07-26 07:45:03 +02:00
parent e955a14dd0
commit b08db1ef97
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 12 additions and 12 deletions

View file

@ -559,7 +559,7 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4])
return true; return true;
} }
static unsigned static float
get_font_dpi(const struct terminal *term) get_font_dpi(const struct terminal *term)
{ {
/* /*
@ -584,7 +584,7 @@ get_font_dpi(const struct terminal *term)
*/ */
/* Use highest DPI from outputs we're mapped on */ /* Use highest DPI from outputs we're mapped on */
unsigned dpi = 0; double dpi = 0.0;
assert(term->window != NULL); assert(term->window != NULL);
tll_foreach(term->window->on_outputs, it) { tll_foreach(term->window->on_outputs, it) {
if (it->item->ppi.scaled.y > dpi) if (it->item->ppi.scaled.y > dpi)
@ -592,7 +592,7 @@ get_font_dpi(const struct terminal *term)
} }
/* If we're not mapped, use DPI from first monitor. Hopefully this is where we'll get mapped later... */ /* If we're not mapped, use DPI from first monitor. Hopefully this is where we'll get mapped later... */
if (dpi == 0) { if (dpi == 0.) {
tll_foreach(term->wl->monitors, it) { tll_foreach(term->wl->monitors, it) {
dpi = it->item.ppi.scaled.y * term->scale; dpi = it->item.ppi.scaled.y * term->scale;
break; break;
@ -601,7 +601,7 @@ get_font_dpi(const struct terminal *term)
if (dpi == 0) { if (dpi == 0) {
/* No monitors? */ /* No monitors? */
dpi = 96; dpi = 96.;
} }
return dpi; return dpi;
@ -692,10 +692,10 @@ reload_fonts(struct terminal *term)
} }
char attrs0[256], attrs1[256], attrs2[256], attrs3[256]; char attrs0[256], attrs1[256], attrs2[256], attrs3[256];
snprintf(attrs0, sizeof(attrs0), "dpi=%u", term->font_dpi); snprintf(attrs0, sizeof(attrs0), "dpi=%.2f", term->font_dpi);
snprintf(attrs1, sizeof(attrs1), "dpi=%u:weight=bold", term->font_dpi); snprintf(attrs1, sizeof(attrs1), "dpi=%.2f:weight=bold", term->font_dpi);
snprintf(attrs2, sizeof(attrs2), "dpi=%u:slant=italic", term->font_dpi); snprintf(attrs2, sizeof(attrs2), "dpi=%.2f:slant=italic", term->font_dpi);
snprintf(attrs3, sizeof(attrs3), "dpi=%u:weight=bold:slant=italic", term->font_dpi); snprintf(attrs3, sizeof(attrs3), "dpi=%.2f:weight=bold:slant=italic", term->font_dpi);
struct fcft_font *fonts[4]; struct fcft_font *fonts[4];
struct font_load_data data[4] = { struct font_load_data data[4] = {
@ -836,7 +836,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
.ptmx = ptmx, .ptmx = ptmx,
.ptmx_buffer = tll_init(), .ptmx_buffer = tll_init(),
.font_sizes = malloc(sizeof(term->font_sizes[0]) * tll_length(conf->fonts)), .font_sizes = malloc(sizeof(term->font_sizes[0]) * tll_length(conf->fonts)),
.font_dpi = 0, .font_dpi = 0.,
.font_subpixel = (conf->colors.alpha == 0xffff /* Can't do subpixel rendering on transparent background */ .font_subpixel = (conf->colors.alpha == 0xffff /* Can't do subpixel rendering on transparent background */
? FCFT_SUBPIXEL_DEFAULT ? FCFT_SUBPIXEL_DEFAULT
: FCFT_SUBPIXEL_NONE), : FCFT_SUBPIXEL_NONE),
@ -1490,11 +1490,11 @@ term_font_size_reset(struct terminal *term)
bool bool
term_font_dpi_changed(struct terminal *term) term_font_dpi_changed(struct terminal *term)
{ {
unsigned dpi = get_font_dpi(term); float dpi = get_font_dpi(term);
if (dpi == term->font_dpi) if (dpi == term->font_dpi)
return true; return true;
LOG_DBG("DPI changed (%u -> %u): reloading fonts", term->font_dpi, dpi); LOG_DBG("DPI changed (%.2f -> %.2f): reloading fonts", term->font_dpi, dpi);
term->font_dpi = dpi; term->font_dpi = dpi;
return reload_fonts(term); return reload_fonts(term);

View file

@ -223,7 +223,7 @@ struct terminal {
struct fcft_font *fonts[4]; struct fcft_font *fonts[4];
struct config_font *font_sizes; struct config_font *font_sizes;
int font_dpi; float font_dpi;
enum fcft_subpixel font_subpixel; enum fcft_subpixel font_subpixel;
tll(struct ptmx_buffer) ptmx_buffer; tll(struct ptmx_buffer) ptmx_buffer;