Skip to content

fix: hint glyphs only at whole pixel sizes the font asks for - #228

Merged
chenyme merged 2 commits into
devfrom
fix/hint-whole-pixel-sizes
Dec 5, 2026
Merged

chenyme merged 2 commits into
devfrom
fix/hint-whole-pixel-sizes

Conversation

@chenyme

@chenyme chenyme commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

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 gasp table. 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 their gasp table where grid fitting helps antialiased text:

  • Microsoft YaHei asks for it up to 21 pixels per em, where it sharpens strokes, and not above.
  • Consolas and Segoe UI ask for it at all text sizes, so they render as before.

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:

100%, 22–26 px 125%, 22.5–26.25 px
Before 186 207 224 317 320 stepped, up to +41%
After 203 227 244 266 288 216 230 240 256 266 281 293

At 12–21 px the font still asks for grid fitting, so hinted sizes are unchanged and as sharp as before.

Tests

  • The hinting test also checks that text between whole pixel sizes draws the same hinted or not.
  • A unit test reads gasp tables 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.

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 chenyme self-assigned this Dec 5, 2026
@chenyme
chenyme merged commit 3b6677a into dev Dec 5, 2026
14 checks passed
@chenyme
chenyme deleted the fix/hint-whole-pixel-sizes branch December 5, 2026 14:55
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant