Repository navigation
Say that no font is set instead of failing on null in documents created with font: null - #1867
Open
alphaNumericEntity wants to merge 1 commit into
Open
alphaNumericEntity wants to merge 1 commit into
alphaNumericEntity wants to merge 1 commit into
Conversation
…ed with font: null Fixes foliojs#1647
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix, fixes #1647.
The docs suggest
new PDFDocument({ font: null })for a document that shouldn't load Helvetica, for example in the browser build where standard fonts have to be registered first. Until a font is selected, though, almost everything text-related fails with aTypeErrorthat doesn't say what's wrong:The same happens with
moveUp(),currentLineHeight(),widthOfString(),heightOfString(),boundsOfString(),text()(wrapped or not),list()andtable(). That's the follow-up in #1647.Changes:
_requireFont()helper in the fonts mixin throwsNo font is set. Select one with doc.font(), or pass the font option when creating the document.It's called where the current font is first read:currentLineHeight(),widthOfString(),list()and_fragment()(fortext()withlineBreak: false, which doesn't go through the line wrapper). Every other path reaches one of these first. Each call sits where the font was already read, so only the error message changes; nothing that worked before throws now.getting_started.md, under "Setting default font", now shows the cleaner answer to the original request:new PDFDocument({ font: fontData })with aUint8Array, anArrayBufferor (in Node) a path starts the document with an embedded font and never loads a standard font. It also says whatfont: nullrequires. The browser section links to it.I also checked the original Deno report. With Deno 2.9.6, a
deno compiled binary runsnew PDFDocument()fine with both 0.17.0 and 0.20.2, so the failure that remains is thefont: nullone above.Not changed: on a
font: nulldocument, a table whose cells set their own font still fails, withNot a supported font format or standard PDF font., because the table code restores the previous font withdoc.font(null, ...)after measuring (lib/table/normalize.js:177, and the same pattern insize.jsandrender.js). It fails the same way on master. I left it alone because changing what restoring "no font" means seemed like a separate decision.Checklist:
yarn test(664 passed),yarn lint,yarn prettierandyarn test:packageall pass. The new tests fail on master with theTypeError.