Adopt go-opentype v0.5.0 subsetting + descriptor primitives (real CFF subsetting) - #1
Merged
Merged
Conversation
Delete pdfkit's private sfnt re-parse (sfnt.go) and TrueType glyf subsetter (subset.go); embedding now uses go-opentype v0.5.0 throughout: - FontDescriptor scalars (FontBBox, Ascent/Descent, CapHeight, ItalicAngle, Flags, StemV, UnitsPerEm) come straight from the new Font accessors, with the documented cap-height -> ascender fallback. - TrueType path embeds Font.SubsetTrueType output (a compact renumbered subset) and builds a /CIDToGIDMap stream from the returned old->new remap (CID = original glyph id -> subset glyph id). - CFF path now truly subsets charstrings via Font.SubsetCFF instead of embedding the whole 'CFF ' table (glyph numbering preserved, Identity CIDToGIDMap stays valid). A CID-keyed CFF or a CFF2 font, which the preserve-numbering subsetter rejects, falls back to embedding the whole 'CFF '/'CFF2' table; a TrueType subset failure falls back to the whole font program. - /W widths now come from Face.AdvanceIndexUnits. Oracle tests re-open the generated PDF with rsc.io/pdf and prove the CFF subset is smaller than the whole table and re-parses with every kept glyph contour-intact; the TrueType subset is resolved through the embedded /CIDToGIDMap and each drawn glyph checked contour-intact. Exact 100% statement coverage; go vet clean; builds on 6 64-bit arches + wasm. 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.
Summary
Refactors font embedding onto go-opentype v0.5.0, deleting pdfkit's private sfnt re-parse and glyf subsetter and gaining real CFF charstring subsetting (previously the whole
CFFtable was embedded).Deleted:
sfnt.go,subset.go(and their tests). All sfnt parsing, subsetting and descriptor metrics now come from go-opentype.What now uses which upstream primitive
FontBBox,Ascent/Descent,CapHeight(with the documented cap-height→ascender fallback),ItalicAngle,Flags,StemV,UnitsPerEmread directly from*opentype.Font.Font.SubsetTrueTypeoutput (compact renumbered subset) and builds a/CIDToGIDMapstream from the returned old→new remap (CID = original glyph id → subset glyph id). Content-stream glyph ids and/Wstay keyed by the original id (the CID), which the map resolves.Font.SubsetCFF(glyph numbering preserved → Identity/CIDToGIDMapstays valid)./Wwidths — fromFace.AdvanceIndexUnits.CFF is now truly subsetted (proof)
For
"Hello"from Source Serif 4: wholeCFF= 115354 bytes, embedded subset = 45512 bytes (39.5%). The oracle test re-opens the PDF withrsc.io/pdf, asserts the embedded program is smaller than the whole table, wraps it back into an OTF, re-parses with go-opentype and checks every kept glyph renders contour-identically. The TrueType oracle resolves each drawn glyph through the embedded/CIDToGIDMapand checks it contour-intact.Graceful fallback
A CID-keyed CFF or CFF2 (variable) font (which the preserve-numbering subsetter rejects) falls back to embedding the whole
CFF/CFF2table; a TrueType subset failure falls back to the whole font program. Both fallbacks are covered by tests (a synthesised CFF2 font and an out-of-range-glyph trigger).Gate
GOWORK=off CGO_ENABLED=0, pure-Go, go 1.26.4go vetclean; builds on 6 64-bit arches (amd64/arm64/riscv64/loong64/ppc64le/s390x) + wasm (+ darwin/windows)🤖 Generated with Claude Code