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

257 Commits

Author SHA1 Message Date
Wez Furlong
e298bb7a11 shaping: fix repeated glyphs for Unicode NFD text
harfbuzz can return incomplete overlapping runs when it processes
text in unicode NFD.  Add another check for the case where we've
accumulated the bytes in the range 0-12 and then harfbuzz returns
another range of 6-12.  We coalesce the two together so that we can
pass the full unresolved sequence to the next fallback pass.

refs: https://github.com/wez/wezterm/issues/2032
2022-05-25 06:51:31 -07:00
Wez Furlong
5bf736bd21 add PaneSelect key assignment
This is still a bit of a WIP, but this commit:

* Introduces a new "Modal" concept to the GUI layer. The intent is
  that modal intercepts key and mouse events while active, and renders
  over the top of the rest of the normal display.
  I think there might be a couple of cases where key events skirt
  through this, but this is good enough as a first step.
  Also, the render is forced into layer 1 which has some funny side
  effects: if the modal choses to render transparent, it will poke
  a hole in the window because all the rendering happens together:
  there aren't distinct layer compositing passes.

* Add a new PaneSelect action that is implemented as a modal.
  It uses quickselect style alphabet -> pane label generation and
  renders the labels over ~the middle of each pane using an
  enlarged version of the window frame font.  Typing the label
  will activate that pane.  Escape will cancel the modal.

More styling and docs will follow in a later commit.

refs: #1975
2022-05-23 08:16:52 -07:00
Wez Furlong
0e0bac2576 deps: prune some unused deps 2022-05-19 06:48:09 -07:00
Wez Furlong
e0785311c1 deps: ordered-float
closes: https://github.com/wez/wezterm/pull/1946
2022-05-01 21:43:22 -07:00
Wez Furlong
c1d7ca96db fonts: include glyph names in ls-fonts --text output 2022-04-12 08:34:32 -07:00
Wez Furlong
b35e3b2aad deps: remove pretty_env_loggger
Go directly to the underlying env_logger crate, as pretty_env_logger
hasn't been updated in some time, and I'd like to be able to redirect
the log output to a file more directly, and that feature is in a newer
version of the env logger than pretty_env_logger was pulling in.
2022-04-07 08:24:07 -07:00
Wez Furlong
1b0f5cf256 fonts: treat "charcell" spacing as monospace
Some versions of fontconfig classify some fonts as having charcell
spacing.  We need to consider those as monospace as well.

refs: https://github.com/wez/wezterm/issues/1820
2022-04-06 08:11:34 -07:00
Wez Furlong
11a19a589a fonts: remember bdfs with multiple sizes found in font_dirs
We were using a simple hashmap of name -> parsed file, but for
something like Terminus where there are ~10 files per weight
but for different pixel sizes, we'd end up forgetting files
beyond the first.

This commit tracks the full list in the font db.

related to #1820 in the sense that I needed this to confirm that
we do handle BDFs, but it is not the issue reported there because
that was sourcing fonts via fontconfig on linux.
2022-04-05 20:46:28 -07:00
Wez Furlong
14323a08d1 fonts: adjust descender for scaled fallback fonts
The gist of the issue is that when setting eg: scale=1.2 to draw
a larger CJK glyph, it is drawn at the same descender level, which
makes it more likely to leave the top of the cell.

This commit adjusts the y position by the difference between the
original and the scaled descender so that is less likely to cause
problems.

refs: https://github.com/wez/wezterm/issues/1803
2022-04-03 09:39:48 -07:00
Wez Furlong
a2004a2a7d fonts: workaround broken symbol fonts with 0 advances
The broot icon font has glyphs with horizontal advance set to 0.  That
would cause us to consider the glyph to be zero width, so handle that as
a special case.  Note that it is legit for certain cells to end up with
a zero advance/width during shaping if they represent combining
characters: this is more common in Arabic scripts.

refs: https://github.com/wez/wezterm/issues/1787
2022-03-28 18:05:13 -07:00
Wez Furlong
b65cf803d7 fonts: show aliases in ls-fonts --list-system output 2022-03-27 20:21:09 -07:00
Wez Furlong
6dd3d55b0b fonts: show aliases in ls-fonts output 2022-03-27 19:56:11 -07:00
Wez Furlong
3e91f23452 fix build/tests 2022-03-26 17:00:03 -07:00
Wez Furlong
4e6b348921 fonts: allow fallback-level scaling factor
This commit allows specifying a scaling factor as part of the font
attribute definition.  This scaling factor is fed through to the
rasterizer and the shaper to adjust the actual font size that is
loaded.

The intent is to provide manual control for situations where the
fallback font has a different scale to the primary font and renders
either too small or too large.

The concrete example is
https://github.com/wez/wezterm/issues/1761#issuecomment-1079708207 where
the CJK fallback looks too small.

The scaling factor doesn't influence font metrics so it may also be
desirable to configure line height.

```lua
local wezterm = require 'wezterm'

return {
  line_height = 1.2,
  font = wezterm.font_with_fallback({
    "JetBrains Mono",
    {family="Microsoft YaHei", scale=1.5},
  }),
}
```
2022-03-26 16:37:50 -07:00
Wez Furlong
32bf0d281e fonts: improve font name decoding
freetype can't handle a wide range of encodings for
font names and can return strings like `?????` when
the family name is only present in the font as a non-unicode encoding,
such as Chinese.

This commit improves our handling of the font name table
and prefers to use results from processing that over the
results returned for eg: font family directly from the
freetype API.

refs: https://github.com/wez/wezterm/issues/1761
2022-03-25 23:27:27 -07:00
Wez Furlong
e500c9c5c0 Fix quoting of style field in ls-fonts
refs: https://github.com/wez/wezterm/issues/1762
2022-03-24 18:06:13 -07:00
Wez Furlong
499e7f936f fixup build on windows
refs: #1646
2022-03-12 11:16:21 -07:00
Wez Furlong
7370e1b1a4 fixup mac build
refs: #1646
2022-03-12 11:13:58 -07:00
Wez Furlong
6df26b476e fonts: FontSlant -> FontStyle
after reading around italic vs. oblique, I think "slant" is a misleading
way to categorize this, as slant implies something about the angle of
the font but really the difference between italic and oblique is purely
stylistic and without a suggested angle.

style more closely matches the CSS name which is well understood by
many, so we go for that.

refs: #1646
2022-03-12 09:46:14 -07:00
Wez Furlong
1aad1cf1a2 tweak oblique detection
refs: #1646
2022-03-12 08:50:15 -07:00
Wez Furlong
06b1bb4f2f fix build on macos
refs: #1646
2022-03-12 08:36:52 -07:00
Wez Furlong
84d4187c9a fonts: replace italic boolean with FontSlant enum
There are three slants that are broadly recognized; normal, italic and
oblique.  Prior to this commit, we only considered normal or italic.

This is mostly a mechanical change to replace the boolean with the enum,
and rename the field from `italic` to `slant`.

For the sake of backwards compatibility with existing configs, the lua
helpers for working with fonts continue to accept boolean italic values
and rewrite them to the equivalent slant value.

refs: #1646
2022-03-12 08:16:27 -07:00
Wez Furlong
48d6935f91 fix matching iosevka font when multiple ttcs were installed
refs: https://github.com/wez/wezterm/issues/1630
2022-02-12 14:07:26 -07:00
Wez Furlong
240026de48 refactor: move color parsing into wezerm-color-types crate
Resolves a little bit of the awkward duplication of color types
between some of the crates by factoring them a little bit better.

This is prep for allowing specifying alpha for some colors
in the config.
2022-02-05 13:59:54 -07:00
Wez Furlong
1e32ccbd2f shaping: fix an issue where we'd lose combining marks like U+20d7
For a sequence like `e U+20d7` the intent is to render the `e` with
a vector arrow over the top.

This is typically implemented by fonts as an `e` followed by the
vector glyph (or vice versa), where either one of those may have
a zero advance so that the two elements are combined.

There were two problems here:

* During shaping we'd see the zero advance and assume that the entry
  was useless and skip it
* During rendering, if we didn't think it had any cell width, we'd
  not render it

Cursoring through that particular sequence can hide the vector
mark if the cursor is set to the default block cursor due to annoyances
in how the block cursor is rendered (it changes the fg color to match
the bg, but for elements outside where we think the cursor is, this
makes those elements invisible).

refs: https://github.com/wez/wezterm/issues/1617
2022-02-05 06:19:25 -07:00
Wez Furlong
9de0e1ac90 shaping: improve glyph cell width math
This is a more robust approach; we make a separate pass to figure
out information about the (harfbuzz) cluster for a sequence of glyphs,
and then map that sequence back to the original cell sequence, and
from there compute the total cell width for the run, then distribute
the glyphs across the run.

This should yield more sane results for bidi.

Fixup the x-position math; it was still wonky despite the
efforts in 5f2c905db8 and
af92265ffb

refs: #1570
refs: #1607
refs: #1563
2022-02-01 22:03:50 -07:00
Wez Furlong
5f2c905db8 shaping: feed presentation width from the terminal through to glyph info
This allows unicode_version to be respected again when rendering.

The updated emoji-presentation.sh script now highlights this slightly
better by putting `.` characters after the emoji; unicode version 14
emoji presentation will show the `.` in the 3rd column, while earlier
versions will show it in the 2nd column for glyphs that are sensitive
to the version.

refs: #1607
refs: #1563
2022-02-01 09:23:57 -07:00
Wez Furlong
66183ed336 fix test build 2022-01-28 18:51:49 -07:00
Wez Furlong
4ca1378f1f fonts: allow shaping with additional paragraph context
we don't really use this yet, except internally when we do fallback
2022-01-28 17:19:36 -07:00
Wez Furlong
addc58525c avoid a misaligned slicing for bidi-reordered text
This almost certainly has problems if the reordered text isn't
contiguous though.
2022-01-26 09:20:09 -07:00
Wez Furlong
0324ff66f0 wezterm: add experimental_bidi config option and very basic bidi
This commit is larger than it appears to due fanout from threading
through bidi parameters.  The main changes are:

* When clustering cells, add an additional phase to resolve embedding
  levels and further sub-divide a cluster based on the resolved bidi
  runs; this is where we get the direction for a run and this needs
  to be passed through to the shaper.
* When doing bidi, the forced cluster boundary hack that we use to
  de-ligature when cursoring through text needs to be disabled,
  otherwise the cursor appears to push/rotate the text in that
  cluster when moving through it! We'll need to find a different
  way to handle shading the cursor that eliminates the original
  cursor/ligature/black issue.
* In the shaper, the logic for coalescing unresolved runs for font
  fallback assumed LTR and needed to be adjusted to cluster RTL.
  That meant also computing a little index of codepoint lengths.
* Added `experimental_bidi` boolean option that defaults to false.
  When enabled, it activates the bidi processing phase in clustering
  with a strong hint that the paragraph is LTR.

This implementation is incomplete and/or wrong for a number of cases:

* The config option should probably allow specifying the paragraph
  direction hint to use by default.
* https://terminal-wg.pages.freedesktop.org/bidi/recommendation/paragraphs.html
  recommends that bidi be applied to logical lines, not physical
  lines (or really: ranges within physical lines) that we're doing
  at the moment
* The paragraph direction hint should be overridden by cell attributes
  and other escapes; see 85a6b178cf

and probably others.

However, as of this commit, if you `experimental_bidi=true` then

```
echo This is RTL -> عربي فارسی bidi
```

(that text was sourced from:
https://github.com/microsoft/terminal/issues/538#issuecomment-677017322)

then wezterm will display the text in the same order as the text
renders in Chrome for that github comment.

```
; ./target/debug/wezterm --config experimental_bidi=false ls-fonts --text "عربي فارسی ->"
LeftToRight
 0 ع    \u{639}      x_adv=8  glyph=300  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 2 ر    \u{631}      x_adv=3.78125 glyph=273  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 4 ب    \u{628}      x_adv=4  glyph=244  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 6 ي    \u{64a}      x_adv=4  glyph=363  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 8      \u{20}       x_adv=8  glyph=2    wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
 9 ف    \u{641}      x_adv=11 glyph=328  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
11 ا    \u{627}      x_adv=4  glyph=240  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
13 ر    \u{631}      x_adv=3.78125 glyph=273  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
15 س    \u{633}      x_adv=10 glyph=278  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
17 ی    \u{6cc}      x_adv=4  glyph=664  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
19      \u{20}       x_adv=8  glyph=2    wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
20 -    \u{2d}       x_adv=8  glyph=276  wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
21 >    \u{3e}       x_adv=8  glyph=338  wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
```

```
; ./target/debug/wezterm --config experimental_bidi=true ls-fonts --text "عربي فارسی ->"
RightToLeft
17 ی    \u{6cc}      x_adv=9  glyph=906  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
15 س    \u{633}      x_adv=10 glyph=277  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
13 ر    \u{631}      x_adv=4.78125 glyph=272  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
11 ا    \u{627}      x_adv=4  glyph=241  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 9 ف    \u{641}      x_adv=5  glyph=329  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 8      \u{20}       x_adv=8  glyph=2    wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
 6 ي    \u{64a}      x_adv=9  glyph=904  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 4 ب    \u{628}      x_adv=4  glyph=243  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 2 ر    \u{631}      x_adv=5  glyph=273  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 0 ع    \u{639}      x_adv=6  glyph=301  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
LeftToRight
 0      \u{20}       x_adv=8  glyph=2    wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
 1 -    \u{2d}       x_adv=8  glyph=480  wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
 2 >    \u{3e}       x_adv=8  glyph=470  wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
;
```

refs: https://github.com/wez/wezterm/issues/784
2022-01-25 09:00:53 -07:00
Wez Furlong
7ccce20544 fonts: allow harfbuzz to guess the script
Our default meant that harfbuzz wouldn't engage preprocessing
steps that normalized the text to NFC.  With this change we now
correctly normalize and render certain compositions that were
totally borked previously.

refs: https://github.com/wez/wezterm/issues/1573
refs: https://github.com/wez/wezterm/issues/1474
2022-01-21 10:10:39 -07:00
Wez Furlong
2deba1ece4 fonts: fix ligature widths at the cost of unicode version conformance
refs: #1563
2022-01-19 18:16:48 -07:00
Wez Furlong
4bc10a75d9 fonts: adopt k9 snapshots for shaper tests 2022-01-19 18:01:07 -07:00
Wez Furlong
e4ed2c93e2 encoding my preferred import grouping in the rustfmt config
This uses an unstable option in rustfmt, you `cargo +nightly fmt`
needs to be used to format the code correctly.
2022-01-17 13:50:51 -07:00
Wez Furlong
070c4030c6 Bundle Symbols Nerd Font Mono
Built using:

```
./FontForge-2020-11-07-21ad4a1-x86_64.AppImage --script $PWD/font-patcher "$PWD/src/unpatched-fonts/NerdFontsSymbolsOnly/NerdFontsSymbolsOnly Template 1000 em.ttf" --powerline --use-single-width-glyphs -out /tmp/nerd-fonts-out --fontawesome --fontawesomeextension --fontlinux --octicons --codicons --powersymbols --powerline --powerlineextra --mdi --weathericons
```

which is everything *except* Pomicons at the time of writing, pending
clarifications of its distribution license
(https://github.com/ryanoasis/nerd-fonts/issues/266)

refs: https://github.com/wez/wezterm/issues/1521
2022-01-16 16:04:35 -07:00
Wez Furlong
79f7f63064 deps: ordered-float -> 2.10
closes: https://github.com/wez/wezterm/pull/1524
2022-01-09 19:25:48 -07:00
Wez Furlong
c05491f831 fonts: fix fontconfig monospace alias resolution
This got broken by 58ece29f00
This commit structures things so that we're less likely to overlook
this in the future!

cc: @unrelentingtech

refs: #1250
2022-01-02 08:26:19 -07:00
Wez Furlong
58ece29f00 fonts: defer best match until we have font_dirs + locator + builtin
A user reported an issue where having just Roboto Thin installed
caused the title font to use that one, rather than the desired
Roboto Bold.

This commit adjusts the font matching code to accumulate candidates
from each of the font_dirs, locator and built-in font locations,
and then find the best match.
2022-01-01 11:34:39 -07:00
Wez Furlong
1e7d552844 fonts: replace font_ptr with a font id
I'm running down a weird thing where the main font renders weirdly
when the title font is 12 pt vs the main font 10 pt.

I thought there might have been a cache invalidation issue and
realized that we could have an A-B-A style issue with the font_ptr
stuff, so I replaced it with an incrementing id.

That didn't fix the thing I was looking at, but does feel a bit
nicer overall.
2021-12-30 19:09:30 -07:00
Wez Furlong
a322c3e8d2 fonts: title fonts now fall back to main font list 2021-12-30 18:28:49 -07:00
Wez Furlong
cbe0bc21dc gui: fonts: just use Roboto for default title font on all systems 2021-12-30 18:10:25 -07:00
Wez Furlong
00a393b3d1 gui: bundle and use Roboto for title font on Linux + Windows
The default we use on macOS looks decent.  Roboto is a similar
looking font that we can use for the other platforms.
I may make it the same on all three once I've had a chance
to compare it on a mac.
2021-12-30 17:51:22 -07:00
Wez Furlong
f4fab10e69 gui: box model style layout/render for fancy tab bar
This commit adds a CSS box model inspired element / layout
facility, and replaces the hand implemented fancy tab bar
element render.

This makes the code for fancy tab bar much easier to read
and update.

The right status area now expands to the full height of the
tab bar area, and uses a line height of 2.0, which makes
it line up nicely in the tab bar.
2021-12-28 00:14:54 -07:00
Wez Furlong
a78ff883a9 windows: query the system caption font
Use this for the tab bar font by default
2021-12-25 09:54:31 -07:00
Wez Furlong
714e74e7af fonts: move computation of title font to wezterm-fonts
Rather than hardcode a fixed default value in the config crate, define
the default as optional and leave it to the font crate to compute
the value.

This is a step towards allow introducing system dependent GUI related
code to resolve/understand the title font: we can't put that directly
in the config crate.
2021-12-25 07:49:46 -07:00
Wez Furlong
4a01bf9bf2 font: improve alpha channel in rasterizer
Previously, we'd set it to 100% if any non-zero channel was present,
but this resulted in stronger/darker outlines that were especially
noticeable when the window background was transparent and over a
bright background.

This commit sets the alpha based on the coverage provided to us
by freetype and looks better with and without a transparent window
background.

@dmfay: I think this might be behind what you noticed in your last
comment on #1025.

refs: #1325
2021-12-24 10:39:33 -07:00
Wez Furlong
bd09b568ed font: add missing bound check for font coverage.
Thanks to @klamonte for finding this!

refs: #1433
2021-12-23 08:05:22 -07:00
Wez Furlong
ddedfa7d70 fonts: almost there... 2021-12-20 23:36:13 -07:00
Wez Furlong
f257fe0c8d fonts: fix windows build 2021-12-20 22:30:04 -07:00