Repository navigation
fix(apple): apply weight and slant to every family of a font list - #319
Merged
Merged
Conversation
houko
force-pushed
the
fix/apple-font-fallback
branch
from
November 16, 2026 01:16
9eb6eac to
4268f8e
Compare
houko
force-pushed
the
fix/apple-font-fallback
branch
from
November 16, 2026 01:27
4268f8e to
aa31df6
Compare
buildFace styled only the first family of a FontFamily list: the cascade list kept the regular faces listedFont made, so a bold or italic text set the characters the first family lacks in the later family's regular face. Each cascade entry now takes the same traits, by family name for a named family and on its own descriptor for the system's UI fonts, and a list that starts with the system font restyles its cascade too.
On macOS and iOS a line takes its height and baseline from the faces its runs use, so a line set wholly in a later family of a list takes that family's metrics, where CSS keeps the first family's as a strut. Say so in the text docs and record the strut as a roadmap item.
houko
force-pushed
the
fix/apple-font-fallback
branch
from
November 16, 2026 01:31
aa31df6 to
1df3e57
Compare
Collaborator
Author
|
Reviewed.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #305.
What changes
buildFacenow styles every family of aFontFamilylist, not only the first. The cascade listlistedFontbuilds names the regular faces of the later families, so a bold or italic text set the characters the first family lacks in the regular face ("Menlo, Hiragino Sans"at 700 set Chinese in HiraginoSans-W3). Each cascade entry is now rebuilt from its family name plus the same traits dictionary the first family gets; entries for the system's UI fonts take the traits onto their own descriptor, asbuildFacedoes for a first family.system-ui, Hiragino Sans) restyles its cascade too. Before, the system-font branch copied the descriptor with only the traits, keeping the regular cascade.docs/public/en/text.md(andzh) say so, as the issue's acceptance allows,docs/architecture/text.mdrecords it, and the roadmap gains a "Font struts on Apple" item for the CSS strut.Why the strut was dropped from this PR
The first version of this PR fixed every line of a font list to the first family's height (paragraph minimum and maximum line height) and moved baselines after layout. Probing it showed:
placed()applied top-down, so glyphs were drawn on the opposite side of whereTextLines, carets and hit tests put them (a 6–8 pt mismatch for a fallback line withMaxLinesor aLineHeight).Menlo, Zapfinomeasured 47 pt against 94 pt alone, and the docs' ownInter, "Noto Sans SC"example would set Chinese lines on Inter's height. CSS's strut is a floor, not a fixed height.Menlo, Hiragino Sansmeasured 57 pt against 48 and 51).Ωin Instrument Serif falling back to Helvetica) was untouched, and it turned off the one-line fast path for every font list.A correct strut needs the backend to stack lines itself (size, drawing, carets, hit tests and truncation from one set of per-line metrics,
max(line, first family)), which also overlaps the framesetter-height work in #340. That is recorded as a roadmap item instead.Verification
TestListsFallBackInTheStyledFacelays out text with characters the first family lacks and checks the run's face is the later family's at the weight and slant asked for (Menlo, Hiragino Sansandsystem-ui, Hiragino Sansat 700,Didot, Times New Romanitalic). Both bold cases andTestStyledFacesOfFallbackFamiliesfail with the cascade left unstyled; the italic case already passed on main, where CoreText matched Times New Roman's italic face for the fallback, and stays as a guard.go build ./...,go tool nsgo check -target all,go tool nsgo test ./internal/platform/apple,go tool nsgo test -run 'Layer|Skills|Doc' .nsgo test -target macos, a throwaway probe app with the lists above, before and after this change): on main the Chinese inMenlo, Hiragino Sansandsystem-ui, Hiragino Sansat 700 is regular beside bold Latin; with this change it is bold. The italic Cyrillic inDidot, Times New Romanis italic both before and after.