Emit selectable Type0 text for TrueType-font widgets in AddWidgetVector - #3
Merged
Merged
Conversation
vectorPainter renders bitmap-font widget text as selectable PDF text via
the painter Text primitive, but a widget tree whose active toolkit font
is a TrueType/OpenType face (SetFont(NewTrueTypeFont(...))) had no way to
reach it — the run either rasterised or fell back to the wrong font at
the wrong size.
Implement the new painter.FacePainter seam on vectorPainter: TextFace
embeds the FACE's own sfnt bytes (so glyph shapes AND advances match the
on-screen layout) and emits the run as real Type0 text at the face's
pixel size, dropping to the baseline by the face ascent. Embedded faces
are memoised per tree so each is subset once; a face whose bytes do not
parse degrades to the plain-Text fallback font rather than vanishing.
An rsc.io/pdf round-trip proves a TrueType-font widget label ("Hi") is
now a Type0 / CIDFontType2 embedded face shown with Tj — with its glyph
codes present and the /ToUnicode CMap mapping them back to "Hi" (real
selectable text) — and that no image XObject is placed (not rasterised).
Bumps go-widgets/toolkit to v0.79.0 and go-widgets/painter to v0.2.0 for
the seam. 100% coverage retained.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Implements the new
painter.FacePainterseam onvectorPainter, so a widget tree whose active toolkit font is a TrueType/OpenType face (SetFont(NewTrueTypeFont(...))) now renders throughAddWidgetVectoras real, selectable Type0 PDF text — not a rasterised image or the wrong fallback font.TextFaceembeds the face's own sfnt bytes (glyph shapes and advances match the on-screen layout), sizes the run at the face's pixel size, and drops to the baseline by the face ascent.Textfallback font rather than vanishing.Previously only the built-in bitmap font produced selectable vector text; TrueType faces had no path to the text seam.
Proof (rsc.io/pdf round-trip)
TestAddWidgetVectorTrueTypeSelectablereparses the output with the independentrsc.io/pdfreader and asserts a TrueType-font widget label ("Hi") is:Tjoperator, its glyph codes<0001><0002>present,/ToUnicodeCMap maps those codes back to "Hi",Dooperator and no XObject resource on the page.On-screen rendering unchanged
The change is confined to the vector painter's new
TextFacemethod; the rasterAddWidget/PixelPainterpath is untouched, so on-screen output is pixel-identical.Deps / coverage
Bumps
go-widgets/toolkit-> v0.79.0 andgo-widgets/painter-> v0.2.0 for the seam. Statement coverage stays 100% (embed, cache hit, early-return and unparseable-face fallback all covered). Builds on all 6 64-bit arches + wasm/windows/darwin.🤖 Generated with Claude Code