Skip to content

Revise image and font handling#103

Merged
ralfstx merged 5 commits intomainfrom
image-font
Feb 15, 2026
Merged

Revise image and font handling#103
ralfstx merged 5 commits intomainfrom
image-font

Conversation

@ralfstx
Copy link
Member

@ralfstx ralfstx commented Feb 15, 2026

No description provided.

ralfstx and others added 5 commits February 15, 2026 14:23
When no `info` object was provided to `renderDocument`, the
`setMetadata` function was skipped entirely, resulting in PDFs without
`CreationDate` or `ModDate` metadata.

Remove the `if (info !== undefined)` guard so that dates are always set.
Use optional chaining for all other info fields, which safely passes
`undefined` when info is absent. Add a test to verify dates are present
even without explicit info.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The deprecated `images` property in `DocumentDefinition` allowed to
register images by name. This is no longer needed since images can be
referred to by URL.

This commit replaces the unnecessarily complex `ImageStore` class with
a simpler `ImageLoader` that is created per `makePdf` call. Images with
the same URL are loaded only once within a document.

The `setResourceRoot` method is preserved for `file:/` URL support.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The `Image` type was a wrapper around `PDFImage` with redundant `width`
and `height` fields (already on `PDFImage`) and unused `url` and
`format` fields that were set but never read.

Remove `images.ts` entirely and use `PDFImage` directly in all places.
Make `ImageFormat` a file-local type in `image-loader.ts`. Simplify
`fakeImage` test helper to return `PDFImage` directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
`FontStore` parsed each font twice: once in `registerFont()` to extract
metadata, and again in `_loadFont()` when actually selecting a font.
Additionally, a stale TODO comment remained from the pdf-core migration,
and the deprecated `fonts` property in the document definition was still
supported.

Store the `PDFEmbeddedFont` created during `registerFont()` in `FontDef`
so that `_loadFont()` can reuse it. Remove the `fonts` property from
`DocumentDefinition`, along with `readFonts`, `readFont`,
`FontsDefinition`, `FontDefinition`, and the `FontStore` constructor
parameter. Update font-store tests to use `registerFont()` with explicit
config instead of pre-built `FontDef` arrays.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The `Font` type was a thin wrapper around `PDFFont`, duplicating
properties (`key`, `style`, `weight`) that already exist on the
underlying `PDFFont` class. Consumers always dereferenced `.pdfFont`
to access the actual font object.

Remove the `Font` type and use `PDFFont` directly throughout the
codebase. `FontStore.selectFont()` now returns `PDFFont` instead of
`Font`, eliminating the wrapping logic in `_loadFont`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ralfstx ralfstx merged commit a612fb6 into main Feb 15, 2026
1 check passed
@ralfstx ralfstx deleted the image-font branch February 15, 2026 15:07
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.

1 participant