Repository navigation
fix: quote font family names so @napi-rs/canvas 1.0.12+ accepts ctx.font - #102
Merged
Merged
Conversation
@napi-rs/canvas 1.0.12 parses ctx.font like Blink, which rejects the whole value when an unquoted family is not a valid CSS identifier sequence (the "1c" in "M PLUS Rounded 1c") and keeps the previous font. Every quote then rendered as tiny tofu in the 10px default font. Quote every non-generic family wherever a font shorthand is built, and cap @napi-rs/canvas below 1.0.12 until the other text layout changes in that release have been checked against the visual gallery.
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.
Problem
@napi-rs/canvas1.0.12 (released 2026-10-20) parsesctx.fontlike Blink. Blink rejects the whole value when an unquoted family is not a valid CSS identifier sequence, such as the1cinM PLUS Rounded 1c, and keeps the previous font. Becausemakeitaquotedeclared"@napi-rs/canvas": "^1.0.8", a fresh install picks up 1.0.13 and every quote renders as tiny tofu in the 10px default font. The lockfile here pins 1.0.8, so CI did not catch it.Reproduced on Windows and Linux (WSL Ubuntu 24.04) with
miq generate --text "日本語のテスト": 1.0.8 to 1.0.11 render correctly, 1.0.12 and 1.0.13 do not.ctx.fontset to40px M PLUS Rounded 1c, sans-serif10px serif)40px "M PLUS Rounded 1c", sans-serifFix
cssFontFamily(), which quotes every family in a list and leaves generic keywords and already-quoted names alone.fontString()uses it, and the two places that built a font shorthand by hand (textStyle.ts, the avatar fallback initial) now go throughfontString().@napi-rs/canvasat>=1.0.8 <1.0.12. 1.0.12 also changed text layout and rasterization to match Chrome, and measured widths differ, so the visual gallery should be checked before allowing it. With the quoting fix, Japanese text already renders correctly on 1.0.13.