Skip to content

v1.2.0

Choose a tag to compare

@github-actions github-actions released this 21 Nov 02:45
· 3 commits to main since this release
v1.2.0
7d290bd

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') (#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

New Contributors

Full Changelog: v1.1.1...v1.2.0