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

194 Commits

Author SHA1 Message Date
Wez Furlong
9b4f7e78d6 fonts: properly fixup emoji baseline
The previous commit was partially OK, but the main cause of
emoji being wonky was this bit of macos specific code that I
added ages ago.

Remove that hack and the portion of the code from the previous
commit that was working to undo it.

This should make the baselines consistent across all platforms.

refs: #1203
2021-10-06 19:40:30 -07:00
Wez Furlong
e25deaaed1 fonts: align emoji fonts with the primary font baseline
refs: #1203
2021-10-05 22:01:21 -07:00
Wez Furlong
d430d3eef1 fix: title_font didn't respect changed dpi 2021-10-04 21:09:31 -07:00
Wez Furlong
cb47f61116 fonts: fix build on win32 2021-10-02 18:38:29 -07:00
Wez Furlong
401719fb01 fonts: improve cap-height and use_cap_height_to_scale_fallback_fonts
We now compute the cap-height from the rasterized glyph data.

Moved the scaling action of use_cap_height_to_scale_fallback_fonts from
glyphcache into the font resolver: when enabled, and we have data
about the baseline font and the font being resolved, then the resolving
font will be scaled such that the cap-height of both fonts has the same
pixel size.

The effect of this is that `I` glyphs from both fonts should appear to
have the same height.

Added a row of `I`'s in differing styles at the bottom of styles.txt
to make this easier to visualize.

refs: #1189
2021-10-02 18:23:51 -07:00
Wez Furlong
1bf8c34cb2 fonts: really fix build on win32
refs: #1189
2021-10-02 10:03:50 -07:00
Wez Furlong
23d1949acd fonts: fixup win32 build
refs #1189
2021-10-02 09:48:46 -07:00
Wez Furlong
d3c748e18f fonts: enable matching against bitmap strike sizes
This is to handle situations such as some versions of the Terminus
bitmap font, where the individual bitmap strike sizes are broken
out across multiple individual files.

Font matching now passes down the nominal pixel height based on
the current DPI and font scale factor, and will use that to select
the font file that has the closest pixel size.

Previously, it would be potentially undefined which of the Terminus
font files would be selected.

refs: https://github.com/wez/wezterm/issues/1189
2021-10-02 09:33:55 -07:00
Wez Furlong
e287474973 fonts: fix a spacing issue for Goho OTB font
This font is a bit funky; the bitmap strikes are only 4px wide:

```
; ftdump gohufont.otb
There is 1 face in this file.

----- Face number: 0 -----

font name entries
   family:              Gohu GohuFont
   style:               Regular
   postscript:          UNAVAILABLE
   created:             1904-01-01
   modified:            1904-01-01
   revision:            1.00
   glyph count:         1694

font type entries
   FreeType driver:     truetype
   sfnt wrapped:        yes
   type:                fixed size
   direction:           horizontal
   fixed width:         no
   glyph names:         no

fixed size
     0: height 11, width 3
        size 11.000, x_ppem 11.000, y_ppem 11.000
     1: height 14, width 4
        size 14.000, x_ppem 14.000, y_ppem 14.000

charmaps (1)
   0: format  4, platform 3, encoding  1   language 0 (active)
```

but using that the cell size isn't right.

We draw from the metrics we compute via cell_metrics to get more
information; we don't get a valid height from that (just 0!), but
we do get the much more plausible width of 8 pixels.

So we take the max of the two techniques for figuring the metrics.

That appears to work out, and also doesn't appear to break emoji
fonts.

refs: #1165
2021-09-25 08:57:26 -07:00
Wez Furlong
f648d8a6a5 deps: Upgrade to freetype 2.11 2021-09-25 00:43:23 -07:00
Wez Furlong
c1515404b7 fonts: improve(!) identifying italic fonts
refs: #1162
2021-09-22 11:00:06 -07:00
Wez Furlong
0ee1f7529b fonts: Fix shaping metrics
This was a bit of a PITA to run down; the essence of the problem
was that the shaper was returning an x_advance of 0 for U+3000,
which caused wezterm's shaping layer to elide that glyph.

I eventually tracked down the x_advance to be the result of
scaling by an x_scale of 0, which in turn is the result of
harfbuzz not knowing the font size.

The critical portion of this diff is the line that advises
harfbuzz that the font has changed after we've applied the
font size.

The rest is just stuff to make it easier to debug and verify.

This:

```
printf "x\u3000x."
```

Now correctly renders on screen as "x  x".

fixes: #1161
2021-09-22 08:34:40 -07:00
Wez Furlong
140d9fd345 fix font matching issue with .ttcs holding multiple families
refs: #1137
2021-09-12 13:31:21 -07:00
Wez Furlong
86f0bae1db fonts: tidy up fontconfig charset acceleration
and add a changelog entry!

refs: #250
2021-09-06 11:05:16 -07:00
HMH
466e5cab21 Speedup font loading with fontconfig and freetype.
- If possible use fontconfig to obtain character coverage instead of
  going through all glyphs using freetype.
- `FT_Get_First_Char` typically returns ranges of continuous glyphs itself
and it is far cheaper (I measured a speedup of about 7 times while
catting a large file with lots of funny unicode) to add a range to the
glyph coverage instead of adding each glyph individually.
- Permit adding a range to a RangeSet without performing checks to speed
  up things even further.
2021-09-06 10:53:01 -07:00
Wez Furlong
10b64abec8 fonts: constrain to a single thread for fallback resolution
@H-M-H noticed and suggested this; rather than spawning a thread
for potentially every cluster of graphemes that are being displayed
before we've located a font, constrain things to a single thread
so that we don't burn CPU trying to process the same results
in an excessive number of threads.
2021-09-06 10:48:00 -07:00
Wez Furlong
3f212012f2 fix black pixel "halo"
Need to only set alpha to 1 if the pixel is not transparent

closes: #1110
2021-09-06 09:31:50 -07:00
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