Packages

@napi-rs/canvas

1.2.0 · 21 Nov 2026MIT56.8M / weekRepositoryHomepagenpmAtom feed

Your version

1.2.0

Latest21 Nov 2026Where it was published

In short

3 new

Release note

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 return null without registering; non-object descriptors throw a TypeError.

  • Variable fonts clamp wght/slnt/wdth to declared descriptor ranges, use the ital axis for italic when available, and apply variation coordinates in SVG <text>.

  • Static (non-variable) font-stretch matching now follows CSS Fonts Level 4 (Width > Style > Weight priority 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 use loadFontsFromDir to match by each file's own style.

DirectWrite and Fontations on Windows in setTextRenderer('system')

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

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

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().

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.