Skip to content

Add PDF subset tags to embedded subset fonts - #2554

Open
swmal wants to merge 5 commits into
develop9from
fix/subset-previx
Open

swmal wants to merge 5 commits into
develop9from
fix/subset-previx

Conversation

@swmal

@swmal swmal commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Add PDF subset tags to embedded subset fonts

Subsetted fonts were embedded in PDF files without the required six-letter prefix (ABCDEF+FontName) in /BaseFont and /FontName.

Changes

  • NameTable.ApplySubsetTag (new): prefixes the full name (nameID 4) and PostScript name (nameID 6) in all platform records. Family/subfamily records (nameID 1, 2, 16, 17) are untouched, as they are used for font identity. Idempotent.
  • SubsetTag.Create (new): deterministic tag (six uppercase letters + +) derived from font identity and code points.
  • OpenTypeFont.CreateSubset: new internal overload with addSubsetTag. The tag is applied to the new subset before PostProcessSubset, so lengths, checksums and cached table bytes reflect the final name table. Public signature unchanged.
  • SingleFontSubsetter.Subset: new overload with addSubsetTag.
  • DocumentFontSubsetBuilder.Build: subsets are now tagged. EmbedWhole fonts and the original cached fonts are never modified.

No changes to EPPlus.Export.Pdf: Type0, CIDFont and FontDescriptor all read FullName, so the three names are identical.

Verification

  • Unit tests for name table, tag generation, serialize roundtrip, builder identity/provider lookup, EmbedWhole, and last-resort fallback.
  • A PDF-level test verifying identical tagged names across the three font objects.
  • pdffonts on a sample export shows all four fonts as emb=yes sub=yes with distinct tags.

@swmal swmal added this to the EPPlus 9.0 or later milestone Sep 30, 2026
@swmal swmal self-assigned this Sep 30, 2026
@swmal swmal added the enhancement New feature or request label Sep 30, 2026

@AdrianEPPlus AdrianEPPlus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bra jobbat

return font.CreateSubset(chars);
return font.CreateSubset(chars, addSubsetTag);
}
catch (Exception ex)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ex is never used varning av github codescan

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants