Add decoded glyph outline access - #122
Open
jplot wants to merge 2 commits into
Open
Conversation
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.
TTFunk parses everything around glyph outlines — headers, bounding boxes, component ids for subsetting — but stops one byte short of the outlines themselves:
Simplekeeps flags and coordinates undecoded inraw, andCompound's documentedComponentstruct is never instantiated. (History note: full decomposition existed for one night in December 2008 and was removed in e80ad0e in favor of parsing "just enough to write it back out in a font subset" — the struct declaration stayed behind.)This PR completes that surface:
Glyf::Simple#contours— decoded outline points (coordinates and on-curve flags), lazily and memoized, so the subsetting path pays nothing.Glyf::Compound#components— fully parsed component records into the existingComponentstruct: signed x/y offsets vs unsigned point numbers perARGS_ARE_XY_VALUES(a flag the codebase had not defined), and F2Dot14 transforms in all three forms.Glyf#contours_for(glyph_id)— composite-resolved, positioned contours. Component nesting is capped to protect against reference cycles, and point-matching alignment raisesTTFunk::Errorrather than producing silently wrong geometry.Additive only — no existing API changes, no new dependencies, and the raw-copy subsetting strategy is untouched (decoding is read-only and on demand).
Motivation: we used this decoding in production to recover text from PDFs whose subsetted fonts had lost their ToUnicode tables, by matching glyph shapes against reference fonts. Outline access also enables subset verification and glyph-level comparison generally.
Tests: 17 new examples against the DejaVuSans fixture (including exact bounding-box span of decoded points and point-by-point verification of composite translation) plus hand-built binary records for the F2Dot14 scale and unsigned point-number paths. Full suite green (207 examples), RuboCop clean.