Repository navigation
v1.2.0
Highlights
@font-face descriptors in GlobalFonts and static font-stretch matching (#1464, #1465, #1467)
GlobalFonts.register(font, nameAlias?, descriptors?) and GlobalFonts.registerFromPath(path, nameAlias?, descriptors?) now accept a descriptors object ({ weight, style, stretch }), matching Chrome's new FontFace(name, data, descriptors):
- Supports CSS values, ranges (
'100 900','oblique 10deg 20deg','75% 125%'),calc(), and'auto'. Invalid descriptors returnnullwithout registering; non-object descriptors throw aTypeError. - Variable fonts clamp
wght/slnt/wdthto declared descriptor ranges, use theitalaxis foritalicwhen available, and apply variation coordinates in SVG<text>. - Static (non-variable)
font-stretchmatching now follows CSS Fonts Level 4 (Width > Style > Weightpriority and exact matches for expanded widths).
GlobalFonts.registerFromPath('./fonts/Lato-Regular.ttf', 'MyLato', { weight: 400 })
GlobalFonts.registerFromPath('./fonts/Lato-Bold.ttf', 'MyLato', { weight: 700 })Behavior change: registered faces without descriptors are all
auto, so in a family registered without descriptors, the most recently registered face draws every style (with synthetic bold/italic when needed), matching Chrome@font-face. Pass{ weight, style, stretch }for each file in a family, or useloadFontsFromDirto match by each file's own style.
DirectWrite and Fontations on Windows in setTextRenderer('system') (#1468)
setTextRenderer('system') on Windows now uses DirectWrite (with Fontations for color, CFF2, avar2, and unsupported variable fonts) plus Chrome Windows' gamma/contrast and rasterizer settings. The default 'portable' text renderer is unchanged across all OSes.
PNG compressionLevel and filters options (#1463)
encode('png', options), encodeSync('png', options), toBuffer('image/png', options), and the node-canvas compatibility PngConfig now accept compressionLevel (zlib 0–9, default 6) and filters (libpng row filter bitmask via the new PngFilter export, default PngFilter.All / 0xF8):
const { createCanvas, PngFilter } = require('@napi-rs/canvas')
// Fast PNG encoding (Chromium's canvas preset: zlib level 1, Up filter only)
const png = await canvas.encode('png', {
compressionLevel: 1,
filters: PngFilter.Up,
})ctx.antialias property (#1466)
Adds the node-canvas-compatible ctx.antialias property ('default' | 'none' | 'gray' | 'subpixel', default 'default'), saved and restored with save()/restore()/reset(). Setting 'none' disables antialiasing on raster shapes, strokes, clips, text, and bitmap image borders without affecting measureText().
What's Changed
- chore(deps): update rust to v1.100.0 by @renovate[bot] in #1457
- fix(deps): update and group libavif crates by @Brooooooklyn in #1461
- feat(fonts):
@font-facedescriptors in GlobalFonts.register by @lavrton in #1464 - feat(fonts): @font-face descriptor follow-ups of #1464 by @Brooooooklyn in #1465
- feat(encode): PNG compressionLevel and filters by @lavrton in #1463
- feat(canvas): add ctx.antialias property by @Brooooooklyn in #1466
- feat(fonts): support @font-face stretch descriptor and fix static font-stretch matching by @Brooooooklyn in #1467
- feat(text): use DirectWrite and Fontations on Windows in system text renderer by @Brooooooklyn in #1468
New Contributors
Full Changelog: v1.1.1...v1.2.0