v2.5.0
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)
.
Changed
- test: fix test image timeout. #262
New Contributors
- @antmelnyk made their first contribution in #217
Full Changelog: v2.4.1...v2.5.0