diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-06-17 15:52:38 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-06-17 15:54:21 +0000 |
| commit | cf81fff062c8cac850f491ac722d6bb79a8bde14 (patch) | |
| tree | fc0e48563073f2eaf4eeec9a4f5c602d76eb39f4 | |
| parent | search: don’t crash when we don’t have any XKB compose state (diff) | |
config: add underline-offset option
This option allows the user to configure a custom underline
offset. That is, use the user provided offset instead of the font
provided one.
Closes #490
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | config.c | 17 | ||||
| -rw-r--r-- | config.h | 3 | ||||
| -rw-r--r-- | doc/foot.ini.5.scd | 22 | ||||
| -rw-r--r-- | foot.ini | 1 | ||||
| -rw-r--r-- | render.c | 6 |
6 files changed, 42 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 588adf0c..b7e2f51a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,8 @@ (https://codeberg.org/dnkl/foot/issues/581). * Support for overriding configuration options on the command line (https://codeberg.org/dnkl/foot/issues/554). +* `underline-offset` option to `foot.ini` + (https://codeberg.org/dnkl/foot/issues/490). ### Changed @@ -793,6 +793,14 @@ parse_section_main(const char *key, const char *value, struct config *conf, return false; } + else if (strcmp(key, "underline-offset") == 0) { + if (!str_to_pt_or_px( + value, &conf->underline_offset, + conf, path, lineno, "default", "underline-offset")) + return false; + conf->use_custom_underline_offset = true; + } + else if (strcmp(key, "dpi-aware") == 0) { if (strcmp(value, "auto") == 0) conf->dpi_aware = DPI_AWARE_AUTO; @@ -2514,10 +2522,11 @@ config_load(struct config *conf, const char *conf_path, }, .startup_mode = STARTUP_WINDOWED, .fonts = {tll_init(), tll_init(), tll_init(), tll_init()}, - .line_height = { .pt = 0, .px = -1, }, - .letter_spacing = { .pt = 0, .px = 0, }, - .horizontal_letter_offset = {.pt = 0, .px = 0, }, - .vertical_letter_offset = {.pt = 0, .px = 0, }, + .line_height = {.pt = 0, .px = -1}, + .letter_spacing = {.pt = 0, .px = 0}, + .horizontal_letter_offset = {.pt = 0, .px = 0}, + .vertical_letter_offset = {.pt = 0, .px = 0}, + .use_custom_underline_offset = false, .box_drawings_uses_font_glyphs = false, .dpi_aware = DPI_AWARE_AUTO, /* DPI-aware when scaling-factor == 1 */ .bell = { @@ -99,6 +99,9 @@ struct config { struct pt_or_px horizontal_letter_offset; struct pt_or_px vertical_letter_offset; + bool use_custom_underline_offset; + struct pt_or_px underline_offset; + bool box_drawings_uses_font_glyphs; struct { diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index e434c84b..a34a1987 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -112,10 +112,24 @@ in this order: Default: _0_. -*box-drawings-uses-font-glyphs* - Boolean. When disabled, foot generates box/line drawing characters - itself. The are several advantages to doing this instead of using - font glyphs: +*underline-offset* + Use a custom offset for underlines. The offset is, by default, in + _points_ and relative the font's baseline. A positive value + positions the underline under the baseline, while a negative value + positions it above the baseline. + + To specify an offset in _pixels_, append *px*: + *underline-offset=2px*. + + If left unset (the default), the offset specified in the font is + used, or estimated by foot if the font lacks underline positioning + information. + + Default: _unset_. + +*box-drawings-uses-font-glyphs* Boolean. When disabled, foot generates + box/line drawing characters itself. The are several advantages to + doing this instead of using font glyphs: - No antialiasing effects where e.g. line endpoints appear dimmed down, or blurred. @@ -12,6 +12,7 @@ # letter-spacing=0 # horizontal-letter-offset=0 # vertical-letter-offset=0 +# underline-offset=<font metrics> # box-drawings-uses-font-glyphs=no # dpi-aware=yes @@ -319,7 +319,11 @@ draw_underline_with_thickness( const pixman_color_t *color, int x, int y, int cols, int thickness) { /* Make sure the line isn't positioned below the cell */ - int y_ofs = font_baseline(term) - font->underline.position; + int y_ofs = font_baseline(term) - + (term->conf->use_custom_underline_offset + ? -term_pt_or_px_as_pixels(term, &term->conf->underline_offset) + : font->underline.position); + y_ofs = min(y_ofs, term->cell_height - thickness); pixman_image_fill_rectangles( |
