PDFBOX-6197: TTFSubsetter: add support for custom cmap subtables via addCustomCmapEntry() / addCustomCmap()#446
Open
sz5000 wants to merge 1 commit intoapache:trunkfrom
Open
Conversation
two new public method added, addCustomCmapEntry and addCustomCmap TTFSubsetter currently only writes a single Windows Unicode BMP cmap subtable (platform 3, encoding 1) and only when addAll() has been called. There is no way for callers to inject additional cmap subtables — for example a Mac Roman subtable (platform 1, encoding 0) or a Windows Symbol subtable (platform 3, encoding 0). This limitation makes it impossible to correctly re-subset TrueType fonts that were originally subsetted by Ghostscript using its TT_BIAS=0xF000 strategy, where the font's Mac Roman cmap is the primary rendering cmap used by viewers.
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
Extends
TTFSubsetterwith two new public methods that allow callers to inject custom cmapsubtables into the subset TTF. This enables correct re-subsetting of TrueType fonts that use
non-Unicode cmap encodings — in particular fonts produced by Ghostscript with
TT_BIAS=0xF000,where the Mac Roman cmap (platform 1, encoding 0) is the primary rendering cmap used by viewers.
Fixes PDFBOX-XXXXX.
Changes
TTFSubsetter.javacustomCmapEntries— accumulates entries added via the new APIbuildCmapTable()extended:uniToGIDis empty (i.e. when onlyaddGlyphIds()was used)(platformId, platformEncodingId)pairgetNewGlyphId()mechanismbuildFormat4Subtable()andbuildFormat4SubtableNewGids()extractedfrom the previous monolithic
buildCmapTable()implementationaddCustomCmapEntry(platformId, platformEncodingId, charCode, gid)addCustomCmap(platformId, platformEncodingId, Map<Integer,Integer> codeToGid)addGlyphIds()(previously undocumented)Backwards Compatibility
Fully backwards-compatible. Callers that do not use the new API get identical behaviour to
the previous implementation.
Testing
Verified against PDFs produced by Ghostscript 10.x containing Thai and other non-Latin scripts
subsetted with
TT_BIAS=0xF000. Before this change, re-subsetting such fonts produced a TTFwith a broken or missing Mac Roman cmap, causing viewers to render blank glyphs. After this
change, both the Mac Roman and Windows Symbol subtables are correctly preserved in the subset,
and glyph rendering is identical to the original.