Skip to content

Commit fab901b

Browse files
matmenclaude
andcommitted
Hinting: FreeType's integer arithmetic
Vectors are 2.14 integers normalized like FT_Vector_NormLen, projections use TT_DotFix14, moves the 16.16 move vector of Compute_Funcs with FT_MulFix (touching only where points move), twilight points TT_MulFix14. Also like FreeType: SLOOP 0, IP on unscaled values (and the original distance when the range is empty), composites measuring their hinted components at scale 1 with unrounded phantoms when they have no instructions, DELTA counts clamped to the stack, exact FT_DivFix. 18 fonts at 8-48 px and all glyphs of DejaVu Sans now match FreeType v35 point for point; the font test targets change accordingly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lfv41PqHEGbU7SLg5onpG1
1 parent a7c9e84 commit fab901b

7 files changed

Lines changed: 148 additions & 70 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
- `Image.renderSVG()`: `overflow="inherit"` on markers and nested viewports takes the parent's value.
5454
- `Image.renderSVG()`: path data ends at the first character that isn't part of it, instead of skipping it.
5555
- `Image.renderSVG()`: line ends (CR LF, CR) read as line feeds, like XML parsers read them.
56+
- Hinting (`renderText` with `hinting`) places points exactly like FreeType's TrueType interpreter (version 35): vectors,
57+
projections and moves in its integer arithmetic (2.14 unit vectors normalized like FT_Vector_NormLen, its rounding of
58+
products and movement factors, points touched only where they move), `SLOOP` with 0, `IP` on the unscaled outline,
59+
composite glyphs' instructions measuring the hinted components at a scale of 1 and their origins left unrounded
60+
without instructions, and `DELTAP`/`DELTAC` asking for more pairs than the stack holds. Over 18 fonts (DejaVu,
61+
Carlito, Noto, Source Sans, Amiri, M+, Open Sans...) at 8-48 pixels, and all 6190 glyphs of DejaVu Sans at 4 sizes,
62+
every point is where FreeType puts it; before, up to 30% of the glyphs of some fonts were off by fractions of a
63+
pixel, a few (DejaVu Sans Mono) by up to 4 pixels.
5664

5765
## 3.8.1
5866

‎src/render/hinting.ts‎

Lines changed: 140 additions & 70 deletions
Large diffs are not rendered by default.

‎tests/targets/emoji-colr.png‎

-2.16 KB
Loading

‎tests/targets/font-1.png‎

0 Bytes
Loading

‎tests/targets/font-2.png‎

16 Bytes
Loading

‎tests/targets/font-3.png‎

0 Bytes
Loading

‎tests/targets/font-4.png‎

0 Bytes
Loading

0 commit comments

Comments
 (0)