Add registered font fallbacks and subsetting#30
Open
bobsingor wants to merge 3 commits into
Open
Conversation
Introduce runtime-registered font support and per-annotation font subsetting for FreeText appearance generation. Adds CPDF_AnnotFontMap and CPDF_AnnotFontSubset to route fallback lookups to CFX_FontRegistry, create marker font entries in the AcroForm DR, and produce subsetted Type0/CIDFont dictionaries (using HarfBuzz) that embed only glyphs used by an annotation/layer. Update CPDF_Font::FallbackFontFromCharcode to prefer registered fonts and create runtime fallbacks, and switch FreeText AP generation to use CPDF_AnnotFontMap so resources include any registered fallback/subset fonts actually used. Expose UpdateDefaultAppearanceRegisteredFont to set a DA referencing a registered runtime font. Update BUILD.gn to include the new files and third_party/harfbuzz-ng, and add supporting CFX_FontRegistry and public/epdf_font glue.
Persist registered-font identity in marker font dictionaries and make font registry behavior robust. - Store registered font id in marker font dict (key "EmbedPDFRegisteredFontId") and add CPDF_AnnotFontSubset::GetRegisteredFontIdFromMarkerFontDict to read it. CPDF_AnnotFontMap now checks the marker dict for identity instead of inferring from BaseFont/resource alias. - Create marker font dicts with the new id field; make subset base-name comment deterministic. - Prevent CFX_FontRegistry::ClearRegisteredFonts from resetting next_font_id to avoid reusing ids that may still be referenced by existing document markers. - Update CPVT_FontMap unicode/charcode logic to use CharCodeFromUnicode checks and safe numeric conversions; preserve upstream appearance font selection behavior. - Add/adjust tests and helpers in fpdfsdk to validate stable appearance streams, alias-suffix survival, fallback rendering, checksums, and related utilities. - Update public API docs for font registration to clarify thread/ownership rules and ClearRegisteredFonts semantics. Also includes small cleanup/refactors and added includes needed by new code and tests.
Prefer registered-font mapping when generating appearance streams for persistent form widgets: if the target is persistent and there are registered fallback fonts or the font dict indicates a registered subset, create a CPDF_AnnotFontMap with registered fallbacks and embed the corresponding Font resources. Refactor duplicated AP generation into a lambda to reduce code duplication and preserve the previous CPVT_FontMap path for non-registered cases. Add CFX_FontRegistry::HasFallbackFonts() and its declaration. Add tests and a DroidSansFallbackFull.ttf test font, plus helpers to register and assert registered fallback behaviour for FreeText, TextField, ComboBox, and ListBox Korean glyphs. Also include small test fixes (initializer_list include, wchar_t usage).
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.
Introduce runtime-registered font support and per-annotation font subsetting for FreeText appearance generation. Adds CPDF_AnnotFontMap and CPDF_AnnotFontSubset to route fallback lookups to CFX_FontRegistry, create marker font entries in the AcroForm DR, and produce subsetted Type0/CIDFont dictionaries (using HarfBuzz) that embed only glyphs used by an annotation/layer. Update CPDF_Font::FallbackFontFromCharcode to prefer registered fonts and create runtime fallbacks, and switch FreeText AP generation to use CPDF_AnnotFontMap so resources include any registered fallback/subset fonts actually used. Expose UpdateDefaultAppearanceRegisteredFont to set a DA referencing a registered runtime font. Update BUILD.gn to include the new files and third_party/harfbuzz-ng, and add supporting CFX_FontRegistry and public/epdf_font glue.