Skip to content

feat(pdf): embed Unicode font and image objects in signed XObjects - #35

Merged
vitormattos merged 5 commits into
mainfrom
feat/issue33-signerphp-resource-bridge
Nov 24, 2026
Merged

vitormattos merged 5 commits into
mainfrom
feat/issue33-signerphp-resource-bridge

Conversation

@vitormattos

@vitormattos vitormattos commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Context

Follow-up to merged #34 for #33. The standalone PDF preview already writes Type 0 fonts, but the signed-PDF resource contract needs document-owned indirect objects. Depends on SignerPHP/pdf-core#5 (optional appearance resource builder); do not merge until that foundation is released and the consumer uses it.

Change

  • Reuse the existing UnicodeFontPdfWriter with callbacks allocated by the target SignerPHP\\PdfCore\\PdfDocument.
  • New SignerPhpCoreXObjectResourceBuilder::resourcesBuilder() materializes Type0/CIDFontType2, embedded FontFile2, CIDToGIDMap, ToUnicode and actual PDFValueReference objects instead of internal __TrueTypeFont arrays.
  • Preserve legacy Type1/other resource aliases and handle PNG alpha soft masks and SVG XObjects.
  • Validate resource dictionary keys, source image paths and generated references; reject null internal resource placeholders. Restore the original object table and allocator if materialization fails partway through.
  • Preserve already encoded image stream bytes (including PNG alpha masks) without applying the declared filter twice.
  • Only add an optional development dependency on signerphp/pdf-core:^0.1.2; consumers supply the compatible core package.
  • No README changes or font files added.

Validation (local, Poland)

Remaining scope of #33

This PR does not implement Arabic/Hebrew bidi/OpenType shaping, font subsetting or final signed-PDF compatibility across released versions. Do not close #33 with this PR.

Refs #33; depends on SignerPHP/pdf-core#5.

Share the Unicode font object serialization with destination-owned PDF
object allocators. Materialize Type0 fonts, ToUnicode, CIDToGIDMap, PNG
soft masks and SVG XObjects for signed appearance dictionaries.

Refs: #33

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Exercise PDF object references, glyph/ToUnicode maps, transparent PNG
soft masks, SVG XObjects, invalid resources, multi-resource scenarios,
and strict reference validation with data providers.

Refs: #33

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Avoid recompressing PNG image and soft-mask streams when materializing
resources in a SignerPHP document. Verify decoded pixel bytes and stream
lengths for transparent, grayscale and RGB PNGs.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Cast stream bytes explicitly for strlen() in PNG resource regression tests.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Restore the destination document object table and allocator on failure.
Reject null internal font and image placeholders instead of emitting them.
Cover failure after a valid font and successful retry on the same document.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@vitormattos
vitormattos marked this pull request as ready for review November 24, 2026 02:37
@vitormattos
vitormattos merged commit 07bd2cd into main Nov 24, 2026
24 checks passed
@vitormattos
vitormattos deleted the feat/issue33-signerphp-resource-bridge branch November 24, 2026 02:37
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.

Support Unicode text in PDF XObject output

1 participant