Repository navigation
Highlights
node-canvas registerFont() descriptors and cleanup (#1473)
registerFont(path, { family, weight, style }) now passes weight and style as @font-face descriptors. Families registered one face per call now select the requested regular, bold, italic, or bold italic face correctly, fixing the v1.2.0 regression reported in #1472.
const { registerFont } = require('@napi-rs/canvas/node-canvas')
registerFont('./fonts/Lato-Regular.ttf', { family: 'MyLato', weight: 400 })
registerFont('./fonts/Lato-Bold.ttf', { family: 'MyLato', weight: 700 })- Descriptors follow the
@font-facegrammar, including numeric weights,calc(700), and'oblique 10deg'. Omitted or invalid fields areauto. - An explicit weight, including
'normal', pins a variable font to that weight. Use a range such as'100 900'to preserve its variation axis. - Faces declared bold or italic follow their descriptor without adding synthetic bold or italic when the underlying file lacks that style.
deregisterAllFonts()removes only theregisterFont()registrations owned by the current thread. Registrations made throughGlobalFontsandloadFontsFromDir()remain untouched. Worker registrations survive worker exit, matching node-canvas; worker pools should callderegisterAllFonts()before each worker exits.
Behavior change: a non-empty
familyis now the face’s only name, matching Chrome’snew FontFace(family, ...). Passfamily: ''or the embedded family name to register the face under its embedded name.
Chrome-compatible fontVariationSettings and variable-font fixes (#1470)
The non-standard, experimental ctx.fontVariationSettings property now follows Chrome’s CSS font-variation-settings parsing, serialization, and WebIDL coercion:
- Supports CSS math functions, comments, escaped quotes and backslashes, tags containing commas, duplicate tags with last-value-wins behavior, and ascending tag-order serialization.
- Invalid values are ignored without corrupting the current font state. Non-string values use WebIDL
ToString;Symbolvalues throw aTypeError. - Variable fonts avoid incorrect synthetic bold or italic when
fontVariationSettingsoverrides theirwghtorslntaxes. .ttcfaces preserve their collection index across font cloning and variation paths, including Fontations and DirectWrite.
Skia chrome/m158 (#1469)
Upgrades Skia from chrome/m157 (b94213a11b) to chrome/m158 (37e919d866). The Skia-tied Fontations dependencies are synchronized to font-types 0.12.6, read-fonts 0.45.0, and skrifa 0.48.0. This also updates the Windows Skia build toolchain.
What's Changed
- feat: chrome/m158 by @Brooooooklyn in #1469
- fix(fonts): align fontVariationSettings with Chrome CSS and fix VF edge cases by @Brooooooklyn in #1470
- chore(deps): update yarn to v4.19.0 by @renovate[bot] in #1471
- fix(node-canvas): registerFont descriptors and private cleanup registrations by @Brooooooklyn in #1473
Full Changelog: v1.2.0...v1.2.1