Skip to content

fix: quote font family names so @napi-rs/canvas 1.0.12+ accepts ctx.font - #102

Merged
otnc merged 1 commit into
mainfrom
fix/quote-font-families
Oct 24, 2026
Merged

otnc merged 1 commit into
mainfrom
fix/quote-font-families

Conversation

@otnc

@otnc otnc commented Oct 24, 2026

Copy link
Copy Markdown
Member

Problem

@napi-rs/canvas 1.0.12 (released 2026-10-20) parses ctx.font like Blink. Blink rejects the whole value when an unquoted family is not a valid CSS identifier sequence, such as the 1c in M PLUS Rounded 1c, and keeps the previous font. Because makeitaquote declared "@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.font set to 1.0.11 1.0.13
40px M PLUS Rounded 1c, sans-serif accepted rejected (stays 10px serif)
40px "M PLUS Rounded 1c", sans-serif accepted accepted

Fix

  • Add 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 through fontString().
  • Cap @napi-rs/canvas at >=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.

@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.
@otnc
otnc merged commit c1c032d into main Oct 24, 2026
5 checks passed
@otnc
otnc deleted the fix/quote-font-families branch October 24, 2026 14:32
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