Commit Graph

858 Commits

Author SHA1 Message Date
Jacob Sandlund
44aa761733 skip testShaperWithDiscoveredFont if discovery is not available 2026-01-26 11:00:15 -05:00
Jacob Sandlund
57f3973040 fix Tai Tham test for FreeType 2026-01-26 10:46:40 -05:00
Jacob Sandlund
c2601dc7ec don't double deinit 2026-01-26 10:32:58 -05:00
Jacob Sandlund
17af9c13e2 Bengali text fix (likely grapheme break changes) 2026-01-26 10:22:17 -05:00
Jacob Sandlund
4f7fcd5956 Skip tests if font family doesn't match 2026-01-26 10:14:03 -05:00
Jacob Sandlund
3b75d25e6c fix typo 2026-01-23 08:48:16 -05:00
Jacob Sandlund
2c32e167fe Merge remote-tracking branch 'upstream/main' into harfbuzz-positions 2026-01-23 08:47:55 -05:00
Mitchell Hashimoto
01f1611c9f tripwire: change backing store from ArrayHashMap to EnumMap
This eliminates all allocation from Tripwire.
2026-01-21 15:30:49 -08:00
Mitchell Hashimoto
3fdff49a82 font: fix memory leak in SharedGrid.init on late failure
Add errdefer cleanup for codepoints and glyphs hash maps in init().
Previously, if ensureTotalCapacity or reloadMetrics() failed after
allocating these maps, they would leak.

Add tripwire test to verify all failure points in init().
2026-01-21 12:37:21 -08:00
Mitchell Hashimoto
b606b71cda font: fix missing errdefer rollback in SharedGrid.renderGlyph
Add errdefer to remove cache entry after getOrPut if subsequent
operations fail (getPresentation, atlas.grow, renderGlyph). Without
this, failed renders would leave uninitialized/garbage entries in
the glyph cache, potentially causing crashes or incorrect rendering.

Add tripwire test to verify the rollback behavior.
2026-01-21 12:23:28 -08:00
Mitchell Hashimoto
a83bd6a111 font: add tripwire tests to Atlas 2026-01-21 11:34:59 -08:00
Mitchell Hashimoto
112363c4e1 font: Collection.getEntry explicit error set 2026-01-20 11:57:22 -08:00
Mitchell Hashimoto
e875b453b7 font/shaper: hook functions can't fail 2026-01-20 11:51:01 -08:00
Mitchell Hashimoto
49b2b8d644 unicode: switch to uucode grapheme break to (mostly) match unicode spec (#9680)
This PR builds on https://github.com/ghostty-org/ghostty/pull/9678 ~so
the diff from there is included here (it's not possible to stack PRs
unless it's a PR against my own fork)--review that one first!~

This PR updates the `graphemeBreak` calculation to use `uucode`'s
`computeGraphemeBreakNoControl`, which has [tests in
uucode](215ff09730/src/x/grapheme.zig (L753))
that confirm it passes the `GraphemeBreakTest.txt` (minus some
exceptions).

Note that the `grapheme_break` (and `grapheme_break_no_control`)
property in `uucode` incorporates `emoji_modifier` and
`emoji_modifier_base`, diverging from UAX #29 but matching UTS #51. See
[this comment in
uucode](215ff09730/src/grapheme.zig (L420-L434))
for details.

The `grapheme_break_no_control` property and
`computeGraphemeBreakNoControl` both assume `control`, `cr`, and `lf`
have been filtered out, matching the current grapheme break logic in
Ghostty.

This PR keeps the `Precompute.data` logic mostly equivalent, since the
`uucode` `precomputedGraphemeBreak` lacks benchmarks in the `uucode`
repository (it was benchmarked in [the original PR adding `uucode` to
Ghostty](https://github.com/ghostty-org/ghostty/pull/8757)). Note
however, that due to `grapheme_break` being one bit larger than
`grapheme_boundary_class` and the new `BreakState` also being one bit
larger, the state jumps up by a factor of 8 (u10 -> u13), to 8KB.

## Benchmarks

~I benchmarked the old `main` version versus this PR for
`+grapheme-break` and surprisingly this PR is 2% faster (?). Looking at
the assembly though, I'm thinking something else might be causing that.
Once I get to the bottom of that I'll remove the below TODO and include
the benchmark results here.~

When seeing the speedup with `data.txt` and maybe a tiny speedup on
English wiki, I was surprised given the 1KB -> 8KB tables. Here's what
AI said when I asked it to inspect the assembly:
https://ampcode.com/threads/T-979b1743-19e7-47c9-8074-9778b4b2a61e, and
here's what it said when I asked it to predict the faster version:
https://ampcode.com/threads/T-3291dcd3-7a21-4d24-a192-7b3f6e18cd31

It looks like two loads got reordered and that put the load that
depended on stage1 -> stage2 -> stage3 second, "hiding memory latency".
So that makes the new one faster when looking up the `grapheme_break`
property. These gains go away with the Japanese and Arabic benchmarks,
which spend more time processing utf8, and may even have more grapheme
clusters too.

### with data.txt (200 MB ghostty-gen random utf8)

<img width="1822" height="464" alt="CleanShot 2025-11-26 at 08 42 03@2x"
src="https://github.com/user-attachments/assets/56d4ee98-21db-4eab-93ab-a0463a653883"
/>

### with English wiki dump

<img width="2012" height="506" alt="CleanShot 2025-11-26 at 08 43 15@2x"
src="https://github.com/user-attachments/assets/230fbfb7-272d-4a2a-93e7-7268962a9814"
/>

### with Japanese wiki dump

<img width="2008" height="518" alt="CleanShot 2025-11-26 at 08 43 49@2x"
src="https://github.com/user-attachments/assets/edb408c8-a604-4a8f-bd5b-80f19e3d65ee"
/>

### with Arabic wiki dump

<img width="2010" height="512" alt="CleanShot 2025-11-26 at 08 44 25@2x"
src="https://github.com/user-attachments/assets/81a29ac8-0586-4e82-8276-d7fa90c31c90"
/>


TODO:

* [x] Take a closer look at the assembly and understand why this PR (8
KB vs 1 KB table) is faster on my machine.
* [x] _(**edit**: checking this off because it seems unnecessary)_ If
this turns out to actually be unacceptably slower, one possibility is to
switch to `uucode`'s `precomputedGraphemeBreak` which uses a 1445 byte
table since it uses a dense table (indexed using multiplication instead
of bitCast, though, which did show up in the initial benchmarks from
https://github.com/ghostty-org/ghostty/pull/8757 a small amount.)

AI was used in some of the uucode changes in
https://github.com/ghostty-org/ghostty/pull/9678 (Amp--primarily for
tests), but everything was carefully vetted and much of it done by hand.
This PR was made without AI with the exception of consulting AI about
whether the "Prepend + ASCII" scenario is common (hopefully it's right
about that being uncommon).
2026-01-20 09:44:15 -08:00
Jacob Sandlund
c587d7a3a0 fix Bengali, Tai Tham letters, and Devanagari tests 2026-01-16 10:29:49 -05:00
Jacob Sandlund
80bf50be1d set cluster level to match CoreText logic 2026-01-16 09:39:47 -05:00
Jacob Sandlund
e48cf5a6e3 Merge remote-tracking branch 'upstream/main' into harfbuzz-positions 2026-01-16 09:05:04 -05:00
Jacob Sandlund
e7e83d6314 Update harfbuzz logic, debugging, and tests to match CoreText changes 2026-01-15 09:40:02 -05:00
Jacob Sandlund
3aba038d38 Merge remote-tracking branch 'upstream/main' into harfbuzz-positions 2026-01-14 08:56:56 -05:00
Jacob Sandlund
55583d9f27 fix Devanagari test 2026-01-13 10:36:20 -05:00
Jacob Sandlund
2a0a575065 comment fixup 2026-01-12 10:22:37 -05:00
Jacob Sandlund
9c6f40680c Merge remote-tracking branch 'upstream/main' into ligature-detect 2026-01-12 09:57:05 -05:00
Jacob Sandlund
f37b0c56ec Keep track of run's max cluster seen. 2026-01-12 09:56:31 -05:00
Jacob Sandlund
8ebb8470b7 Fix unsigned subtraction from zero 2026-01-07 10:46:01 -05:00
Jacob Sandlund
13e125a057 Add a big comment for the heuristic to detect ligatures. 2026-01-07 10:13:33 -05:00
Jacob Sandlund
48dd6314dc Use Python syntax for easier debugging 2026-01-07 09:57:16 -05:00
Britt Binler
896615c004 font: add bitmap font tests for BDF, PCF, and OTB formats
Add test coverage for bitmap font rendering using the Spleen 8x16 font
in three formats: BDF (Bitmap Distribution Format), PCF (Portable
Compiled Format), and OTB (OpenType Bitmap). Tests validate glyph
rendering against expected pixel patterns.

Addresses #8524.
2026-01-06 09:14:33 -08:00
Jacob Sandlund
f258265ef0 font/shaper: keep codepoints in same cell if detecting ligature 2026-01-06 10:30:13 -05:00
Jacob Sandlund
15899b70fb simplify run_offset_x comment 2026-01-05 10:35:22 -05:00
Jacob Sandlund
7aec7effea Add test for Tai Tham letter position.y difference 2026-01-05 10:12:05 -05:00
Jacob Sandlund
41f63384f5 Turn off debugging 2026-01-05 09:59:37 -05:00
Jacob Sandlund
d38558aee1 Show current cp with ▸ in list of cps 2026-01-05 09:34:17 -05:00
Jacob Sandlund
1d4a5d91e0 More debugging for position.y differences 2026-01-04 21:24:45 -05:00
Jacob Sandlund
0a648cddf8 shaping: Use position.y directly for CoreText 2025-12-30 17:36:45 -05:00
Jacob Sandlund
e1ad74c0b7 debug codepoints 2025-12-30 17:14:04 -05:00
Jacob Sandlund
2ff05c9ffb Merge remote-tracking branch 'origin/main' into harfbuzz-positions 2025-12-28 17:24:58 -06:00
Chris Marchesi
6d36193378 deps: update z2d to v0.10.0
Release notes at:
 https://github.com/vancluever/z2d/blob/v0.10.0/CHANGELOG.md

Mainly a maintenance update with regards to Ghostty use, with a couple
of minor changes required to some type references to match new API
semantics.
2025-12-28 12:30:36 -08:00
rezky_nightky
bf73f75304 chore: fixed some typo
Author: rezky_nightky <with dot rezky at gmail dot com>
Repository: ghostty
Branch: main
Signing: GPG (4B65AAC2)
HashAlgo: BLAKE3

[ Block Metadata ]
BlockHash: c37f4ee817412728a8058ba6087f5ca6aaff5a845560447d595d8055972d0eac
PrevHash: 3510917a780936278debe21786b7bae3a2162cb3857957314c3b8702e921b3d4
PatchHash: 5e5bb4ab35df304ea13c3d297c6d9a965156052c82bccf852b1f00b7bcaa7dd4

FilesChanged: 18
Lines: +92 / -92

Timestamp: 2025-12-25T17:27:08Z
Signature1: c1970dbb94600d1e24dfe8efcc00f001664db7b777902df9632a689b1d9d1498
Signature2: 30babb1e3ca07264931e067bfe36c676fb7988c2e06f8c54e0c9538fe7c7fc9a
2025-12-26 00:27:08 +07:00
Jacob Sandlund
e41dbe84fc shaping: Use position offsets for HarfBuzz 2025-12-24 16:23:16 -06:00
Jacob Sandlund
139a23a0a2 Pull out debugging into a separate function. 2025-12-17 09:57:32 -05:00
Jacob Sandlund
075ef6980b Fix comment typo 2025-12-12 09:27:45 -05:00
Jacob Sandlund
6addccdeeb Add shape Tai Tham vowels test 2025-12-11 10:48:28 -05:00
Jacob Sandlund
572c06f67d font/coretext: Use positions to fix x/y offsets 2025-12-10 09:47:42 -05:00
Jacob Sandlund
c49d50eb80 Merge remote-tracking branch 'upstream/main' into grapheme-break 2025-11-30 08:57:08 -05:00
Mitchell Hashimoto
dbfc3eb679 Remove unused imports 2025-11-27 13:37:53 -08:00
Jacob Sandlund
42bdd7f4de Merge remote-tracking branch 'upstream/main' into grapheme-break 2025-11-25 08:39:26 -05:00
Qwerasd
6d65abc489 fix(pkg/freetype): fully correct load flags
These now properly match the FreeType API- compared directly in the unit
tests against the values provided by the FreeType header itself.

This was ridiculously wrong before, like... wow.
2025-11-24 17:57:02 -07:00
Jacob Sandlund
97aff0743e unicode: switch to uucode grapheme break to match unicode 16 spec 2025-11-23 22:33:01 -05:00
Mitchell Hashimoto
2ecaf4a595 font/shaper: fix harfbuzz tests 2025-11-20 22:00:44 -08:00
Mitchell Hashimoto
3d56a3a02b font/shaper: remove old pre-renderstate logic 2025-11-20 22:00:44 -08:00