1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-21 03:39:16 +03:00
Commit Graph

2910 Commits

Author SHA1 Message Date
Wez Furlong
b0bee3b036 wezterm-font: introduce FontDatabase
This tidies up the font-dir and built-in font management a little
bit and paves the way for codepoint -> font resolution for fonts
discovered in font-dirs.
2020-11-25 19:15:08 -08:00
Wez Furlong
164adb78e3 wezterm: blow more caches when scaling changes
The recent addition of dynamic fallback resolution highlighted this
issue.

The test scenario is:

1. Output some glyphs that need dynamic fallback
2. ctrl-+ to change the font scaling
3. rasterization fails because of some bad cached state; the font_idx's
   were invalidated by the scale change which reset the dynamically
   discovered fallback fonts.

The resolution is to blow the glyph and shape caches when scaling
is changed.
2020-11-25 16:19:56 -08:00
Wez Furlong
80488ea14d improve freetype error context
Tag some font related errors with more context.
This makes it a bit easier to understand where a problem
is coming from.
2020-11-25 16:19:56 -08:00
Wez Furlong
4fd574cc7f freetype: enable FT_Error_String
By default, freetype doesn't include error strings and FT_Error_String
will always return NULL.  Turn on the compile time option that makes
this function useful!
2020-11-25 16:19:56 -08:00
Wez Furlong
ba44548d46 wezterm-font: teach gdi locator how to search for fallback fonts
This commit uses a bit of DirectWrite to discover which font(s)
can be used to render a set of codepoints.

While hooking this up, I found that the method we were using
to extract the font data didn't handle TTC data so this commit
improves some parser diagnostics and handling for that.

refs: https://github.com/wez/wezterm/issues/299
2020-11-25 16:19:56 -08:00
Wez Furlong
58eb8e3614 wezterm-font: move caching of freetype font size into Face
Profiling showed that set_font_size was a hotspot.  While there was
caching of the size info at the shaper layer, it was also needed in
the raster layer, so move it into the raster layer from the shaper
layer.

refs: #353
2020-11-25 09:20:14 -08:00
Benoit de Chezelles
c7dc44a538 Update fonts.markdown 2020-11-24 18:26:27 -08:00
Wez Furlong
5fbb6a4400 wezterm-font: cache metrics lookup in harfbuzz shaper
98f289f511 causes more metrics retrieval
than in earlier versions; each unchached glyph render would trigger
a metrics recompute for the relevant font.

Add a simple cache for this.

refs: #353
2020-11-24 18:19:49 -08:00
Wez Furlong
827d94a9a8 wezterm-font: add find-fall-back-for-codepoints concept
This commit makes some adjustments to FontConfiguration and LoadedFont
such that it the shaper is unable to resolve a (non-last-resort) font
for a set of codepoints, the locator can be used to try to find a
font that has coverage for those codepoints.

At the moment this is a bit limited:

* Only the font-config locator implements this function
* The directory based locator isn't actually an implementor of the
  locator trait and doesn't have a way to be invoked for this.
2020-11-24 18:03:32 -08:00
Wez Furlong
3652a8360f wezterm-font: fix typo in error message 2020-11-24 12:37:11 -08:00
Simon Legner
93ef3a7572 docs: fix capitalization of PageUp/PageDown 2020-11-24 10:45:42 -08:00
Wez Furlong
3b69586416 wezterm: add allow_square_glyphs_to_overflow_width = "WhenFollowedBySpace"
Adds an option to control how wide glyphs (more specifically: square
aspect glyphs) are scaled to conform to their specified width.

The three options are `Never`, `Always`, and `WhenFollowedBySpace`.

When a glyph is loaded, if it is approximately square, this option is
consulted.  If overflow is permitted then the glyph will be scaled
to fit only the height of the cell, rather than ensuring that it fits
in both the height and width of the cell.

refs: #342
2020-11-24 10:38:20 -08:00
Wez Furlong
d97e4e44a9 use double wide glyphs for square emoji 2020-11-24 10:17:44 -08:00
Wez Furlong
6e8f8298af wezterm: explain where the font came from in fallback errors
Make an effort to explain what failed to load and where it came from,
and funnel users to the documentation on font configuration.

The message presented is slightly different depending on whether
we think that the font was their primary font, an explicitly
specified font_rule or an implicitly synthesized font_rule.

refs: #340
2020-11-24 08:49:26 -08:00
Benoit de Chezelles
eee40f7d17 Update permute_any_mods.md 2020-11-23 17:22:21 -08:00
Benoit de Chezelles
2963520a1e Update permute_any_or_no_mods.md 2020-11-23 17:22:21 -08:00
Wez Furlong
98f289f511 wezterm-font: improve fallback font scaling
Use the scaling factor between the font metrics for the base font
and those of the fallback font selected for a given glyph.

The scenario is this: the base font is typically the first one selected
from the font configuration.  There may be multiple fallback fonts that
are different sizes; for instance, the Font Awesome font has glyphs that
are square in aspect and are thus about twice the width of a typical
textual monospace font.  Similarly, Noto Color Emoji is another square
font but that has a single set of bitmap strikes at a fixed 128 px
square.

The shaper returns advance metrics in the scale of the containing font,
and the rasterizer will target the supplied size and dpi.

We need to scale these to match the base metrics.

Previously we used a crude heuristic to decide whether to scale,
and that happened to work for Noto Color Emoji but not for Font Awesome,
whose metrics were just inside the bounds of the heuristic.

This commit allows retrieving the metrics for a given font_idx so
that we can compute the correct scale factor without any heuristics,
and applies that to the rasterized glyph.

refs: https://github.com/wez/wezterm/issues/342
2020-11-23 16:59:30 -08:00
Wez Furlong
65ac2269dd wezterm-font: fix exact match of full font name
Don't short circuit on just the family portion of the name;
if the criteria don't match there, we should fall back to
test against the full font name.

closes: https://github.com/wez/wezterm/issues/341
2020-11-23 15:01:19 -08:00
Benoit de Chezelles
d4d3e70a9b Update permute_any_or_no_mods.md 2020-11-23 14:52:45 -08:00
Wez Furlong
3309803925 ci: speculative fix for C++11 build break in harfbuzz
Weird that this was set to not enable C++, but I suspect it is the
reason why the C++11 compiler flag isn't being added to resolve this:

```
warning: harfbuzz/src/hb-meta.hh:41:18: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
warning: template<typename... Ts> struct _hb_void_t { typedef void type; };
```
2020-11-23 14:33:47 -08:00
Wez Furlong
eabfa3c0f8 term: fix ALT-Escape
This appears to have been accidentally broken as part of the churn
around building out CSI-u key encoding in
6289c08a4e

closes: https://github.com/wez/wezterm/issues/338
2020-11-23 14:20:43 -08:00
Wez Furlong
a063d20cf0 wezterm: improve shaping of emoji
This is one of those massive time sinks that I almost regret...
As part of recent changes to dust-off the allsorts shaper, I noticed
that the harfbuzz shaper wasn't shaping as well as the allsorts one.

This commit:

* Adds emoji-test.txt, a text file you can `cat` to see how well
  the emoji are shaped and rendered.

* Fixes (or at least, improves) the column width calculation for
  combining sequences such as "deaf man" which was previously calculated
  at 3 cells in width when it should have just been 2 cells wide, which
  resulted in a weird "prismatic" effect during rendering where the
  glyph would be rendered with an extra RHS portion of the glyph across
  3 cells.

* Improved/simplified the clustering logic used to compute fallbacks.
  Previously we could end up with some wonky/disjoint sequence of
  undefined glyphs which wouldn't be successfully resolved from a
  fallback font.  We now make a better effort to consolidate runs of
  undefined glyphs for fallback.

* For sequences such as "woman with veil: dark skin tone" that occupy a
  single cell, the shaper may return 3 clusters with 3 glyphs in the
  case that the font doesn't fully support this grapheme.  At render
  time we'd just take the last glyph from that sequence and render it,
  resulting in eg: a female symbol in this particular case.  It is
  generally a bit more useful to show the first glyph in the sequence
  (eg: person with veil) rather than the gender or skin tone, so the
  renderer now checks for this kind of overlapping sequence and renders
  only the first glyph from the sequence.
2020-11-23 13:45:38 -08:00
Wez Furlong
dc453f2eed deps: update bundled harfbuzz to 2.7.2 2020-11-23 08:43:53 -08:00
Wez Furlong
69d56fc868 wezterm-font: remove some dead code 2020-11-23 08:43:53 -08:00
Wez Furlong
3bd8d8c845 wezterm-font: bundle a last resort font
Bundle the *Last Resort High-Efficiency* font from
https://github.com/unicode-org/last-resort-font/
version 13.001 (Oct 22 2020).

This provides a more useful fallback glyph than we'd otherwise
produce if there is no matching glyph in any of the fonts.

Its license is OFL-1.1 which is compatible with the other
bundled fonts.
2020-11-22 16:12:20 -08:00
Wez Furlong
4500510d5c wezterm-font: improve perf of windows font locator
This avoids enumerating and parsing all fonts on startup, and improves
matching in general.
2020-11-22 12:39:29 -08:00
Wez Furlong
534cdfeaf2 wezterm-font: cargo fmt and fix comment
refs: #337
2020-11-22 11:23:58 -08:00
Wez Furlong
30cc10d4cf wezterm-font: remove font-loader dependency
This commit replaces it with the underlying core text calls
on macos.

refs: #337
2020-11-22 11:19:44 -08:00
Wez Furlong
9ca428c4e1 wezterm-font: remove font-loader dep on windows
There are a number of cases where font-loader might panic on windows,
and the optional font-loader dep causes problems with `cargo vendor`
in #337, so this is a step to removing that dep.

This commit makes direct GDI calls to enumerate monospace truetype
fonts from the system and then applies our normal matching on the
result.
2020-11-22 10:27:48 -08:00
Wez Furlong
9bebc811d0 window: fix build when opengl is not enabled 2020-11-22 09:24:07 -08:00
Wez Furlong
ddc4c1b624 wezterm: fixup some allsorts shaping cases
* Fixes `keycap 0` by plucking out the prior character for an
  EnclosingMark
* Fixes lookahead for VariationSelector

refs: #66
2020-11-20 18:44:28 -08:00
Wez Furlong
a2a64e80a7 wezterm: update allsorts shaper
The current master of allsorts supports color fonts in both bitmap and
svg varieties.  I'm interested to see if I can teach wezterm to render
the svg based variety in a subsequent diff.

First though, it's times to dust off our allsorts shaper logic.

This commit updates to point to the current master of allsorts at the
time of writing; there's a little bit of API fanout that makes it a bit
easier to manage font fallback.

The fallback logic has been improved so that we can now successfully
fall back to the emoji font.

The shaping logic has been improved so that we turn on the options that
enable ZWJ for combining sequences of emoji, such as "man health
worker".

Running with the allsorts shaper enabled produces generally superior
emoji/ligature substitution results compared to harfbuzz with Noto Color
Emoji; the "man health worker" and the flags (eg: `flag: England`) from
the subdivsion-flag section don't get substituted at all with harfbuzz,
but do produce appropriate glyphs with allsorts.

refs: https://github.com/wez/wezterm/issues/66
2020-11-20 16:56:07 -08:00
Wez Furlong
fba2159839 deps: remove unused deps
Not all of these are needed in these crates (copypasta resulting
from splitting out modules)
2020-11-20 12:37:38 -08:00
Wez Furlong
a498aa56af termwiz: deallocate "fat" attrs if all are none
Noticed this while looking at another issue
2020-11-20 12:37:38 -08:00
Wez Furlong
c6c87eaf7c tmux: plumbing for querying panes when control mode is started up
refs: https://github.com/wez/wezterm/issues/336
2020-11-20 09:25:01 -08:00
Wez Furlong
9442726f23 tmux: press q to detach control mode pane
refs: https://github.com/wez/wezterm/issues/336
2020-11-20 09:24:58 -08:00
Wez Furlong
91f1cc21fc mux/wezterm: move Renderable into Pane
This makes it easier to overrride/overlay inside the mux when
indicating that we are in tmux mode.

refs: https://github.com/wez/wezterm/issues/336
2020-11-20 09:24:56 -08:00
Wez Furlong
fffb9b3fa0 tmux: some plumbing for detaching and indicating tmux is active
the renderable interface is getting in the way though...

refs: https://github.com/wez/wezterm/issues/336
2020-11-20 09:24:53 -08:00
Wez Furlong
aaf63285d2 tmux: attach control mode parser to terminal
This causes `tmux -CC attach` to enter control mode and patch
into the terminal, printing out parsed event messages.

refs: https://github.com/wez/wezterm/issues/336
2020-11-20 09:24:50 -08:00
Wez Furlong
0b64683a60 term: allow embedding application to hook device control mode
refs: https://github.com/wez/wezterm/issues/336
2020-11-20 09:24:48 -08:00
Wez Furlong
6035e16f33 tmux: restructure a bit to capture guarded output blocks
refs: https://github.com/wez/wezterm/issues/336
2020-11-20 09:24:43 -08:00
Wez Furlong
ec55a23398 tmux: add tmux-cc crate
This crate knows how to parse data returned from the `tmux -CC` protocol.

refs: https://github.com/wez/wezterm/issues/336
2020-11-20 09:24:28 -08:00
Wez Furlong
6716d40222 Add note about AA shadows to changelog
(and fix a typo in the comment in the shader)

closes: #331
2020-11-20 09:10:39 -08:00
Wez Furlong
fd3c062daf cargo fmt
latest rust changed the formatting options, so reformat to
avoid the CI being unhappy.
2020-11-20 09:06:21 -08:00
Wez Furlong
8c858ae6ce wezterm: avoid "shadow" AA artifacts when fg and bg are the same
When subpixel or greyscale AA are in use, the glyph data includes
some lighter and darker shaded pixels.  That's their purpose,
but if the fg and bg color are the same, the expectation is that
the glyph is invisible and we don't want "phantom" pixels around
the character.

This commit adjusts the shader to set the color to transparent
when the fg and bg are the same, and we are not rendering a color
emoji.

refs: #331
2020-11-20 08:49:12 -08:00
Wez Furlong
9d2df980e7 More fun with actions-rs/toolchain
I don't think that https://github.com/actions-rs/toolchain/issues/124
is 100% fixed, but this should fix our CI in the meantime.
2020-11-17 12:03:24 -08:00
Wez Furlong
8b9f6aed65
speculative fix for CI (#333)
* speculative fix for CI

GitHub made a breaking change, and this may get us through
until this action is updated.

refs: https://github.com/actions-rs/toolchain/pull/114
refs: https://github.com/actions-rs/toolchain/issues/124
2020-11-16 17:28:37 -08:00
Wez Furlong
0bb02ff674 docs: note about #320 in changelog
refs: #320
2020-11-15 22:26:20 -08:00
Wez Furlong
e8ad765ff5 wezterm: add SelectionMode::SemanticZone
This makes it possible to configure wezterm to eg: triple click
on command input (or output) to select the entire input or output
without messing around trying to find the bounds.

The docs have an example of how to configure this; it requires
setting up shell integration to define the appropriate semantic
zones.
2020-11-15 22:23:18 -08:00
Wez Furlong
720a6fd9b6 wezterm: fixup dark edges on text
9892b16d40 adjusted how the text
colors are produced; it resulted in some ugly dark edges, especially
on lighter backgrounds.

This commit routes that tint via an alpha compositing helper which
produces smoother edges.

refs: #320
2020-11-15 15:17:23 -08:00