1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 13:52:55 +03:00
Commit Graph

326 Commits

Author SHA1 Message Date
Wez Furlong
7af61159a8
font: port over radial gradient fills 2023-08-22 06:43:58 -07:00
Wez Furlong
85bb023295
font: refactor: extract common function 2023-08-21 09:40:24 -07:00
Wez Furlong
dd6f2a4d7f
fonts: stub out sweep gradient 2023-08-21 09:38:18 -07:00
Wez Furlong
40083f55b8
font: refactor: reuse ColorLine and gradient structs 2023-08-21 09:30:40 -07:00
Wez Furlong
01fd28fc02
refactor: extract colr from freetype -> colr.rs 2023-08-21 09:19:22 -07:00
Wez Furlong
64dd96917d
fonts: repurpose experimental_svg_fonts -> ignore_svg_fonts
Now we can optionally skip loading svg fonts, making our default
to continue to try to use them.

We don't actually support interpreting svg data, but we do now
support COLR v1 data which is found in some of those same fonts.

refs: https://github.com/wez/wezterm/issues/4148
2023-08-20 22:59:22 -07:00
Wez Furlong
e1044a6d5f
font: colr: add font_colr_rasterizer option
The harfbuzz driven rasterization of COLR glyphs is superior to
my attept at a freetype driven rasterizer, so let's default to
the harfbuzz version.

This change means that the default for most regular glyphs is
freetype, but we'll use harfbuzz for COLR glyphs.
2023-08-20 22:55:02 -07:00
Wez Furlong
017432d0cf
freetype: colr: fixup crazy scaling issue in char selector
Popping open the char selector could result in comedy-sized emoji
that dramatically overflow the bounds.

The reason for that is that glyphcache isn't smart enough to notice
when the glyph.height exceeds the cell_height and allows the glyph
bitmap to be rendered at the rasterized size.

The reason for that glyph being so huge is that freetype is producing
outlines that are too large.  The font metrics have the requested
x and y ppem values (eg: the nominal font size in pixels), but also
x and y scaling values that are not set to 1.  The result is that
the produced extents are too large by those x and y scaling values.

I'm not sure why that is, but it is simplest and most self-contained
to adjust for that scale factor when we rasterize via cairo, so that
is what we do here.
2023-08-20 19:55:56 -07:00
Wez Furlong
b6ba87ad3c
fonts: tidy up some warnings 2023-08-20 17:46:34 -07:00
Wez Furlong
8f4f9653c5
font: adjust metrics for pre-scaled bitmap glyphs
When using the harfbuzz rasterizer with a bitmap glyph, the result
is a rasterized glyph that is pre-scaled to the cell dimensions.

We need to tell glyphcache that that has happened, otherwise it
will apply the same scale factor again.
2023-08-20 17:32:42 -07:00
Wez Furlong
84720a18f0
fonts: stick with ft based metrics for now
I think I've got the right values going in and out, so I think
it's ok to turn this on, but I'm worried about legacy non-opentype
formats that freetype supports but harfbuzz doesn't.

Let's stick with ft's metrics until I find time to validate
the behavior.
2023-08-20 16:52:33 -07:00
Wez Furlong
536c3fa4da
rasterizer/freetype: tune debug logging 2023-08-20 15:31:33 -07:00
Wez Furlong
7264030a28
fonts: adopt fixed crate for freetype fixed-point math
This found at least one bug and should prevent future bugs.
2023-08-20 15:19:30 -07:00
Wez Furlong
1ed4058741
fonts: add freetype COLR 1 raster impl
This isn't fully baked, but it looks mostly ok.
The ghost emoji has a weirdly positioned white patch; there's
something funky with its positioning that needs to be investigated.

There's some copypasta here; a bunch of the cairo related stuff
was copied and adapted from the harfbuzz impl.

I plan to refactor the latter in terms of the former to reduce
the amount of code overall.
2023-08-20 15:19:30 -07:00
Wez Furlong
44e9e09273
font: remove half-baked attempt at rendering svg fonts
It's just too complex. Will focus on COLR 1 instead.
2023-08-20 15:19:30 -07:00
Wez Furlong
6b7ba71f32
fonts: harfbuzz raster: add linear and radial gradients
fixup colors and excessive clipping.

This now looks decent. Still don't support sweep gradients;
those look complex and I'm not sure that I have a font to
test that against.
2023-08-20 15:19:30 -07:00
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