Skip to content

Subset font tags and escaped names (from #48), with CIDSet for PDF/A-1 - #50

Merged
dskripchenko merged 3 commits into
mainfrom
fix/font-subset-tag
Oct 27, 2026
Merged

dskripchenko merged 3 commits into
mainfrom
fix/font-subset-tag

Conversation

@dskripchenko

Copy link
Copy Markdown
Owner

This carries the commit of #48 by @serpentblade unchanged, authorship kept, and adds two follow-up commits from the review. Thank you — naming subsets as ISO 32000 asks, deterministically from their bytes, is the right fix, and the name escaping closes a gap we had in the CFF path as well.

The follow-up, and why it is needed:

  • /CIDSet for TrueType subsets. Once subsets carry the ABCDEF+ tag, veraPDF recognises them as subsets and applies ISO 19005-1 §6.3.5: a CIDFont subset must have a /CIDSet. The library wrote none, so pdfa-1b and pdfa-1a of the conformance set started failing rule 6.3.5-3 (they pass on main only because the subsets were untagged). CI did not run on the fork's pull request, so this could not show up there.
    The set marks every glyph below numGlyphs: our subsetter keeps glyph numbering and leaves unused glyphs empty, and veraPDF counts each of them as present. A narrower set (used glyphs, glyph 0, composite components) fails PDF/A-2 and 3 on rule 6.2.11.4.2-2, which requires the set to be complete. It is written for every TrueType subset — PdfFont does not know the conformance level, and PDF/A-2/3 accept a complete set; for Liberation Sans that is ~330 bytes before compression. Fonts embedded whole and CFF fonts get none.
  • CHANGELOG [Unreleased] → Fixed: subset tags (with the visible name change /BaseFont /LiberationSans → /ABCDEF+LiberationSans), escaped names, CIDSet.

Tests: the CIDSet stream exists, its length is ceil(numGlyphs/8) and every bit matches, on a text with a composite glyph (é); no CIDSet for whole fonts and CFF. Full suite 2608 OK (14 skipped), PHPStan clean, veraPDF 1.30 passes all nine PDF/A documents of the conformance set, including 1b and 1a.

Closes #48.

🤖 Generated with Claude Code

serpentblade and others added 3 commits October 22, 2026 10:05
An embedded TrueType subset was named after the whole font: /BaseFont
/Inter-Bold. ISO 32000-1 §9.6.4 requires a subset's name — both /BaseFont
entries and the descriptor's /FontName — to start with six uppercase
letters and a plus sign: /BaseFont /DCFUHW+Inter-Bold.

Without the tag, two subsets of one font in a document share a name. A
certificate set in Inter used it for bold and for bold italic, so it
carried two different Inter-Bold subsets under one name; a processor that
looks fonts up by name (Ghostscript, preflight, merging) can draw one
subset's text from the other and lose glyphs. Tools also took the subset
for the whole font: pdffonts listed it with sub "no".

The tag is taken from a hash of the subset's bytes, so different subsets
get different tags and the same subset always gets the same one — the
output stays reproducible. Fonts embedded whole (subset: false) and CFF
fonts, which are never subset, keep the plain name.

The PostScript name was also written into the PDF name unescaped. The
OpenType spec keeps delimiters, '#' and non-printable bytes out of it, but
a font that broke the rule produced a broken font dictionary; those
characters are written as #xx now (§7.3.5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the subset tag in /FontName, veraPDF treats the font as a subset and
PDF/A-1 requires a CIDSet for it (ISO 19005-1 §6.3.5, rule 6.3.5-3), so
pdfa-1b and pdfa-1a stopped validating.

The subsetter keeps the glyph numbering and leaves unused glyphs empty,
so every GID below numGlyphs is present in the font program, and the
CIDSet sets all of them. PDF/A-2 and 3 accept a CIDSet only when it lists
every glyph present (§6.2.11.4.2): one of only the used glyphs fails
veraPDF there. It is written for every subset, whatever the conformance
level: the font does not know it, and the stream is a few hundred bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dskripchenko
dskripchenko merged commit 8e6ca97 into main Oct 27, 2026
10 checks passed
@dskripchenko
dskripchenko deleted the fix/font-subset-tag branch October 27, 2026 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants