Skip to content

feat(pdf): add font metrics, time limits and image loading - #397

Open
gcutrini wants to merge 1 commit into
v5.xfrom
feature/pdf-toolkit-loaders-v5
Open

gcutrini wants to merge 1 commit into
v5.xfrom
feature/pdf-toolkit-loaders-v5

Conversation

@gcutrini

Copy link
Copy Markdown
Contributor

ref: https://app.clickup.com/t/86bbf0d90

Moves the font and image loading that the my-orders receipt does on its own into the toolkit, so every PDF widget gets it.

Fonts

  • A URL font that doesn't download within 10 seconds, isn't a TTF, OTF or WOFF file, is cut short, or is WOFF2 prints in Helvetica, with a console warning that names the font. pdfmake prints most WOFF2 fonts as blank text, without an error. None of these is cached.
  • A font without a bold, italics or bold italics file uses its closest style instead of failing the document. A font with no file at all prints in Helvetica.
  • loadFont(pdfMake, font) returns { family, fontMetrics }. createDocument passes fontMetrics to the template: each style's ascender and capital height per em, or null when they can't be read, for lining shapes up with text.

Images

  • loadImage(src, { maxWidth, maxHeight }) returns a node to spread into the document: { image } for PNG and JPEG, { svg } for an SVG file, and a canvas-drawn PNG for other formats. It gives up after 10 seconds and returns null when the image can't be loaded.

resolveFont and imageDataUrl keep their signatures.

Same change as #392 for the 5.x line.

A URL font that doesn't download within 10 seconds, isn't a TTF, OTF or
WOFF file, is cut short, or is WOFF2 (which pdfmake prints blank) falls
back to Helvetica, and isn't cached. A missing bold or italics style uses
the closest file the font has. loadFont also returns each style's
ascender and capital height, and createDocument passes them to the
template as fontMetrics.

loadImage loads an image within 10 seconds: PNG and JPEG as they are,
SVG as vector, other formats drawn to PNG. It returns null when the image
can't be loaded.
@gcutrini gcutrini self-assigned this Nov 23, 2026
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ade0d0b9-45d3-4fc5-9644-1a88812d9266

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@santipalenque santipalenque 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.

LGTM

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