Skip to content

v2.5.0

Compare
Choose a tag to compare
@github-actions github-actions released this 16 Oct 08:31
· 52 commits to main since this release

What's Changed

Added

Now we can finally loading custom fonts in Wasm, including the WOFF2 format (see playground), thanks to the high-performance woff2-rs.

In addition, we implemented smarter default font family fallback. the defaultFontFamily option can now be omitted. We'll read the font-family from the incoming fonts and set it to the default.

<script src="https://unpkg.com/@resvg/resvg-wasm"></script>
<script>
  (async function () {
    await resvg.initWasm(fetch('https://unpkg.com/@resvg/resvg-wasm/index_bg.wasm'))

    const font = await fetch('./fonts/Pacifico-Regular.woff2')
    if (!font.ok) return

    const fontData = await font.arrayBuffer()
    const buffer = new Uint8Array(fontData)

    const opts = {
      font: {
        fontBuffers: [buffer], // New in 2.5.0, loading custom fonts.
        // defaultFontFamily: 'Pacifico', // You can omit this.
      },
    }

    const svg = '<svg> ... </svg>' // Input SVG, String or Uint8Array
    const resvgJS = new resvg.Resvg(svg, opts)
    const pngData = resvgJS.render(svg, opts) // Output PNG data, Uint8Array
    const pngBuffer = pngData.asPng()
    const svgURL = URL.createObjectURL(new Blob([pngData], { type: 'image/png' }))
    document.getElementById('output').src = svgURL
  })()
</script>
  • feat: improve custom loaded fonts. Thanks to @yisibl #209
  • feat: support for loading custom fonts in Wasm, via the fontBuffers option. Thanks to @antmelnyk #217
  • feat: support loading WOFF2 font in Wasm. Thanks to @yisibl #220
  • chore: Wasm uses the same logic as Node.js to find the default font family.Thanks to @yisibl #252

We have improved the upstream svgtypes#14, allow parsing of float rgb()/rgba() values from CSS Color 4 draft like rgb(3.14, 110, 201).

  • fix(deps): update rust crate svgtypes to 0.12.0. Thanks to @yisibl #266

Changed

  • test: fix test image timeout. #262

New Contributors

Full Changelog: v2.4.1...v2.5.0