aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2023-07-26 14:12:36 +0000
committerDaniel Eklöf <daniel@ekloef.se>2023-07-28 13:40:07 +0000
commitf3c5b82c8276feda3c9eec522e549062c1589484 (patch)
treec89b6e101aa72ab97865cff122b0a9935a52d6b9
parentrender: revert part of a36f67cbe311bebd9321fbf58773dace8128fcd7 (diff)
config: add tweak.bold-text-in-bright-amount
By how much to increase the luminance when brightening bold fonts. This was previously hard-coded to a factor of 1.3, which is now the default value of the new config option. Closes #1434
-rw-r--r--CHANGELOG.md6
-rw-r--r--config.c14
-rw-r--r--config.h1
-rw-r--r--doc/foot.ini.5.scd8
-rw-r--r--hsl.c6
-rw-r--r--render.c4
-rw-r--r--tests/test-config.c9
7 files changed, 35 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f1ed9f3..85eeae1f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -46,6 +46,12 @@
## Unreleased
### Added
+
+* `[tweak].bold-text-in-bright-amount` option ([#1434][1434]).
+
+[1434]: https://codeberg.org/dnkl/foot/issues/1434
+
+
### Changed
### Deprecated
### Removed
diff --git a/config.c b/config.c
index 58a655e6..302e30f0 100644
--- a/config.c
+++ b/config.c
@@ -480,7 +480,7 @@ value_to_dimensions(struct context *ctx, uint32_t *x, uint32_t *y)
}
static bool NOINLINE
-value_to_double(struct context *ctx, float *res)
+value_to_float(struct context *ctx, float *res)
{
const char *s = ctx->value;
@@ -659,7 +659,7 @@ value_to_pt_or_px(struct context *ctx, struct pt_or_px *res)
res->px = value;
} else {
float value;
- if (!value_to_double(ctx, &value))
+ if (!value_to_float(ctx, &value))
return false;
res->pt = value;
res->px = 0;
@@ -1089,7 +1089,7 @@ parse_section_scrollback(struct context *ctx)
}
else if (strcmp(key, "multiplier") == 0)
- return value_to_double(ctx, &conf->scrollback.multiplier);
+ return value_to_float(ctx, &conf->scrollback.multiplier);
else {
LOG_CONTEXTUAL_ERR("not a valid option: %s", key);
@@ -1298,7 +1298,7 @@ parse_section_colors(struct context *ctx)
else if (strcmp(key, "alpha") == 0) {
float alpha;
- if (!value_to_double(ctx, &alpha))
+ if (!value_to_float(ctx, &alpha))
return false;
if (alpha < 0. || alpha > 1.) {
@@ -2461,7 +2461,7 @@ parse_section_tweak(struct context *ctx)
}
else if (strcmp(key, "box-drawing-base-thickness") == 0)
- return value_to_double(ctx, &conf->tweak.box_drawing_base_thickness);
+ return value_to_float(ctx, &conf->tweak.box_drawing_base_thickness);
else if (strcmp(key, "box-drawing-solid-shades") == 0)
return value_to_bool(ctx, &conf->tweak.box_drawing_solid_shades);
@@ -2472,6 +2472,9 @@ parse_section_tweak(struct context *ctx)
else if (strcmp(key, "sixel") == 0)
return value_to_bool(ctx, &conf->tweak.sixel);
+ else if (strcmp(key, "bold-text-in-bright-amount") == 0)
+ return value_to_float(ctx, &conf->bold_in_bright.amount);
+
else {
LOG_CONTEXTUAL_ERR("not a valid option: %s", key);
return false;
@@ -2939,6 +2942,7 @@ config_load(struct config *conf, const char *conf_path,
.bold_in_bright = {
.enabled = false,
.palette_based = false,
+ .amount = 1.3,
},
.startup_mode = STARTUP_WINDOWED,
.fonts = {{0}},
diff --git a/config.h b/config.h
index 8189e56d..4d2838c4 100644
--- a/config.h
+++ b/config.h
@@ -133,6 +133,7 @@ struct config {
struct {
bool enabled;
bool palette_based;
+ float amount;
} bold_in_bright;
enum { STARTUP_WINDOWED, STARTUP_MAXIMIZED, STARTUP_FULLSCREEN } startup_mode;
diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd
index ae91ddf5..8726da0c 100644
--- a/doc/foot.ini.5.scd
+++ b/doc/foot.ini.5.scd
@@ -1337,7 +1337,13 @@ any of these options.
Default: _512_. Maximum allowed: _2048_ (2GB).
*sixel*
- Boolean. When enabled, foot will process sixel images. Default: _yes_
+ Boolean. When enabled, foot will process sixel images. Default:
+ _yes_
+
+*bold-text-in-bright-amount*
+ Amount by which bold fonts are brightened when
+ *bold-text-in-bright* is set to *yes* (the *palette-based* variant
+ is not affected by this option). Default: _1.3_.
# SEE ALSO
diff --git a/hsl.c b/hsl.c
index 3ebe4beb..d5d00e67 100644
--- a/hsl.c
+++ b/hsl.c
@@ -83,7 +83,7 @@ hsl_to_rgb(int hue, int sat, int lum)
b += m;
return (
- (int)round(r * 255.) << 16 |
- (int)round(g * 255.) << 8 |
- (int)round(b * 255.) << 0);
+ (uint8_t)round(r * 255.) << 16 |
+ (uint8_t)round(g * 255.) << 8 |
+ (uint8_t)round(b * 255.) << 0);
}
diff --git a/render.c b/render.c
index 37c0c97d..6771fae5 100644
--- a/render.c
+++ b/render.c
@@ -299,7 +299,9 @@ color_brighten(const struct terminal *term, uint32_t color)
int hue, sat, lum;
rgb_to_hsl(color, &hue, &sat, &lum);
- return hsl_to_rgb(hue, sat, min(100, lum * 1.3));
+
+ lum = (int)roundf(lum * term->conf->bold_in_bright.amount);
+ return hsl_to_rgb(hue, sat, min(lum, 100));
}
static void
diff --git a/tests/test-config.c b/tests/test-config.c
index 54efd13a..2ae891e8 100644
--- a/tests/test-config.c
+++ b/tests/test-config.c
@@ -265,7 +265,7 @@ test_uint32(struct context *ctx, bool (*parse_fun)(struct context *ctx),
}
static void
-test_double(struct context *ctx, bool (*parse_fun)(struct context *ctx),
+test_float(struct context *ctx, bool (*parse_fun)(struct context *ctx),
const char *key, const float *ptr)
{
ctx->key = key;
@@ -580,7 +580,7 @@ test_section_scrollback(void)
test_uint32(&ctx, &parse_section_scrollback, "lines",
&conf.scrollback.lines);
- test_double(&ctx, parse_section_scrollback, "multiplier", &conf.scrollback.multiplier);
+ test_float(&ctx, parse_section_scrollback, "multiplier", &conf.scrollback.multiplier);
test_enum(
&ctx, &parse_section_scrollback, "indicator-position",
@@ -1312,7 +1312,7 @@ test_section_tweak(void)
RENDER_TIMER_BOTH},
(int *)&conf.tweak.render_timer);
- test_double(&ctx, &parse_section_tweak, "box-drawing-base-thickness",
+ test_float(&ctx, &parse_section_tweak, "box-drawing-base-thickness",
&conf.tweak.box_drawing_base_thickness);
test_boolean(&ctx, &parse_section_tweak, "box-drawing-solid-shades",
&conf.tweak.box_drawing_solid_shades);
@@ -1345,6 +1345,9 @@ test_section_tweak(void)
test_boolean(&ctx, &parse_section_tweak, "font-monospace-warn",
&conf.tweak.font_monospace_warn);
+ test_float(&ctx, &parse_section_tweak, "bold-text-in-bright-amount",
+ &conf.bold_in_bright.amount);
+
#if 0 /* Must be equal to, or less than INT32_MAX */
test_uint32(&ctx, &parse_section_tweak, "max-shm-pool-size-mb",
&conf.tweak.max_shm_pool_size);