Skip to content

book: x/image's opentype face kerns by the same pixels at every size - #742

Merged
closer-claudio merged 1 commit into
mainfrom
claudio/20261122-ximage-kern
Nov 23, 2026
Merged

closer-claudio merged 1 commit into
mainfrom
claudio/20261122-ximage-kern

Conversation

@closer-claudio

Copy link
Copy Markdown
Contributor

🎯 Why

golang.org/x/image's opentype.Face moves a kerned pair by the same number of pixels at every size: its Kern hands sfnt.Font.Kern the font's units per em where that function wants the face's pixels per em. Text measured or drawn through such a face is too tight at small sizes and too loose at large ones. The module is pinned and not forked, so the bug belongs in the book's known upstream bugs, with the workaround one repository carries and the condition under which it goes.

🛠️ What

🧪 How

  • V the line, read at the commit that is both the release go-graphviz pins and the head of the module's repository: (*Face).Kern passes fixed.Int26_6(f.f.UnitsPerEm()); every other call of the face passes its scale.
  • V the symptom, reproduced with a throwaway program on Arial at 72 dpi: Face.Kern('A','V') is -2.3750 px at 7, 14 and 140 points; sfnt.Font.Kern at the face's real pixels per em gives -0.5156, -1.0469 and -10.3906.
  • V consumers: across the organisations' repositories only go-graphviz imports font/opentype.
  • V upstream's tracker holds a report of it by others, closed, with the line unchanged since; the entry carries the link.
  • V just lint exit 0, just test exit 0, just do security links exit 0 (549 links, 437 ok, 112 excluded), just do lint commits exit 0.

📝 Notes

A known upstream bug in a module go-graphviz pins and nobody here has
forked. opentype's (*Face).Kern hands sfnt.Font.Kern the font's units per
em where it wants the face's pixels per em, so a pair's kern comes back
as the font's units read as 26.6 pixels, the same at every size.
Reproduced on Arial at 72 dpi: -2.375 px at 7, 14 and 140 points, where
sfnt.Font.Kern at the real pixels per em gives -0.52, -1.05 and -10.39.
The line is the same at the module's latest release, which is the head of
its repository.

go-graphviz, the one repository that imports the package, gives its face
a Kern of its own; the entry names it and says when it can go.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: closer-claudio <claudio@farcloser.world>
@closer-claudio closer-claudio added the internal Changes nothing for a consumer; left out of release notes label Nov 23, 2026
@closer-claudio

Copy link
Copy Markdown
Contributor Author

Reviewed at ec2cdde

@closer-claudio
closer-claudio merged commit 633fef2 into main Nov 23, 2026
14 checks passed
@closer-claudio
closer-claudio deleted the claudio/20261122-ximage-kern branch November 23, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Changes nothing for a consumer; left out of release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants