299 Commits

Author SHA1 Message Date
Chris Marchesi
e0d458004f font/sprite: add Powerline face
This adds the Powerline face to our set of built-in faces, which
represents glyphs that are used to draw Powerline-style shell prompts
and status lines.

Since these are used similar to box-drawing characters, alignment is
important, and this gives us the most control in preventing related
artifacts.

This initial commit is scaffolding and support for the various solid
triangles - additional glyphs will come in other commits.

Fixes #675.
2023-11-23 01:29:12 -08:00
Mitchell Hashimoto
89fe07271e font: fallback fonts need to deinit their unused deferred faces
Fixes #885

Interestingly, this isn't that big of a leak for whatever reason on
macOS. But on Linux with fontconfig this is a MASSIVE memory leak.
2023-11-20 21:05:01 -08:00
Mitchell Hashimoto
42c4f52711 font: shaper should not look up U+200D for consistent fonts
Related to #914

U+200D is the zero-width joiner character used for multi-codepoint
Emojis. When faced with a multi-codepoint grapheme, the font shaper must
find a font that provides _all codepoints_ consistently. However, U+200D
isn't meant to be provided by any font. As a result, the font shaper
search ends up iterating over every font looking for a match.
2023-11-20 19:12:37 -08:00
Krzysztof Wolicki
44a48f62f1 change unmodified vars to consts in anticipation of zig changes 2023-11-17 15:46:46 +01:00
Mitchell Hashimoto
947ebc0697 font/coretext: split typographic leading equally when calculating cell height
This maybe is a robust way to get Monaspace fonts working.

Previously, we used leading as part of the calculation in cell height. I
don't remember why. It appears most popular monospace fonts (Fira Code,
Berkeley Mono, JetBrains Mono, Monaco are the few I tested) have a value
of 0 for leading, so this has no effect. But some fonts like Monaspace
have a non-zero (positive) value, resulting in overly large cell
heights.

The issue is that we simply add leading to the height, without modifying
ascent. Normally this is what you want (normal typesetting) but for
terminals, we're trying to set text centered vertically in equally
spaced grid cells. For this, we want to split the leading between the
top and bottom.
2023-11-10 21:41:49 -08:00
Mitchell Hashimoto
a4ca581219 font: load valid union field for loaded deferred fonts 2023-11-09 11:06:58 -08:00
Mitchell Hashimoto
3d8dd0783a font: if VS15/16 not specified, prefer any presentation in explicit font
Fixes #845

Quick background: Emoji codepoints are either default text or default
graphical ("Emoji") presentation. An example of a default text emoji
is ❤. You have to add VS16 to this emoji to get: ❤️. Some font are
default graphical and require VS15 to force text.

A font face can only advertise text vs emoji presentation for the entire
font face. Some font faces (i.e. Cozette) include both text glyphs and
emoji glyphs, but since they can only advertise as one, advertise as
"text".

As a result, if a user types an emoji such as 👽, it will fallback to
another font to try to find a font that satisfies the "graphical"
presentation requirement. But Cozette supports 👽, its just advertised
as "text"!

Normally, this behavior is what you want. However, if a user explicitly
requests their font-family to be a font that contains a mix of test and
emoji, they _probably_ want those emoji to be used regardless of default
presentation. This is similar to a rich text editor (like TextEdit on
Mac): if you explicitly select "Cozette" as your font, the alien emoji
shows up using the text-based Cozette glyph.

This commit changes our presentation handling behavior to do the
following:

  * If no explicit variation selector (VS15/VS16) is specified,
    any matching codepoint in an explicitly loaded font (i.e. via
    `font-family`) will be used.

  * If an explicit variation selector is specified or our explicitly
    loaded fonts don't contain the codepoint, fallback fonts will be
    searched but require an exact match on presentation.

  * If no fallback is found with an exact match, any font with any
    presentation can match the codepoint.

This commit should generally not change the behavior of Emoji or VS15/16
handling for almost all users. The only users impacted by this commit
are specifically users who are using fonts with a mix of emoji and text.
2023-11-08 21:55:20 -08:00
Mitchell Hashimoto
4781a83e4a replace utf8proc with ziglyph 2023-11-07 13:17:56 -08:00
Mitchell Hashimoto
cb684e35cc font/coretext: discovery scoring should take into account symb. traits
Fixes #707

Our scoring algorithm previously did not take into account symbolic
traits, so when `bold = false and italic = false`, regular, bold, italic
would all be equally likely to appear first.

This modifies our scoring algorithm to prioritize matching symbolic
traits. Further, we have a special case for no symbolic traits to
prioritize "Regular" named styles. We can expand this to other styles
too but we do not do this here.

We also modified the algorithm to always prefer fonts with more glyphs
over fonts with less, hopeful that we can load fewer fonts for other
glyphs later.
2023-11-03 22:21:34 -07:00
Mitchell Hashimoto
2275768383 font: if a codepoint is emoji presentation, prefer that for shaping
Fixes #787
2023-11-02 21:46:50 -07:00
Matthew Winter
a81c7b7bb2 feat: improve variable naming 2023-11-01 19:04:20 +11:00
Matthew Winter
212b30a163 feat: change minimum height to 2 2023-11-01 11:51:32 +11:00
Matthew Winter
d7a16e0245 feat: update undercurl thickness and wave height 2023-10-31 21:53:04 +11:00
Matthew Winter
60b69a32d0 feat: update undercurl thickness and wave height 2023-10-31 21:23:53 +11:00
Mitchell Hashimoto
3a5f12b8ab font: box sprite use saturated subtraction
Fixes #757

The x/y is unsigned (as it should be, since top-left is 0,0). In the
case of a very small grid size and certain thickness settings, its
possible to overflow. In this scenario, the only reasonable thing to do
is just clamp to 0 because some sprites are going to look weird with
small enough grids anyways.
2023-10-30 09:01:14 -07:00
Matthew Winter
58f1653a16 feat: cleanup types and reduce casting 2023-10-29 14:17:46 +11:00
Mitchell Hashimoto
a249e5973d font/underline: some additional type annotations 2023-10-28 10:40:51 -07:00
Matthew Winter
6d971de87a feat: add x_facter comment and remove old code 2023-10-29 03:13:17 +11:00
Matthew Winter
a5eb746cf5 feat: update undercurl with antialiasing 2023-10-29 02:49:31 +11:00
Mitchell Hashimoto
7995d44cfb font: render sprites with a configurable grid cell width
Fixes #666
2023-10-13 14:31:55 -07:00
Mitchell Hashimoto
1411015038 font: fallback search should search full discovery chain
Fixes #668

We were previously only checking the first font result in the search.
This also fixes our CoreText scoring algorithm to prioritize faces that
have the codepoint we're searching for.
2023-10-13 12:25:27 -07:00
Mitchell Hashimoto
224b39b86e font/coretext: allow setting a non-monospace font explicitly
This changes our font discovery to not filter out monospace and updates
our scoring mechanism to prefer monospace.
2023-10-05 08:39:48 -07:00
Mitchell Hashimoto
7a0b8a6781 font: fix failing macos tests 2023-10-05 08:08:04 -07:00
Mitchell Hashimoto
b98cc3d79f config: add remaining font modifiers 2023-10-04 22:08:19 -07:00
Mitchell Hashimoto
16cfb14200 font: modify font compiles for freetype 2023-10-04 21:48:51 -07:00
Mitchell Hashimoto
2563a195a1 font: wire up all the metric modifiers 2023-10-04 21:42:03 -07:00
Mitchell Hashimoto
54b9b45a7f font: rework font init to use a struct with modifiersets everywhere 2023-10-04 17:23:57 -07:00
Mitchell Hashimoto
969960a10b font: Metrics ModifierSet 2023-10-04 15:56:32 -07:00
Mitchell Hashimoto
bac5e20962 font: Metrics.Modifier for applying a percentage/absolute change 2023-10-04 15:28:22 -07:00
Mitchell Hashimoto
15e6c07bd9 font/fontconfig: adhere to correct function signature 2023-10-03 09:26:14 -07:00
Mitchell Hashimoto
1127330b3a font/coretext: score discovered fonts 2023-10-03 09:17:41 -07:00
Mitchell Hashimoto
5c1fbd09cd font: shaper dynamically allocates cell buffer
Pathlogical grapheme clusters can use a LOT of memory, so we need to be
able to grow.
2023-09-26 17:59:16 -07:00
Mitchell Hashimoto
b1389cbbfe renderer: support font style changing at runtime 2023-09-26 08:51:04 -07:00
Mitchell Hashimoto
6b913bc6bb font: Group can enable/disable styles 2023-09-26 08:37:07 -07:00
Mitchell Hashimoto
6ac4cc9671 font: debug log for overide 2023-09-24 20:40:36 -07:00
Mitchell Hashimoto
abd3e16ebd font: Group will use the codepoint map for codepoint overrides 2023-09-24 19:44:06 -07:00
Mitchell Hashimoto
5c1c090f39 font: change FontIndex to a u16 since we can expect more fonts with maps 2023-09-24 15:53:39 -07:00
Mitchell Hashimoto
9e2e3acecf font: add codepoint map and descriptor cache to Group, not used yet 2023-09-24 11:50:03 -07:00
Mitchell Hashimoto
3915d9ee3a font: add CodepointMap with tests 2023-09-24 11:22:57 -07:00
Mitchell Hashimoto
6b640c2d9f font: discovery descriptor can be hashed 2023-09-24 11:17:07 -07:00
Mitchell Hashimoto
4e54c5389e font: CodepointMap 2023-09-24 11:10:20 -07:00
Mitchell Hashimoto
49dbd8d151 font/shaper: fix failing test on macos 2023-09-24 11:10:04 -07:00
Mitchell Hashimoto
16cecc082a font: fallback should not restrict to only monospace 2023-09-24 09:05:40 -07:00
Mitchell Hashimoto
8e083d8618 font/fontconfig: support style descriptor 2023-09-24 09:05:07 -07:00
Mitchell Hashimoto
966166015f font/core-text: discovery supports style search 2023-09-24 09:02:35 -07:00
Mitchell Hashimoto
70a2a0556d font: fontconfig should not omit earlier fonts 2023-09-24 08:42:12 -07:00
Mitchell Hashimoto
2fb14eee09 font: CoreText discovery searches monospace only by default 2023-09-24 08:22:50 -07:00
Mitchell Hashimoto
3c7ba634d2 font: remove excess debugging code 2023-09-13 14:41:43 -07:00
Mitchell Hashimoto
a2236d1ceb font: fallback search must verify presentation 2023-09-13 14:27:04 -07:00
Mitchell Hashimoto
3bd77259bf font: don't use intCast on index
This is a weird one. By using intCast on the `idx` I am periodically
getting a panic on index out of bounds where the index is larger than
FontIndex can possibly be. Very strange!

I tried to just remove intCasts and believe it or not that worked.
Previously, `cat /dev/urandom` would trigger the issue in seconds and
now I've had it running 20+ minutes without the issue.

The additional `if` check is just a safety mechanism
2023-08-31 21:16:56 -07:00