Skip to content

Commit

Permalink
2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Oct 16, 2023
1 parent 4e68970 commit b07a26f
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 16 deletions.
53 changes: 52 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,56 @@ This changelog also contains important changes in dependencies.

## [Unreleased]

## [2.5.0] - 2023-10-16

### Added

Now we can finally loading custom fonts in Wasm, including the WOFF2 format (see [playground](https://resvg-js.vercel.app/)), 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.

```html
<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](https://github.com/yisibl/resvg-js/issues/209)
- feat: support for loading custom fonts in Wasm, via the `fontBuffers` option. Thanks to @antmelnyk [#217](https://github.com/yisibl/resvg-js/issues/217)
- feat: support loading WOFF2 font in Wasm. Thanks to @yisibl [#220](https://github.com/yisibl/resvg-js/issues/220)
- chore: Wasm uses the same logic as Node.js to find the default font family.Thanks to @yisibl [#252](https://github.com/yisibl/resvg-js/issues/252)

We have improved the [upstream svgtypes#14](https://github.com/RazrFalcon/svgtypes/pull/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](https://github.com/yisibl/resvg-js/issues/266)

### Changed

- test: fix test image timeout. [#262](https://github.com/yisibl/resvg-js/issues/262)

## [2.4.1] - 2023-02-15

### Fixed
Expand Down Expand Up @@ -526,7 +576,8 @@ The first official version, use [resvg 0.18.0](https://github.com/RazrFalcon/res
- Support custom fonts and system fonts.
- Supports setting the background color of PNG.
[unreleased]: https://github.com/yisibl/resvg-js/compare/v2.4.1...HEAD
[unreleased]: https://github.com/yisibl/resvg-js/compare/v2.5.0...HEAD
[2.5.0]: https://github.com/yisibl/resvg-js/compare/v2.4.1...v2.5.0
[2.4.1]: https://github.com/yisibl/resvg-js/compare/v2.4.0...v2.4.1
[2.4.0]: https://github.com/yisibl/resvg-js/compare/v2.3.1...v2.4.0
[2.3.1]: https://github.com/yisibl/resvg-js/compare/v2.3.0...v2.3.1
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async function main() {
font: {
fontFiles: ['./example/SourceHanSerifCN-Light-subset.ttf'], // Load custom fonts.
loadSystemFonts: false, // It will be faster to disable loading system fonts.
defaultFontFamily: 'Source Han Serif CN Light',
// defaultFontFamily: 'Source Han Serif CN Light', // You can omit this.
},
}
const resvg = new Resvg(svg, opts)
Expand Down Expand Up @@ -161,11 +161,21 @@ This package also ships a pure WebAssembly artifact built with `wasm-bindgen` to
(async function () {
// The Wasm must be initialized first
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 = {
fitTo: {
mode: 'width', // If you need to change the size
value: 800,
},
font: {
fontBuffers: [buffer], // New in 2.5.0, loading custom fonts
},
}
const svg = '<svg> ... </svg>' // Input SVG, String or Uint8Array
Expand Down
2 changes: 1 addition & 1 deletion npm/android-arm-eabi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js-android-arm-eabi",
"version": "2.4.1",
"version": "2.5.0",
"os": [
"android"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/android-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js-android-arm64",
"version": "2.4.1",
"version": "2.5.0",
"os": [
"android"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js-darwin-arm64",
"version": "2.4.1",
"version": "2.5.0",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js-darwin-x64",
"version": "2.4.1",
"version": "2.5.0",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-arm-gnueabihf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js-linux-arm-gnueabihf",
"version": "2.4.1",
"version": "2.5.0",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js-linux-arm64-gnu",
"version": "2.4.1",
"version": "2.5.0",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js-linux-arm64-musl",
"version": "2.4.1",
"version": "2.5.0",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js-linux-x64-gnu",
"version": "2.4.1",
"version": "2.5.0",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js-linux-x64-musl",
"version": "2.4.1",
"version": "2.5.0",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-arm64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js-win32-arm64-msvc",
"version": "2.4.1",
"version": "2.5.0",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-ia32-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js-win32-ia32-msvc",
"version": "2.4.1",
"version": "2.5.0",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js-win32-x64-msvc",
"version": "2.4.1",
"version": "2.5.0",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-js",
"version": "2.4.1",
"version": "2.5.0",
"description": "A high-performance SVG renderer and toolkit, powered by Rust based resvg and napi-rs",
"main": "index.js",
"repository": "[email protected]:yisibl/resvg-js.git",
Expand Down
Binary file modified wasm/index_bg.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@resvg/resvg-wasm",
"version": "2.4.1",
"version": "2.5.0",
"description": "A high-performance SVG renderer and toolkit, powered by Rust based resvg and napi-rs",
"main": "index.js",
"module": "index.mjs",
Expand Down

1 comment on commit b07a26f

@vercel
Copy link

@vercel vercel bot commented on b07a26f Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

resvg-js – ./

resvg-js-yisibl.vercel.app
resvg-js-git-main-yisibl.vercel.app
resvg-js.vercel.app

Please sign in to comment.