From c04d831ee51d06f7d3150cd0ff06145cd5d9e124 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 21 May 2022 06:10:03 -0700 Subject: [PATCH] add cell_width config to scale cell_width This works similarly to line_height refs: #1979 --- config/src/config.rs | 3 ++ docs/changelog.md | 2 ++ docs/config/fonts.md | 1 + docs/config/lua/config/cell_width.md | 49 +++++++++++++++++++++++++++ docs/config/lua/config/line_height.md | 2 +- wezterm-gui/src/customglyph.rs | 2 +- wezterm-gui/src/utilsprites.rs | 7 ++-- 7 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 docs/config/lua/config/cell_width.md diff --git a/config/src/config.rs b/config/src/config.rs index 79b719091..4423de0cc 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -47,6 +47,9 @@ pub struct Config { #[dynamic(default = "default_one_point_oh_f64")] pub line_height: f64, + #[dynamic(default = "default_one_point_oh_f64")] + pub cell_width: f64, + #[dynamic(default)] pub allow_square_glyphs_to_overflow_width: AllowSquareGlyphOverflow, diff --git a/docs/changelog.md b/docs/changelog.md index 7d7b8544a..5d9be5daa 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -31,6 +31,8 @@ As features stabilize some brief notes about them will accumulate here. * Search Mode: key assignments are [now configurable](scrollback.md#configurable-key-assignments) [#993](https://github.com/wez/wezterm/issues/993) * Copy Mode and Search Mode can be toggled and remember search results and cursor positioning, making it easier to locate and select text without using the mouse [#1592](https://github.com/wez/wezterm/issues/1592) * In the Launcher Menu, you may now use `CTRL-G` to cancel/exit the launcher [#1977](https://github.com/wez/wezterm/issues/1977) +* [cell_width](config/lua/config/cell_width.md) option to adjust the horizontal spacing when the availble font stretches are insufficient. [#1979](https://github.com/wez/wezterm/issues/1979) + #### Updated * Bundled harfbuzz to 4.2.1 diff --git a/docs/config/fonts.md b/docs/config/fonts.md index 32fd2d9b1..d739adebe 100644 --- a/docs/config/fonts.md +++ b/docs/config/fonts.md @@ -69,6 +69,7 @@ Additional options for configuring fonts can be found elsewhere in the docs: * [freetype_load_flags](lua/config/freetype_load_flags.md) - advanced hinting configuration * [freetype_load_target](lua/config/freetype_load_target.md) - configure hinting and anti-aliasing * [freetype_render_target](lua/config/freetype_render_target.md) - configure anti-aliasing +* [cell_width](lua/config/cell_width.md) - scale the font-specified cell width * [line_height](lua/config/line_height.md) - scale the font-specified line height * [wezterm.font](lua/wezterm/font.md) - select a font based on family and style attributes * [wezterm.font_with_fallback](lua/wezterm/font_with_fallback.md) - select a font from a list of candidates diff --git a/docs/config/lua/config/cell_width.md b/docs/config/lua/config/cell_width.md new file mode 100644 index 000000000..7249db104 --- /dev/null +++ b/docs/config/lua/config/cell_width.md @@ -0,0 +1,49 @@ +# `cell_width = 1.0` + +*Since: nightly builds only* + +Scales the computed cell width to adjust the spacing between successive cells +of text. + +If possible, you should prefer to specify the `stretch` parameter when +selecting a font using [wezterm.font](../wezterm/font.md) or +[wezterm.font_with_fallback](../wezterm/font_with_fallback.md) as that will +generally look better and have fewer undesirable side effects. + +If your preferred font doesn't have variations with different stretches, or +if the font spacing still doesn't look right to you, then `cell_width` gives +you a simple way to influence the spacing. + +The default cell width is indirectly controlled by the [font](font.md) and +[font_size](font_size.md) configuration options; the selected font and font +size controls the height of the font, while the font designer controls the +aspect ratio of the glyphs in the font. The base font (the first font resolved +from your `font` configuration) defines the cell metrics for the terminal +display grid, and those metrics are then used to place glyphs, regardless of +which fallback font might be resolved for a given glyph. + +If you feel that your chosen font feels too horizontally cramped then you can +set `cell_width = 1.2` to increase the horizontal spacing by 20%. Conversely, +setting `cell_width = 0.9` will decrease the horizontal spacing by 10%. + +This option doesn't adjust the rasterized width of glyphs, it just changes what +wezterm considers to be the cell boundaries. When rendering monospace, wezterm +advances by the cell width to place successive glyphs. + +If you set the scale less than `1.0` then the glyphs won't be truncated or +squished, but will render over the top of each other. Conversely, if you set +the scale to greater than `1.0`, the glyphs won't be stretched but will render +further apart from each other. + +Changing `cell_width` doesn't adjust the positioning of the glyph within the +cell: it remains at its usual x-position. It is *not* centered within the +adjusted space. + +Changing `cell_width` may have undesirable consequences, especially for fonts +that use ligatures: depending on the font, you may find that some ligatured +sequences are misaligned or render strangely. This is not a bug: the font is +designed to be rendered with a `cell_width = 1.0`, so running with a different +value will have this sort of side effect. + +See also: [line_height](line_height.md) + diff --git a/docs/config/lua/config/line_height.md b/docs/config/lua/config/line_height.md index c1dede4c3..355fdaa6f 100644 --- a/docs/config/lua/config/line_height.md +++ b/docs/config/lua/config/line_height.md @@ -7,4 +7,4 @@ font feels too vertically cramped then you can set `line_height = 1.2` to increase the vertical spacing by 20%. Conversely, setting `line_height = 0.9` will decrease the vertical spacing by 10%. - +See also: [cell_width](cell_width.md) diff --git a/wezterm-gui/src/customglyph.rs b/wezterm-gui/src/customglyph.rs index af0671983..783d04d6d 100644 --- a/wezterm-gui/src/customglyph.rs +++ b/wezterm-gui/src/customglyph.rs @@ -3695,7 +3695,7 @@ impl GlyphCache { return Ok(sprite.clone()); } - let metrics = metrics.scale_cell_width(width); + let metrics = metrics.scale_cell_width(width as f64); let mut buffer = Image::new( metrics.cell_size.width as usize, diff --git a/wezterm-gui/src/utilsprites.rs b/wezterm-gui/src/utilsprites.rs index 07d3ff742..8b3a72af5 100644 --- a/wezterm-gui/src/utilsprites.rs +++ b/wezterm-gui/src/utilsprites.rs @@ -61,9 +61,9 @@ impl RenderMetrics { } } - pub fn scale_cell_width(&self, scale: u8) -> Self { + pub fn scale_cell_width(&self, scale: f64) -> Self { let mut scaled = self.clone(); - scaled.cell_size.width *= scale as isize; + scaled.cell_size.width = (self.cell_size.width as f64 * scale) as isize; scaled } @@ -73,10 +73,11 @@ impl RenderMetrics { .context("failed to get font metrics!?")?; let line_height = fonts.config().line_height; + let cell_width = fonts.config().cell_width; let (cell_height, cell_width) = ( (metrics.cell_height.get() * line_height).ceil() as usize, - metrics.cell_width.get().ceil() as usize, + (metrics.cell_width.get() * cell_width).ceil() as usize, ); // When line_height != 1.0, we want to adjust the baseline position