From aeac5ad6f1cfcf462c8a8babf0066c6d58e7c956 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Wed, 21 Jul 2021 09:17:43 +0200 Subject: [PATCH] Add option to enable subpixel font rendering with transparent background --- config.c | 4 ++++ config.h | 2 ++ doc/foot.ini.5.scd | 4 ++++ foot.ini | 1 + terminal.c | 4 ++-- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index a9acb58e..f17f1367 100644 --- a/config.c +++ b/config.c @@ -961,6 +961,9 @@ parse_section_main(const char *key, const char *value, struct config *conf, else if (strcmp(key, "box-drawings-uses-font-glyphs") == 0) conf->box_drawings_uses_font_glyphs = str_to_bool(value); + else if (strcmp(key, "subpixel-with-alpha") == 0) + conf->subpixel_with_alpha = str_to_bool(value); + else { LOG_AND_NOTIFY_ERR("%s:%u: [default]: %s: invalid key", path, lineno, key); return false; @@ -2740,6 +2743,7 @@ config_load(struct config *conf, const char *conf_path, .vertical_letter_offset = {.pt = 0, .px = 0}, .use_custom_underline_offset = false, .box_drawings_uses_font_glyphs = false, + .subpixel_with_alpha = false, .dpi_aware = DPI_AWARE_AUTO, /* DPI-aware when scaling-factor == 1 */ .bell = { .urgent = false, diff --git a/config.h b/config.h index 729eba3e..8a998187 100644 --- a/config.h +++ b/config.h @@ -114,6 +114,8 @@ struct config { bool box_drawings_uses_font_glyphs; bool can_shape_grapheme; + bool subpixel_with_alpha; + struct { bool urgent; bool notify; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 8b2f1dc8..640fc831 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -145,6 +145,10 @@ in this order: Default: _no_. + *subpixel-with-alpha* + Boolean. When enabled, subpixel font rendering will be used also + with transparent background. Default: _no_. + *dpi-aware* *auto*, *yes*, or *no*. When set to *yes*, fonts are sized using the monitor's DPI, making a font of a given size have the same diff --git a/foot.ini b/foot.ini index 31167cd5..55677d7d 100644 --- a/foot.ini +++ b/foot.ini @@ -19,6 +19,7 @@ # underline-offset= # box-drawings-uses-font-glyphs=no # dpi-aware=yes +# subpixel-with-alpha=no # initial-window-size-pixels=700x500 # Or, # initial-window-size-chars= diff --git a/terminal.c b/terminal.c index 46e7fc01..2fe452fd 100644 --- a/terminal.c +++ b/terminal.c @@ -760,7 +760,7 @@ get_font_dpi(const struct terminal *term) static enum fcft_subpixel get_font_subpixel(const struct terminal *term) { - if (term->colors.alpha != 0xffff) { + if (!term->conf->subpixel_with_alpha && term->colors.alpha != 0xffff) { /* Can't do subpixel rendering on transparent background */ return FCFT_SUBPIXEL_NONE; } @@ -1086,7 +1086,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, xmalloc(sizeof(term->font_sizes[3][0]) * conf->fonts[3].count), }, .font_dpi = 0., - .font_subpixel = (conf->colors.alpha == 0xffff /* Can't do subpixel rendering on transparent background */ + .font_subpixel = ((conf->subpixel_with_alpha || conf->colors.alpha == 0xffff) /* Can't do subpixel rendering on transparent background */ ? FCFT_SUBPIXEL_DEFAULT : FCFT_SUBPIXEL_NONE), .cursor_keys_mode = CURSOR_KEYS_NORMAL,