1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 15:04:36 +03:00
Commit Graph

177 Commits

Author SHA1 Message Date
Wez Furlong
545a8fc8a7 deps: ordered-float -> 2.8 2021-09-05 23:25:37 -07:00
Wez Furlong
18ddf38174 font: set alpha to 0xff in rasterizer
Since fonts now use dual source blending, the pixel colors are
interpreted as individual alpha channels.  The A component should
be set to 1.0, so that's what we do here.

refs: #1025
2021-09-04 18:54:32 -07:00
Wez Furlong
4fc8dfb374 fonts: retry fallback with no presentation if we hit last resort
The introduction of the Emoji vs Text VS processing means that we might
in some cases not find a glyph with the requested presentation.

In that case, we'd rather show the emoji presentation glyph than none at
all, so we'll retry fallback processing with unspecified presentation.

refs: #997
2021-08-17 22:00:27 -07:00
Wez Furlong
6f78ee4f14 deps: update unicode-segmentation to 1.8 2021-08-11 23:06:17 -07:00
Wez Furlong
99074c6dc3 font: avoid running out of fallbacks!
The recent presentation logic needs to be tweaked to ensure that
we ignore presentation when we reach the fallback font, otherwise
we'll end up in a bad error stack and crash the program.
2021-08-11 22:50:35 -07:00
Wez Furlong
0866e5d213 fonts/shaping: respect the Presentation selection for a cluster
This commit annotates fonts with a boolean that indicates whether
we think it contains glyphs with emoji presentation, and then
passes the cluster.presentation field down to the shaper.

If the presentation doesn't match the current font in the fallback,
then it will be skipped until we exhaust its options.

`wezterm ls-fonts` also shows whether we think a font has emoji
presentation.

refs: #997
2021-08-11 09:11:59 -07:00
Wez Furlong
e3acbd594f fonts: coretext: don't specify monospace when locating fonts
The fonts in https://github.com/wez/wezterm/issues/984 aren't
considered to be monospace by coretext, so when we asked it
to resolve monospace fonts with the given name, it wouldn't
return it to us.

Remove the code that tries to restrict to monospace.

refs: https://github.com/wez/wezterm/issues/984
2021-08-04 16:25:08 -07:00
Wez Furlong
365a68dfb8 Wrap up synchronized output handling, parser changes
This commit hooks up DECRQM so that we can report that we implement
synchronized updates, and then refines the code that manages sending
data to the terminal model; the first cut at synchronized updates
was a bit simplistic, and now we make a point of "flushing" pending
actions when we start a sync point, and again as soon as we release
the sync point.

This smooths out the jaggies around the orca that I mentioned in
dcbbda7702

and while testing this, I realized that recent parser changes had
mangled processing bundled dec private mode sequences where multiple
modes were specified in the same overall escape sequence.  I've
added the missing unit test case for this and made that work again.

refs: https://github.com/wez/wezterm/issues/955
refs: https://github.com/wez/wezterm/issues/882
2021-07-24 17:01:21 -07:00
Wez Furlong
a2e882a7cb deps: cargo update, and a couple of dependabot suggestions 2021-07-18 19:10:46 -07:00
Wez Furlong
70ec166076 shaper: micro-optimize some of the harfbuzz stuff
Probably not super effective compared to all the Vec stuff
going on in here, but it can't hurt.
2021-07-09 19:56:31 -07:00
Wez Furlong
5b135a6e50 fix auto-complete-o 2021-07-04 09:43:34 -07:00
Wez Furlong
47fc6cac64 fixup build on linux 2021-07-04 09:30:16 -07:00
Wez Furlong
423b208780 font weight can now be specified as the underlying opentype weight
opentype allows a font to have a weight in the range 0-1000.
MacOS has its own concept of symbolic weight names and opentype
values that is a slightly different scale of boldness to Windows
and Linux.

That means that Medium could be a different range of opentype
weight values depending on the system.

To further complicate things, the font designer can name their
variant with any name they like and assign it an arbitrary
opentype weight value.

For the Operator Mono font, it has Book variant with opentype
weight 325 and a Light variant with an opentype weight of 300.

wezterm was considering these both to have `FontWeight::Light` because
that's how those values were bucketed, which results in amibiguity in
resolve the font and frustration in not being able to access one of the
variants.

This commit changes the `FontWeight` type to now hold the unambiguous
opentype weight value, and to define some symbolic aliases for
some specified weights.

When serializing, if the weight matches a symbolic alias, then that
name will be used in the canonical name (eg: as listed via ls-fonts).
Otherwise, the numeric value will be used.

When parsing the font configuration, wezterm will allow both symbolic
and numeric values.

This allows all of the Operator Mono variants to be referenced
unambiguously, although some variants have to be specified via the
numeric weight:

```
wezterm.font("Operator Mono", {weight=275, stretch="Normal", italic=false}) -- /Users/wez/.fonts/OperatorMono-XLight.otf, FontDirs
wezterm.font("Operator Mono", {weight="Light", stretch="Normal", italic=false}) -- /Users/wez/.fonts/OperatorMono-Light.otf, FontDirs
wezterm.font("Operator Mono", {weight=325, stretch="Normal", italic=false}) -- /Users/wez/.fonts/OperatorMono-Book.otf, FontDirs
wezterm.font("Operator Mono", {weight="DemiLight", stretch="Normal", italic=false}) -- /Users/wez/.fonts/OperatorMono-Medium.otf, FontDirs
wezterm.font("Operator Mono", {weight="Regular", stretch="Normal", italic=false}) -- /Users/wez/.fonts/OperatorMono-Bold.otf, FontDirs
```

https://github.com/wez/wezterm/issues/849#issuecomment-873454483
2021-07-04 08:55:08 -07:00
Wez Furlong
c514254138 wayland: use proportional font for title bar
allow specifying the font in the config file
2021-06-27 13:04:20 -07:00
Wez Furlong
e69869efa7 refactor deps so that window can depend on wezterm-font
I want to use this to render the font in the title bar
2021-06-26 22:58:42 -07:00
Wez Furlong
618f77f2c6 macos: improve core text font matching
Change the loader so that it has better matching weight and stretch
characteristics, and ask core text to return all possible candidates
so that we can then apply our CSS-style font matching rules.

Previously, the font descriptor we created would only match the
family name and return the normal/regular variant only.

refs: https://github.com/wez/wezterm/issues/873
2021-06-17 23:33:05 -07:00
Wez Furlong
7afe539b0c ls-fonts: implement for macos
this also improves the PartialOrd impl for ParsedFont so that we can
dedup results from core text correctly.

refs: https://github.com/wez/wezterm/issues/347
2021-06-17 17:58:00 -07:00
Wez Furlong
e0b62d07ca ls-fonts: add --list-system flag to list system fonts
heads up @bew!

This is implemented on windows and font-config systems;
needs to be fleshed out for macos.

refs: https://github.com/wez/wezterm/issues/347
2021-06-17 09:11:54 -07:00
Wez Furlong
c7ec47e2c0 add sextant glyphs to custom block glyphs
While I'm in here, teach the font fallback code that it doesn't
need to search for these glyphs when custom block glyphs are
enabled.

refs: https://github.com/dankamongmen/notcurses/issues/1715
refs: #584
refs: #588
2021-06-10 20:38:48 -07:00
Wez Furlong
b03e27adb1 deps: ordered-float 2.1 -> 2.5
closes: https://github.com/wez/wezterm/pull/831
2021-05-31 00:17:18 -07:00
Wez Furlong
717a2157f6 fonts: synthesize dim when a light weight font is unavailable 2021-05-30 20:52:10 -07:00
Wez Furlong
68619fcd92 fixup synthetic boldening
Improve the logic that enables it so that we don't make the wrong
things bolder than they should be.
2021-05-28 15:11:29 -07:00
Wez Furlong
030e517b43 deps: metrics 0.15 -> 0.16, cargo update 2021-05-24 07:57:03 -07:00
Wez Furlong
0519b5499a fonts: can now synthesize italics for bitmap fonts
refs: #815
2021-05-23 08:27:36 -07:00
Wez Furlong
c37ee01222 fonts: synthesize bold when missing
refs: #815
2021-05-22 16:20:35 -07:00
Wez Furlong
2bbe2bd154 fonts: synthesize italics for fonts that don't have it
This commit adds a slant to *scalable* (not bitmap!) fonts whose
originating font attributes requested italics but for for which
the resolved face is not italic.

refs: #815
2021-05-22 16:01:16 -07:00
Wez Furlong
a59e9b1706 update metrics 0.14 -> 0.15
closes: https://github.com/wez/wezterm/pull/778
2021-05-11 19:20:24 -07:00
Wez Furlong
0c4c129b91 fonts: use toast notification for missing glyph notification
Popping open the config error window is a bit of overkill
2021-05-01 16:45:57 -07:00
Wez Furlong
8880979586 Adjust font scaling math again
This commit introduces the knowledge about whether a font is
scalable or was using bitmap strikes (eg: color emoji bitmaps).

Then that information is used to help figure out whether and
how to scale a glyph.

refs: https://github.com/wez/wezterm/issues/685
2021-05-01 16:45:57 -07:00
Wez Furlong
9ccdc157a7 fonts: search locator for fallbacks first
Also add an option to control whether we look in font_dirs for fallback.
Previously we would, but it could lead to some surprising fallback
choices.

The default now is to search locator then built-in.

refs: https://github.com/wez/wezterm/issues/685
refs: https://github.com/wez/wezterm/issues/727
2021-05-01 16:45:57 -07:00
Wez Furlong
f91ca30008 micro-optimize clustering
This improves it by ~4x for long lines, taking it from 120us to ~30us.
2021-04-28 08:25:07 -07:00
Wez Furlong
a2b068d59f fonts: remove some dead code 2021-04-27 22:24:43 -07:00
Wez Furlong
d6c8eb1e3b benchmarking shaping
`cargo test --release -p wezterm-gui -- --nocapture bench_shaping`:

```
running 1 test
100: 139.82µs
1000: 385.333µs
10000: 3.144203ms
test shapecache::test::bench_shaping ... ok
```
2021-04-27 21:48:15 -07:00
Wez Furlong
2520b6bd1d fontconfig: allow for undefined spacing case
I *think* the heart of the issue is that the problematic fonts
don't define a `spacing` property, and we were being stric
about matching it.

This commit changes the behavior to strictly match the spacing
value when it is defined, but to allow an undefined spacing
value to match.

refs: https://github.com/wez/wezterm/issues/726
2021-04-24 11:32:11 -07:00
Wez Furlong
91cd2e22e4 prefer local/specific config for a couple more cases
Avoid using `configuration()` when there may be a more specific
config with overrides that we can resolve.
2021-04-16 09:04:51 -07:00
Wez Furlong
67d8848676 ls-fonts: refine output a bit
It now outputs something that you could conceivably put into
your config file, although the intent is to show the canonical
way to reference the individual fonts that were found, rather
than to specify a fully baked list to paste into a config.

eg:

```
; ./target/debug/wezterm ls-fonts
Primary font:
wezterm.font_with_fallback({
  -- /home/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
  {family="Operator Mono SSm Lig", weight="DemiLight"},

  -- /home/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontConfig
  {family="Operator Mono SSm Lig", weight="DemiLight"},

  -- /home/wez/.fonts/MaterialDesignIconsDesktop.ttf, FontDirs
  "Material Design Icons Desktop",

  -- /home/wez/.fonts/terminus-bold.otb, FontDirs
  {family="Terminus", weight="Bold"},

  -- /home/wez/.fonts/JetBrainsMono-Regular.ttf, FontDirs
  "JetBrains Mono",

  -- /home/wez/.fonts/NotoColorEmoji.ttf, FontDirs
  "Noto Color Emoji",

  -- /home/wez/.fonts/MaterialDesignIconsDesktop.ttf, FontConfig
  "Material Design Icons Desktop",

  -- /usr/share/fonts/terminus-fonts/ter-u32n.otb, FontConfig
  "Terminus",

  -- /home/wez/.fonts/JetBrainsMono-Regular.ttf, FontConfig
  "JetBrains Mono",

  -- /home/wez/.fonts/NotoColorEmoji.ttf, FontConfig
  "Noto Color Emoji",

  -- <built-in>, BuiltIn
  "Last Resort High-Efficiency",

})
```
2021-04-14 09:06:02 -07:00
Wez Furlong
1f6bfd453b fontconfig: remove over-eager unloading
In earlier times, in an effort to avoid bleeding resources into
child processes, the fontconfig wrapper grew some logic to keep
track of how many fontconfig objects we'd loaded so that we could
aggressively unload it when there were none.

Since that time we've evolved differently pessimistic logic that forces
random fds closed when we spawn children so the critical need for unloading
fontconfig is no longer present.

Importantly, with the over-eager unloading, each font query we make
effectively needs to initialize fontconfig from scratch, which is a
fixed minimum cost of ~5-6ms on my system, and I've seen some traces
with a number as high as 100ms (those systems need `fc-cache` to be
run).

Removing the unloading keeps fontconfig initialized so we only pay
the 5ms cost once, then subsequent queries are in the order of 100us.
2021-04-14 07:38:01 -07:00
Wez Furlong
ac6ac53655 fonts: under-specify fontconfig pattern, match ourselves
It seems difficult/impossible to phrase precisely the constraints
that we want when making a font config query, so this changes our
queries to use relative broad family and postscriptname list operations
and then we parse and filter using our own CSS-inspired font matching
criteria.

refs: #689
2021-04-14 07:34:42 -07:00
Wez Furlong
5d386818e1 fontconfig: skip postscript name lookup if already resolved font
I put this condition at the wrong nesting level :-/
2021-04-14 07:34:42 -07:00
Wez Furlong
c54b9dc873 fonts: include the width in the fontconfig debug output 2021-04-14 07:34:42 -07:00
Wez Furlong
3fae59b01b fonts: use cap-height metric to scale fallback fonts
we now compute the ratio of the cap height (the height of a capital
letter) vs. the em-square (which relates to our chosen point size) to
understand what proportion of the font point-size that a given font
occupies when rendered.

When rendering glyphs from secondary fonts we can use the cap height
ratios of both to scale the secondary font such that its effective
cap height matches that of the primary font.

In plainer-english: if you mix say bold, italic and regular text
style in the same line, and you have different font families for
those fonts, then they will now appear to be the same height where
previously they may have varied more noticeably.

For emoji and symbol fonts there may not be a cap-height metric
encoded in the font.  We can however, improve our scaling: prior
to this commit we'd use the ratio of the cell metrics of the two
fonts to scale the icon/emoji glyph, but this could cause the glyph
to be slightly oversized as seen in https://github.com/wez/wezterm/issues/624

If we know the cap-height of the primary font then we can additionaly
apply that factor to scale the emoji to better fit the cell.

While looking at this, I noticed that the aspect ratio calculation
for when to apply to the allow_square_glyphs_to_overflow_width option
had width and height flipped :-(

See also: https://tonsky.me/blog/font-size/
refs: https://github.com/wez/wezterm/issues/624
2021-04-13 23:02:27 -07:00
Wez Furlong
776aedf97e fonts: allow specifying weight/stretch/italic for each fallback font 2021-04-12 22:30:55 -07:00
Wez Furlong
2e34f1a8dd Add wezterm ls-fonts subcommand
At this time it just shows you the fonts that your config matches
and where they came from:

```
; wezterm -n ls-fonts
Primary font:
  wezterm.font("JetBrains Mono", weight="Regular", stretch="Normal", italic=false)
    (/home/wez/.fonts/JetBrainsMono-Regular.ttf, FontConfig)

  wezterm.font("Noto Color Emoji", weight="Regular", stretch="Normal", italic=false)
    (/usr/share/fonts/google-noto-emoji/NotoColorEmoji.ttf, FontConfig)

  wezterm.font("Noto Color Emoji", weight="Regular", stretch="Normal", italic=false)
    (/home/wez/.fonts/NotoColorEmoji.ttf, FontConfig)

  wezterm.font("Last Resort High-Efficiency", weight="Regular", stretch="Normal", italic=false)
    (<built-in>, BuiltIn)

When Italic=true:
  wezterm.font("JetBrains Mono", weight="Regular", stretch="Normal", italic=true)
    (/home/wez/.fonts/JetBrainsMono-Italic.ttf, FontConfig)

  wezterm.font("JetBrains Mono", weight="Regular", stretch="Normal", italic=false)
    (/home/wez/.fonts/JetBrainsMono-Regular.ttf, FontConfig)

  wezterm.font("Noto Color Emoji", weight="Regular", stretch="Normal", italic=false)
    (/usr/share/fonts/google-noto-emoji/NotoColorEmoji.ttf, FontConfig)

  wezterm.font("Noto Color Emoji", weight="Regular", stretch="Normal", italic=false)
    (/home/wez/.fonts/NotoColorEmoji.ttf, FontConfig)

  wezterm.font("Last Resort High-Efficiency", weight="Regular", stretch="Normal", italic=false)
    (<built-in>, BuiltIn)

When Intensity=Bold:
  wezterm.font("JetBrains Mono", weight="Bold", stretch="Normal", italic=false)
    (/home/wez/.fonts/JetBrainsMono-Bold.ttf, FontConfig)

  wezterm.font("JetBrains Mono", weight="Regular", stretch="Normal", italic=false)
    (/home/wez/.fonts/JetBrainsMono-Regular.ttf, FontConfig)

  wezterm.font("Noto Color Emoji", weight="Regular", stretch="Normal", italic=false)
    (/usr/share/fonts/google-noto-emoji/NotoColorEmoji.ttf, FontConfig)

  wezterm.font("Noto Color Emoji", weight="Regular", stretch="Normal", italic=false)
    (/home/wez/.fonts/NotoColorEmoji.ttf, FontConfig)

  wezterm.font("Last Resort High-Efficiency", weight="Regular", stretch="Normal", italic=false)
    (<built-in>, BuiltIn)

When Intensity=Bold Italic=true:
  wezterm.font("JetBrains Mono", weight="Bold", stretch="Normal", italic=true)
    (/home/wez/.fonts/JetBrainsMono-Bold-Italic.ttf, FontConfig)

  wezterm.font("JetBrains Mono", weight="Regular", stretch="Normal", italic=false)
    (/home/wez/.fonts/JetBrainsMono-Regular.ttf, FontConfig)

  wezterm.font("Noto Color Emoji", weight="Regular", stretch="Normal", italic=false)
    (/usr/share/fonts/google-noto-emoji/NotoColorEmoji.ttf, FontConfig)

  wezterm.font("Noto Color Emoji", weight="Regular", stretch="Normal", italic=false)
    (/home/wez/.fonts/NotoColorEmoji.ttf, FontConfig)

  wezterm.font("Last Resort High-Efficiency", weight="Regular", stretch="Normal", italic=false)
    (<built-in>, BuiltIn)

```

refs: #347
2021-04-12 09:44:27 -07:00
Wez Furlong
5ced58c37b Allow disabling re-sorting fallback fonts
The system locator may have a reasonable default ordering
in its list of fallbacks.

refs: #685
2021-04-12 08:03:17 -07:00
Wez Furlong
e6602dde7d fonts: refine font sorting and listing
Sort the available fonts list by family name (rather than full name),
then the styling attributes.

Display the font name in the preferred form for inclusion in the
wezterm config.
2021-04-11 16:53:12 -07:00
Wez Furlong
903c7a47b6 fonts: refine fallback some more
* Log which codepoints we're about to perform fallback resolution for
* Rank the fallback fonts by decreasing amount of coverage
* If a fallback covers the desired codepoints, remove those codepoints
  from the set and reduce, so that we only add the minimal set of
  fallback fonts for the set of codepoints

You can see what triggered fallback processing using:

```
; WEZTERM_LOG=wezterm_font=trace wezterm -n 2> /tmp/font.txt
; grep 'fallback font' /tmp/font.txt
 2021-04-11T21:41:09.653Z TRACE wezterm_font > Looking for \u{d604}\u{c7ac}\u{be0c}\u{b79c}\u{ce58} in fallback fonts
 2021-04-11T21:41:12.132Z TRACE wezterm_font > Looking for \u{f4e9} in fallback fonts
```

refs: https://github.com/wez/wezterm/issues/559#issuecomment-817260512
2021-04-11 14:43:29 -07:00
Wez Furlong
88e9ce8fa5 fonts: remove trace log when Face is dropped
It's overly verbose!
2021-04-10 21:37:00 -07:00
Wez Furlong
406d1044fa fonts: restore messaging about missing glyphs
Now that all platforms know whether the system fallbacks
covered the requested glyph range, it is reasonable to
restore the configuration error window to advise the user
if they are missing fonts for the text they want to display.

refs: https://github.com/wez/wezterm/issues/671
2021-04-10 21:35:58 -07:00
Wez Furlong
22c4407ae9 fonts: macos: improve fallback glyph resolution performance
Previously, we would add a list of ~100 or so fallback fonts to
the shaper's fallback list.

In pathological cases where a wide range of glyphs that have no
corresponding font are repeatedly emitted to the output, we'd
keep loading and unloading that large list of fallbacks in the
hope of finding a match.

Since that code was written, we're now able to compute the
codepoint coverage for ourselves, so teach the core text locator
how to reduce the the list of fallback fonts to just those that
contain the missing glyphs.

Furthermore, we restrict that list to just the normal/regular
weight/stretch/style fonts.

refs: https://github.com/wez/wezterm/issues/671
2021-04-10 21:10:22 -07:00
Wez Furlong
9b7ae8fb23 fonts: move coverage calc into ParsedFont 2021-04-10 20:39:58 -07:00