1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-26 08:25:50 +03:00
Commit Graph

310 Commits

Author SHA1 Message Date
Wez Furlong
f1c82e8894
fonts: harfbuzz raster: use cairo
This meshes well with the sequence of instructions that we
get from harfbuzz.

This will need some vendoring to integrate with wezterm's build
on all platforms; that can come later.

Still need to hook up gradients.
2023-08-20 15:19:27 -07:00
Wez Furlong
4ddcad7ef6
fonts: harfbuzz raster: rejigger
We need to make a couple of passes over the paint instructions,
and making a nice interface around FontFuncs and DrawFuncs was
taking up a lot of boilerplate.

Adjust so that we accumulate parsed PaintOps and DrawOps instead.

This makes the code smaller and easier to grok.

Still has trouble rasterizing the new noto color emoji font though.
2023-08-20 15:18:10 -07:00
Wez Furlong
75b72c9520
fonts: use harfbuzz ot funcs when shaping
I think this fixes up the discrepancy I had in metrics with images.
The "solution" is to tell harfbuzz to scale to the selected
bitmap strike size instead of the the computed pixel size for
the current settings.
2023-08-20 15:18:10 -07:00
Wez Furlong
25697d406e
font: add helper to swap red/blue channels in an image 2023-08-20 15:18:09 -07:00
Wez Furlong
847b1b7ab9
font: refactor: extract cropping helper 2023-08-20 15:18:09 -07:00
Wez Furlong
560fa1f552
fonts: harfbuzz raster: add basic glyph rendering 2023-08-20 15:18:09 -07:00
Wez Furlong
c7b689e369
fonts: starting building out harfbuzz rasterizer
This seems like it might be a way to get COLR support without
too much effort.

This commit just adds bitmap image support as a first step
2023-08-20 15:18:09 -07:00
Wez Furlong
58a2a30623
Add vendored cairo-sys-rs crate
I'm experimenting with using cairo's 2D graphics for glyph related
drawing operations, and perhaps more stuff in the UI in the future.

The challenge is that no one has yet encapsulated its build in a
cargo-friendly way.

This commit is that attempt.

The strategy is this:

* `deps/cairo` is ostensibly the same thing as https://github.com/gtk-rs/gtk-rs-core/tree/master/cairo/sys
  which is the cairo-sys-rs crate
* Its build.rs has been replaced with a version that builds from the C
  sources that are found in-tree; it will never look for the system
  cairo library
* A pair of scripts to import pixman (a required dep of cairo) and
  cairo itself in a repeatable way are include, for if/when we need
  to update the vendored sources
  Cairo is a mature library and doesn't release very often.
* The workspace sets a patch for crates.io so that cairo-rs has
  its cairo-sys-rs dep redirected to the local build.

I'm not planning to upstream this stuff to gtk-rs-core as full cairo
depends on a lot more things than are dealt with here, so it would be a
PITA to handle that generally.

This vendoring strips out things that are not used, so the cairo
library that remains:

* Is not internally thread safe; no TLS or mutex support is enabled
  in either of them. That's fine because the high level cairo-rs
  wrapper is not Send+Sync, which means that rust will only allow
  it to be used single threaded anyway.
* Only has the basic recording and image surfaces
* No platform support for win32/xlib/xcb and so on
2023-08-20 14:59:29 -07:00
Wez Furlong
b365225695
fonts: svg: half-assed attempt to set the y-bearing
This is not right, but better than not setting it.
2023-08-15 11:27:34 -07:00
Wez Furlong
edbf4ac1e4
add experiemental svg font support
The vertical alignment is wonky, and some glyphs have the wrong
aspect and are missig colors. eg: the watermelon glyph in Noto Color
Emoji (U+1f349).

Turn this off by default, and skip loading fonts that have svg by
default.
2023-08-15 10:33:45 -07:00
Wez Furlong
8c77ea1d9e
fonts: allow svg fonts to take precedence over bitmap versions
But note that we don't currently render svg

refs: https://github.com/wez/wezterm/issues/4148
2023-08-14 20:23:17 -07:00
Wez Furlong
085e8da478
macos: fonts: use alternative fallback approach
The approach we were using previously was to ask macOS for the fallback
font list, but it didn't include the correct fonts for certain
codepoints.

Switch to using an alternative API that asks macOS which font to use for
a specific codepoint.

refs: #4099
2023-08-05 18:15:08 -07:00
Wez Furlong
33187d0e79
macos: fonts: use full list of user fallback languages
The hope was that this would find more fonts, but it doesn't actually
help for this case.

refs: https://github.com/wez/wezterm/issues/4099
2023-08-05 17:33:59 -07:00
Wez Furlong
f5173c48a7
fonts: micro optimize by caching size calcs
Don't ask harfbuzz to recompute on every shaper call, just those
where the size has changed.
2023-05-29 10:36:59 -07:00
Wez Furlong
e4b96bd9bb
update Symbols Nerd Font Mono to v3.0.1 2023-05-21 09:34:10 -07:00
Michael Rosenberg
2f0bcb3c20 Fixed double-skewing behavior 2023-04-24 22:13:50 -07:00
Wez Furlong
8582165ffc
add display_pixel_geometry config option for subpixel geometry
refs: #3422
2023-04-01 11:05:09 -07:00
Wez Furlong
1531dd8471
update tests for updated JetBrainsMono 2023-03-25 07:21:36 -07:00
Wez Furlong
843b9e8fc4
update bundled JetBrainsMono to 2.304 2023-03-25 07:18:29 -07:00
Jalil David Salamé Messina
d541e2e13d fix(clippy): Remove closures where possible
- Removes closures and function calls for types that implement default:

  ```rust
  // Change
  let _my_str = get_str().unwrap_or(String::new);
  // To
  let _my_str = get_str().unwrap_or_default();
  ```

- Uses the `.cloned()/.copied()` methods where possible
- Use function pointer instead of simple closure

May improve performace, as closures generate more code, and this might
unlock some inlining opportunities.
2023-03-19 08:41:38 -07:00
Jalil David Salamé Messina
191aacc7d7 fix(clippy): Use faster methods on Iterators
- Use `find` instead of `position(..).next()`
- Use `any` instead of `position(..).next().is_some()/.is_none()`
- Use `first/next` instead of `get(0)/nth(0)`
- Prefer `for` loops over `while let` loops on iterators

May improve performance.
2023-03-19 07:29:23 -07:00
Jalil David Salamé Messina
cb9dc3a800 fix(clippy): Remove unnecessary clone/to_string calls 2023-03-16 07:40:12 -07:00
Pavel Roskin
a7cc87f30f gdi.rs: Avoid non-idiomatic iterations over Option, they cause warnings 2023-03-05 13:16:49 -08:00
Wez Furlong
4ec428ff75
config: allow using bright but not bold text when brightening text
In https://github.com/wez/wezterm/issues/2932 the user desired to have
brightened text without the boldness, as they were accustomed to that
behavior in a couple of other terminal emulators.

This commit changes the `bold_brightens_ansi_colors` from a simple
boolean to a tristate that allows for not changing the brightness,
changing the brightness, and changing the brightness while adjusting
the boldness down to normal levels.

boolean values are accepted for backwards compatibility.
2023-01-09 15:19:17 -07:00
Wez Furlong
ab8a4f129c
command palette: first pass
This commit introduces a rough first pass at a command palette modal.
It is an adaptation of the emoji character selector and needs
refinement.

Importantly, the default pane selector key assignment now calls
into this new command palette instead.

refs: https://github.com/wez/wezterm/issues/1485
2022-12-22 20:24:57 -07:00
Wez Furlong
9923ae20b5
env_logger -> 0.10
closes: https://github.com/wez/wezterm/pull/2803
2022-11-27 21:37:25 -07:00
Wez Furlong
68c754b1f3
fonts: improve error message slightly
refs: https://github.com/wez/wezterm/issues/2772
2022-11-22 15:46:21 -07:00
Wez Furlong
0516b61f62
lfucache: improve LFU algorithm and structure
Do it "more properly": use intrusive list linkage to manage three
indices:

* hash lookup
* recency
* frequency

eviction is frequency based, but in order to avoid things that were
super hot in the past and that are no longer hot clogging up the cache,
eviction will incrementally age out least recently used entries that
haven't been active in the span of some number of get/put operations.

Aging scales down the frequency value to reduce its strength, so an aged
item isn't necessarily immediately a candidate for removal, it just
makes it more likely to be picked up by the frequency based removal as
it goes unused for an extended period.
2022-11-14 10:00:49 -07:00
Wez Furlong
b1faba9d8a deps: upgrade finl_unicode to 1.2 2022-10-23 12:07:00 -07:00
Wez Furlong
7cc91696e9 fonts: fix shaping for U+28 U+FF9F
This sequence forms a grapheme with cell_width=2, but harfbuzz returns
it as two distinct clusters, causing our prior logic to shape them
independently from different fonts, but our logic for assessing width
would resolve them both to the same cell and double-count their width,
leading to issues with the rendered result.

This commit revises our clustering logic to add a pass that compares
the harfbuzz cluster positions with the cell-based positions from
the presentation_width that may have been provided.  We use the starting
cell positions from that to order and de-dup so that clusters aren't
split in the wrong place.

refs: https://github.com/wez/wezterm/issues/2572
2022-10-15 08:42:07 -07:00
Wez Furlong
85db555b37 deps: update finl_unicode 2022-09-16 07:47:33 -07:00
Wez Furlong
10cd78a81a fonts: remove last resort font
I was going to upgrade to the unicode 15 font, but in testing this I
decided that the logic is slightly complex and the glyphs are often
difficult to see at most terminal font sizes, which generates questions
from users, so just fall back to notdef.
2022-09-15 08:23:58 -07:00
Wez Furlong
72674f5d28 perf: reduce number of calls to Line::get_cell
The clustered line storage impl of get_cell() is O(column-index)
as cells have to be iterated in order.

The render pass was calling it 3 times to resolve information
about the cursor; reduce that to just once.

It was also calling it once per cell to determine whether the
cell needed to be replaced with a custom glyph if custom block
glyphs were enabled, making it accidentally quadratic!

While it wasn't especially expensive, it did show up in profiling,
so this commit removes that call: we can cache the block glyph
key in the shaper info which is a better place for it anyway,
so that's what we do.

Similarly, there was some extraneous work to call get_cell
when computing some shaper info; remove that too!

That one might be slightly contentious: the is-followed-by-space
logic used to check the successor cell by index to see if it
was a space, but now looks at the successor shaped glyph to see
if it was a space. That might actually be a better choice, but
it may have some ripple effects.
2022-09-10 09:11:22 -07:00
Wez Furlong
96c4e7e9b9 Switch to finl_unicode for grapheme clustering
According to its benchmarks, it's almost 2x faster than
unicode_segmentation.  It doesn't appear to make a visible
difference to `time cat bigfile`, but I'll take anything
that gives more headroom for such little effort of switching.
2022-09-10 07:15:49 -07:00
Wez Furlong
ad35b9dc21 Add compile time features to allow building without vendored fonts
closes: #2305
2022-09-09 08:53:39 -07:00
Wez Furlong
86c9d78148 shaper: restart presentation=None from font_idx=0
When falling back to presentation-ambivalent font lookup, restart
our shaper run from font_idx=0 rather than the current font index.

For:

```
wezterm  ls-fonts --text "$(printf \\U1faf0)"
```

the current font index was the last resort font so we'd never
search over anything useful in the second pass.

Looking back at 4fc8dfb374, I can't
see a good reason for starting at the later offset.
2022-09-05 17:10:04 -07:00
Jan Katins
29f5d066b8 Fix typo in harfbuzz.rs 2022-09-05 06:01:59 -07:00
Wez Furlong
68380188e8 fix hangul NFC shaping
We were getting data like this back from harfbuzz:

shaped font_idx=0 "파인더에서 만든 폴더" as: [.notdef=0+448|.notdef=0+448|.notdef=6+448|.notde=6+448|.notdef=6+448|.notdef=15+448|.notdef=15+448|.notdef=21+448|.notdef=21+448|.notdef=27+448|.notdef=27+448|space=33+448|.notdef=34+448|.notdef=34+448|.notdef=34+448|.notdef=43+448|.notdef=43+448|.notdef=43+448|space=52+448|.notdef=53+448|.notdef=53+448|.notdef=53+448|.notdef=62+448|.notdef=62+448]

which had a series of discontiguous and repeated runs for the same
cluster/region, but due to a logic error, we weren't coalescing them
together and were passing somewhat nonsensical ranges to the
next font for shaping.

This commit "simply" ensures that we code the checks for codepoint==0
(the `.nodef` seen above) and the results are at least correct
for this particular case.

refs: https://github.com/wez/wezterm/issues/2482
2022-09-04 21:24:30 -07:00
Wez Furlong
c38816fc6e fontconfig: allow proportional fallbacks for codepoints
refs: https://github.com/wez/wezterm/discussions/2468#discussioncomment-3528085
2022-09-04 07:05:58 -07:00
liushuyu
9a6cee2b59 font: fix the function signature for log_buffer_message ...
... this will fix the build on non-x86 architectures
2022-09-04 06:41:25 -07:00
Wez Furlong
c4d19afa75 adventures in shaping
This commit is a result of debugging a problem with a particular font
where a VS2 variation of a glyph produced incorrect shaping.

Further investigation showed that this was specific to using freetype
font functions and that switching to opentype functions produces the
correct shaping information in that case.

Further-further investigation showed that this difference in behavior
was really due to the font file being out of spec and freetype returning
unexpected data as a result.

This commit allows switching to using harfbuzz's own opentype font+face
(rather than freetype) and/or switching the freetype-based font to using
opentype font functions.  These two options don't yield equivalent
results in the wezterm integration: a couple of our shaping tests
fail due to the x-advances not being the same. Those can be drastically
different in some cases (eg: I seem to get 0 for certain bitmap strikes,
and for Roboto the value is off by a factor of about 1.5).

This is incomplete and not something I want to turn on by default at
the moment, but I don't want to lose this work, hence this commit.

refs: https://github.com/wez/wezterm/issues/2475
refs: https://github.com/harfbuzz/harfbuzz/issues/3806
2022-09-03 08:34:19 -07:00
Wez Furlong
2af5a05d19 harfbuzz: allow creating an OT Face + Font
We've been using hb with freetype faces. This gives us the option
of using harfbuzz's own opentype based face and function set.

It doesn't change any behavior: this is just newly available code.

refs: https://github.com/wez/wezterm/issues/2475
2022-09-03 08:25:43 -07:00
Wez Furlong
ed731a0d8d Add CharSelect modal for emoji/nerdfont/unicode input
CTRL-SHIFT-U is a new default key assignment for this new modal.
It opens up a fuzzy searchable browser that defaults to showing
emoji/emoticons.  The category can by cycled through the suggested
emoji categories using CTRL-r.  Unlike the system emoji palette,
wezterm includes a category for nerdfont symbols, and another
that is a list of all unicode codepoint names, so you should be
able to browse for pretty much any codepoint you can think of.

The modal also allows fuzzy searching based on:

* The official unicode name
* The github shortcode
* codepoint value in hex

so if you know the codepoint value but not the name, you can
still find a way to input what you're looking for.

Pressing Enter will copy the selected item to the clipboard
send it to the active pane, and cancel the modal. You can therefore
repeat the insert by simply pasting.

I plan to add frecency to this in a later commit: that way the
frequently/recently used selections will show in a category of
their own and make it easier to re-input them.

refs: https://github.com/wez/wezterm/issues/2163
2022-08-31 18:15:28 -07:00
Wez Furlong
53aef1ac6e fix build; last commit passed cargo check but not cargo build!? 2022-07-14 09:49:07 -07:00
Wez Furlong
df6a6667a4 fonts: allow glyph not found warnings to show after config reload
refs: #2188
2022-07-14 09:07:15 -07:00
Wez Furlong
49e3fd4c9e fonts: limit missing glyph notification to once per hour
refs: https://github.com/wez/wezterm/issues/2188
2022-07-14 07:26:04 -07:00
Wez Furlong
c97e8e564e fonts: allow setting assume_emoji_presentation per font
This allows the user to specify what happens if they have an emoji
font that doesn't match our built-in heuristics.
2022-07-08 21:14:16 -07:00
Wez Furlong
b98fb8410b fonts: assume emoji presentation for fonts with "moji" in their name
previously, we'd match "emoji", but that wouldn't match openmoji.
2022-07-08 21:01:35 -07:00
Wez Furlong
21e6fcedd9 fonts: add negative cache into LoadedFont
Continuing from 427e4a0a84, we
can't just omit the negative cache as that leads to problems
like <https://github.com/wez/wezterm/issues/2165>, so this
commit restores it but moves it into LoadedFont, so that we
should stop looking for a given styled font after the first
attempt.

refs: https://github.com/wez/wezterm/issues/2165
2022-06-23 06:36:03 -07:00
Wez Furlong
427e4a0a84 fonts: remove no_glyphs cache from FontConfigInner
This avoids a confusing situation where we'd not bother to resolve
a font for a given codepoint for say bold text if we had previously
resolved it for normal text.

This hashset would be more useful if we maintained a mapping of
codepoint to font at that layer, but we don't.

The simplest thing to do for this is to allow the search to continue
and succeed.

refs: https://github.com/wez/wezterm/issues/2158
refs: https://github.com/wez/wezterm/issues/1913
2022-06-22 06:17:16 -07:00