Repository navigation
fix: hint glyphs only at whole pixel sizes the font asks for - #228
Merged
Merged
Conversation
Fonts' instructions run at a whole number of pixels per em. Between two, at scales such as 125% and 175%, they snapped stems as for one of them, and the weight of Chinese text jumped by up to 40% from one size to the next. Fonts also tell in their gasp table where snapping helps antialiased text: Microsoft YaHei asks for it up to 21 pixels per em, where it sharpens strokes, and not above, where it thickened 1.5 pixel stems to 2. Glyphs are now hinted only at whole pixel sizes the font asks for, and fonts without the table as before. Measuring ink, for squeezing characters into cells and for formula layout, now hints as drawing does, also where the desktop turns hinting off.
chenyme
added a commit
that referenced
this pull request
Dec 5, 2026
* fix: hint glyphs only at whole pixel sizes the font asks for Fonts' instructions run at a whole number of pixels per em. Between two, at scales such as 125% and 175%, they snapped stems as for one of them, and the weight of Chinese text jumped by up to 40% from one size to the next. Fonts also tell in their gasp table where snapping helps antialiased text: Microsoft YaHei asks for it up to 21 pixels per em, where it sharpens strokes, and not above, where it thickened 1.5 pixel stems to 2. Glyphs are now hinted only at whole pixel sizes the font asks for, and fonts without the table as before. Measuring ink, for squeezing characters into cells and for formula layout, now hints as drawing does, also where the desktop turns hinting off. * docs: number the changelog entry
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.
Closes #110, closes #227
On Windows and Linux, Chinese text changed weight by up to 40% from one size to the next, at scales such as 125% and 175% and in large text. Glyphs are now hinted only at whole pixel sizes where the font asks for it.
Why
Whole pixel sizes. Fonts' TrueType instructions run at a whole number of pixels per em. At 24.5 px they snapped stems as for 24 or 25, so a stroke that should be 1.4 px drew as one or two rows. Hinting only at whole pixel sizes follows @HaujetZhao's proposal in #227. FreeType hints TrueType only at whole sizes too, but it rounds the size to get there; here glyphs keep their size, so they still match their advances.
The font's
gasptable. Whole sizes alone left jumps at 100%: in Microsoft YaHei, 重 grew by 41% from 24 to 25 px, because snapping 1.5 px stems to whole pixels thickens some to 2. Fonts tell in theirgasptable where grid fitting helps antialiased text:Version 1 tables are read by their ClearType grid-fitting bit, as on Windows; version 0 tables by the older one. Fonts without the table are hinted as before.
Measuring. Measuring ink, for squeezing characters into cells and for formula layout, now hints as drawing does, also where the desktop turns hinting off.
Measured on Windows
Ink of 重 in Microsoft YaHei; 0 is paper, 1 a full pixel:
At 12–21 px the font still asks for grid fitting, so hinted sizes are unchanged and as sharp as before.
Tests
gasptables of both versions, a missing one and a short one.fmt, clippy for every target, docs, and the workspace tests pass on macOS, Linux and Windows. macOS does not hint, so it is unchanged.