[PR #1216] [MERGED] Fonts: TrueType providers and the font picked by text components #3430

Closed
opened 2026-11-03 04:09:29 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1216
Author: @ludovic111
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @ludovic111

Base: main ← Head: feat/truetype-fonts


📝 Commits (10+)

  • 4e45a3b Credits and end poem (WinScreen)
  • 7e410d9 Fonts: TrueType providers and the font picked by text components
  • 3ce3fe0 Merge origin/main into feat/win-screen
  • 6bd80fe Merge feat/win-screen (now with main) into feat/truetype-fonts
  • 9f54087 Win screen: cover main's menu-blur match (Screen::Win)
  • 725962b Merge feat/win-screen into feat/truetype-fonts
  • 906d02f Merge origin/main into feat/win-screen
  • 181c91d Merge feat/win-screen (now with main) into feat/truetype-fonts
  • 3f58e51 Options test: Credits & Attribution follows Horizon's two buttons
  • 7eeb7eb Merge feat/win-screen (Options test fix) into feat/truetype-fonts

📊 Changes

21 files changed (+1786 additions, -246 deletions)

View changed files

📝 crates/horizon-client/src/component.rs (+23 -0)
📝 crates/horizon-client/src/font.rs (+819 -223)
📝 crates/horizon-client/src/game.rs (+28 -5)
📝 crates/horizon-client/src/game/agent.rs (+1 -0)
📝 crates/horizon-client/src/game/control.rs (+25 -0)
📝 crates/horizon-client/src/game/end.rs (+4 -1)
📝 crates/horizon-client/src/game/music.rs (+6 -2)
📝 crates/horizon-client/src/game/options.rs (+1 -0)
📝 crates/horizon-client/src/game/remote.rs (+4 -0)
📝 crates/horizon-client/src/game/screens.rs (+4 -0)
📝 crates/horizon-client/src/game/startup_menu.rs (+40 -0)
➕ crates/horizon-client/src/game/win.rs (+150 -0)
📝 crates/horizon-client/src/hud.rs (+99 -10)
📝 crates/horizon-client/src/hud.wgsl (+50 -1)
📝 crates/horizon-client/src/lib.rs (+1 -0)
📝 crates/horizon-client/src/options_ui.rs (+58 -3)
📝 crates/horizon-client/src/packs.rs (+1 -0)
📝 crates/horizon-client/src/save.rs (+4 -0)
📝 crates/horizon-client/src/scoreboard.rs (+1 -0)
📝 crates/horizon-client/src/text.rs (+15 -1)

...and 1 more files

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Stacked on #1215 (it uses that PR's obfuscated-glyph code). The base is feat/win-screen, so the diff shows only this change. Merge #1215 first.

What

  • Every font is loaded, not just font/default.json: minecraft:alt, minecraft:illageralt, minecraft:uniform, the include/* fonts and any font a pack adds. Each one is a FontSet with its providers in order (space, bitmap, unihex, ttf), their filters (uniform, jp) and packs' providers first, as FontManager builds them. A font id that doesn't exist draws every character as the missing glyph (FontManager.getFontSetRaw → missingFontSet).
  • TrueType providers (TrueTypeGlyphProvider): "type": "ttf" with file (under font/), size, oversample, shift and skip (a string or a list). CFF (OTTO) fonts are refused, as vanilla refuses non-TrueType ones. Glyphs are rasterized with ab_glyph, already a dependency, into the atlas's glyph region when first drawn. The pixels per em are round(size * oversample). Coverage is stored as rrrr texels with coverage below 0.1 cut (text_intensity). Bearings are divided by the oversampling (GlyphBitmap) and advances are whole oversampled pixels like hinted FreeType's.
  • The font a text component picks: text::Style gains the font id. It is parsed from JSON and SNBT text components (chat and tellraw among them), pack descriptions and scoreboard number formats, inherited by children and written back to JSON. Drawing, measuring and wrapping use the style's font, and obfuscated text picks its random glyph in it.
  • Bitmap sheets outside textures/font/ (another namespace or folder, as packs' own fonts often use) are read from the pack and copied into the glyph region when first drawn.

Why

Fixes #336. Found by the resource pack audit (docs/resource-packs.md): ttf providers were ignored, and every component drew in the default font whatever its font said.

How tested

Two test packs, the same files in both clients. f2b-fonts has a pack description mixing minecraft:alt, minecraft:illageralt, a Geist TrueType font (size 12, oversample 2, shift [0,-1]), Geist Mono (size 10, skip "O") and a font that doesn't exist. f2b-ttf-default puts a Geist ttf provider first in minecraft:default, so the whole UI draws in it.

Vanilla 26.3 (left, 854x480, GUI scale 2) against Horizon (right, --offscreen 1280x720, GUI scale 3, box-downscaled): the pack screen with f2b-fonts, then with both packs, then the title screen with both:
fonts

Text boxes measured on the frames, in GUI pixels:

text vanilla Horizon
"Geist as the default font (ttf)" x 266.5–398.0, y 78.0–86.5 x 266.3–398.0, y 78.0–86.7
"Geist 1.5x" (size 12, shift −1) x 320.0–385.0, y 111.5–124.0 x 320.0–385.0, y 111.3–124.0

The skipped O and the missing font draw the missing-glyph box in both. The remaining differences (the Default pack's icon, Realms greyed out, the branding) are already on main.

Unit tests:

  • font.rs: a TrueType font rasterized at its size, oversampling, shift and skip, with rrrr texels; styles picking their font, a missing font drawing missing glyphs, sheets outside the atlas copied in; provider filters following Force Unicode Font.
  • component.rs: font parsed, inherited, written back and re-read; invalid ids are dropped.

Font loading on the real resources takes 6.8 ms including decoding the sheets. The common glyph lookup (the default font) is the first entry, so per-glyph cost stays a short string compare plus the glyph cache.

Self-check (Mac mini, on top of #1215 rebased on origin/main c16b41ab):

cargo fmt --all --check                                   ok
cargo clippy --workspace --all-targets -- -D warnings     ok (exit 0, pipefail)
cargo test -p horizon-client                              1114 passed, 0 failed
tools/parity.py --changed origin/main (this stack: #1215 + this PR)
                                                          102 passed, 0 failed (world_spawn rerun alone after a
                                                          machine restart cut the run)
tools/parity.py on main: --changed selects nothing there

Not done here (one line in horizon-parity FEATURES.md, 4v)

  • World-space name tags (game/names.rs) still draw from the default font's 8x8 cells.
  • ab_glyph doesn't hint, so at small sizes a glyph's shape can be a pixel off from FreeType's hinted outline. Advances are rounded the same way, so text widths match.

Nothing needs Ludovic.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/1216 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/truetype-fonts` --- ### 📝 Commits (10+) - [`4e45a3b`](https://github.com/horizon-rust/horizon/commit/4e45a3bddfd2f0a3090d729ac95a02ab9d11a43e) Credits and end poem (WinScreen) - [`7e410d9`](https://github.com/horizon-rust/horizon/commit/7e410d93b3f38dd92b349c1608fb5eb5ad85479a) Fonts: TrueType providers and the font picked by text components - [`3ce3fe0`](https://github.com/horizon-rust/horizon/commit/3ce3fe03740f36c8ac689028ccc8dff16d1b2608) Merge origin/main into feat/win-screen - [`6bd80fe`](https://github.com/horizon-rust/horizon/commit/6bd80fe8178b1f0159d634ae8eef7e074fd04154) Merge feat/win-screen (now with main) into feat/truetype-fonts - [`9f54087`](https://github.com/horizon-rust/horizon/commit/9f54087a8694a4d9b620240a93b29bad14020ef4) Win screen: cover main's menu-blur match (Screen::Win) - [`725962b`](https://github.com/horizon-rust/horizon/commit/725962b8581e330a30bb1cf8c9bb42227f9261f8) Merge feat/win-screen into feat/truetype-fonts - [`906d02f`](https://github.com/horizon-rust/horizon/commit/906d02fff36f7c3cc4b317bcac0d84d774e8d2dd) Merge origin/main into feat/win-screen - [`181c91d`](https://github.com/horizon-rust/horizon/commit/181c91d1b84b67457b7fc23c622b25e5c3e58aea) Merge feat/win-screen (now with main) into feat/truetype-fonts - [`3f58e51`](https://github.com/horizon-rust/horizon/commit/3f58e512e091751e95046504842054768ac3f2d8) Options test: Credits & Attribution follows Horizon's two buttons - [`7eeb7eb`](https://github.com/horizon-rust/horizon/commit/7eeb7ebbc2c16738f0cf4eb51d76ab429b2c0a80) Merge feat/win-screen (Options test fix) into feat/truetype-fonts ### 📊 Changes **21 files changed** (+1786 additions, -246 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/component.rs` (+23 -0) 📝 `crates/horizon-client/src/font.rs` (+819 -223) 📝 `crates/horizon-client/src/game.rs` (+28 -5) 📝 `crates/horizon-client/src/game/agent.rs` (+1 -0) 📝 `crates/horizon-client/src/game/control.rs` (+25 -0) 📝 `crates/horizon-client/src/game/end.rs` (+4 -1) 📝 `crates/horizon-client/src/game/music.rs` (+6 -2) 📝 `crates/horizon-client/src/game/options.rs` (+1 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+4 -0) 📝 `crates/horizon-client/src/game/screens.rs` (+4 -0) 📝 `crates/horizon-client/src/game/startup_menu.rs` (+40 -0) ➕ `crates/horizon-client/src/game/win.rs` (+150 -0) 📝 `crates/horizon-client/src/hud.rs` (+99 -10) 📝 `crates/horizon-client/src/hud.wgsl` (+50 -1) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) 📝 `crates/horizon-client/src/options_ui.rs` (+58 -3) 📝 `crates/horizon-client/src/packs.rs` (+1 -0) 📝 `crates/horizon-client/src/save.rs` (+4 -0) 📝 `crates/horizon-client/src/scoreboard.rs` (+1 -0) 📝 `crates/horizon-client/src/text.rs` (+15 -1) _...and 1 more files_ </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **Stacked on #1215** (it uses that PR's obfuscated-glyph code). The base is `feat/win-screen`, so the diff shows only this change. Merge #1215 first. ## What - **Every font is loaded**, not just `font/default.json`: `minecraft:alt`, `minecraft:illageralt`, `minecraft:uniform`, the `include/*` fonts and any font a pack adds. Each one is a `FontSet` with its providers in order (`space`, `bitmap`, `unihex`, `ttf`), their `filter`s (`uniform`, `jp`) and packs' providers first, as `FontManager` builds them. A font id that doesn't exist draws every character as the missing glyph (`FontManager.getFontSetRaw` → `missingFontSet`). - **TrueType providers** (`TrueTypeGlyphProvider`): `"type": "ttf"` with `file` (under `font/`), `size`, `oversample`, `shift` and `skip` (a string or a list). CFF (`OTTO`) fonts are refused, as vanilla refuses non-TrueType ones. Glyphs are rasterized with ab_glyph, already a dependency, into the atlas's glyph region when first drawn. The pixels per em are `round(size * oversample)`. Coverage is stored as `rrrr` texels with coverage below 0.1 cut (`text_intensity`). Bearings are divided by the oversampling (`GlyphBitmap`) and advances are whole oversampled pixels like hinted FreeType's. - **The font a text component picks**: `text::Style` gains the font id. It is parsed from JSON and SNBT text components (chat and `tellraw` among them), pack descriptions and scoreboard number formats, inherited by children and written back to JSON. Drawing, measuring and wrapping use the style's font, and obfuscated text picks its random glyph in it. - Bitmap sheets outside `textures/font/` (another namespace or folder, as packs' own fonts often use) are read from the pack and copied into the glyph region when first drawn. ## Why Fixes #336. Found by the resource pack audit (docs/resource-packs.md): `ttf` providers were ignored, and every component drew in the default font whatever its `font` said. ## How tested Two test packs, the same files in both clients. `f2b-fonts` has a pack description mixing `minecraft:alt`, `minecraft:illageralt`, a Geist TrueType font (`size` 12, `oversample` 2, `shift` [0,-1]), Geist Mono (`size` 10, `skip` "O") and a font that doesn't exist. `f2b-ttf-default` puts a Geist `ttf` provider first in `minecraft:default`, so the whole UI draws in it. Vanilla 26.3 (left, 854x480, GUI scale 2) against Horizon (right, `--offscreen` 1280x720, GUI scale 3, box-downscaled): the pack screen with `f2b-fonts`, then with both packs, then the title screen with both: ![fonts](https://raw.githubusercontent.com/ludovic111/horizon/4b2b2085f436629de1bd75844453697a7e5dc9aa/336/cmp-fonts.png) Text boxes measured on the frames, in GUI pixels: | text | vanilla | Horizon | | --- | --- | --- | | "Geist as the default font (ttf)" | x 266.5–398.0, y 78.0–86.5 | x 266.3–398.0, y 78.0–86.7 | | "Geist 1.5x" (size 12, shift −1) | x 320.0–385.0, y 111.5–124.0 | x 320.0–385.0, y 111.3–124.0 | The skipped `O` and the missing font draw the missing-glyph box in both. The remaining differences (the Default pack's icon, Realms greyed out, the branding) are already on main. Unit tests: - font.rs: a TrueType font rasterized at its size, oversampling, shift and skip, with `rrrr` texels; styles picking their font, a missing font drawing missing glyphs, sheets outside the atlas copied in; provider filters following Force Unicode Font. - component.rs: `font` parsed, inherited, written back and re-read; invalid ids are dropped. Font loading on the real resources takes 6.8 ms including decoding the sheets. The common glyph lookup (the default font) is the first entry, so per-glyph cost stays a short string compare plus the glyph cache. Self-check (Mac mini, on top of #1215 rebased on origin/main c16b41ab): ``` cargo fmt --all --check ok cargo clippy --workspace --all-targets -- -D warnings ok (exit 0, pipefail) cargo test -p horizon-client 1114 passed, 0 failed tools/parity.py --changed origin/main (this stack: #1215 + this PR) 102 passed, 0 failed (world_spawn rerun alone after a machine restart cut the run) tools/parity.py on main: --changed selects nothing there ``` ## Not done here (one line in horizon-parity FEATURES.md, 4v) - World-space name tags (game/names.rs) still draw from the default font's 8x8 cells. - ab_glyph doesn't hint, so at small sizes a glyph's shape can be a pixel off from FreeType's hinted outline. Advances are rounded the same way, so text widths match. Nothing needs Ludovic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:09:29 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#3430
No description provided.