Skip to content

fix(apple): match framesetter heights for fonts with leading - #340

Merged
houko merged 1 commit into
mainfrom
fix/apple-fallback-line-metrics
Nov 17, 2026
Merged

houko merged 1 commit into
mainfrom
fix/apple-fallback-line-metrics

Conversation

@houko

@houko houko commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Apple's single-line shortcut measured a line with CTLineGetTypographicBounds, which counts a font's whole typographic leading in the height. A framesetter leaves that leading out of a frame's last line. Native CI first saw this as Menlo's Japanese fallback measuring 24 points against the framesetter's 18. Main has since moved every non-ASCII text off the shortcut (isASCIILine). ASCII texts in fonts that have leading still differ: at 12 points, "abc" in Hiragino Sans GB measures 19 points as a line and 13 in a frame, and Heiti SC, Thonburi and Devanagari Sangam MN each measure a point taller.

A text whose shaped line has nonzero typographic leading now uses the framesetter for both measuring and drawing. Lines without leading, such as the system font's, keep the shortcut and its rounding to whole points (framedHeight). docs/architecture/text.md now says that only ASCII texts take the shortcut and that texts in fonts with leading do not. The shared backend change applies to macOS and Apple's mobile targets.

The regression TestOneLineWithLeadingMatchesTheFramesetter compares measured sizes, rendered pixels, line information and carets between the shortcut and the framesetter. It covers four fonts, ASCII text and three other scripts, each with and without a line limit.

Validation:

  • On current main without the fix, the new regression fails: all four fonts measure ASCII text too tall and draw different pixels.
  • go tool nsgo test ./internal/platform/apple on macOS arm64: 78 passed, 0 failed, 2 skipped.
  • go tool nsgo check -target all passed.
  • go build ./... passed for the host, windows, linux, android/arm64 and js/wasm. go vet passed for darwin and ios on internal/platform/apple.
  • go tool nsgo test -run 'Layer|Skills|Doc' .: 35 passed.
  • Still to check: no iPhone check has been done. The iOS path shares this CoreText code, and its vet passed.

CTLineGetTypographicBounds counts a font's whole typographic leading in a line's height, where a framesetter leaves it out of a frame's last line: an ASCII text in Hiragino Sans GB at 12 points measured 19 points on the one-line shortcut and 13 through the framesetter, and Heiti, Thonburi and Devanagari Sangam MN were a point too tall. A line with nonzero leading now stays on the framesetter for measuring and drawing; lines without leading keep the shortcut. The regression compares sizes, pixels, lines and carets for those four fonts, ASCII and other scripts, with and without a line limit.
@houko
houko force-pushed the fix/apple-fallback-line-metrics branch from dfa29b0 to 1f5f15d Compare November 17, 2026 04:02
@houko

houko commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. Rebased onto current main (now 1f5f15d, a clean rebase: the commits main gained touch only video.go in this package) and checked the following.

  • Diff: fitsOneLine drops a text to the framesetter when its shaped line has nonzero typographic leading and releases the line; lines without leading keep the shortcut with main's whole-point rounding, so dropping the + leading term is exact. layout and Measure both go through fitsOneLine, so measuring and drawing stay consistent. No CHANGELOG change, no hard-wrapped lines, nothing unrelated.
  • Regression is real: with main's text.go and the PR's test, TestOneLineWithLeadingMatchesTheFramesetter fails for all four fonts (e.g. Hiragino Sans GB "abc" and "Hello world " at 12 pt measure 19 pt against the framesetter's 13, and pixels differ). With the fix it passes.
  • The optimisation is kept where it matters: a probe on macOS arm64 showed the system font (13 regular, 17 semibold, 11 italic), Menlo and Helvetica still take the one-line path, while Times New Roman and Hiragino Sans GB (fonts with leading) now use the framesetter.
  • macOS arm64 build host: go tool nsgo test ./internal/platform/apple 78 passed, 0 failed, 2 skipped, before and after the rebase; go vet for darwin and ios/arm64 (cgo) passed.
  • Real macOS target (a second Mac, macOS 27.2, GUI session): the four one-line text regressions, which render through CoreText and compare sizes, pixels, line info and carets against the framesetter, all pass.
  • Linux build host: go build ./... for the host, windows, linux, android/arm64 and js/wasm passed; go tool nsgo test -run 'Layer|Skills|Doc' . 35 passed.
  • Not device-checked: iOS. The iPhone is currently unavailable; iOS shares this CoreText code path, which is verified on macOS, and its vet passes.

@houko
houko marked this pull request as ready for review November 17, 2026 04:02
@houko
houko merged commit aa17c0d into main Nov 17, 2026
9 checks passed
@houko
houko deleted the fix/apple-fallback-line-metrics branch November 17, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation iOS macOS size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant