Skip to content

Commit

Permalink
test: add load custom WOFF2 font test case
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Sep 25, 2023
1 parent 6fb4fdc commit 24b9f07
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions __test__/wasm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,27 @@ test('should be load custom multiple fontBuffers', async (t) => {
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 8938)
})

test('should be load custom WOFF2 font', async (t) => {
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" width="500" height="200" viewBox="0 0 500 200">
<text fill="blue" font-size="60">
<tspan x="40" y="100">Hello resvg-js</tspan>
</text>
</svg>
`
const pacificoBuffer = await fs.readFile(join(__dirname, '../wasm/fonts/', 'Pacifico-Regular.woff2'))
const resvg = new Resvg(svg, {
font: {
fontBuffers: [pacificoBuffer],
},
})
const pngData = resvg.render()
const originPixels = Array.from(pngData.pixels)

// Find the number of blue `rgb(0,255,255)`pixels
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 6067)
})

test('should generate a 80x80 png and opaque', async (t) => {
const svg = `<svg width="200px" height="200px" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg">
<rect fill="green" x="0" y="0" width="100" height="100"></rect>
Expand Down
Binary file removed example/Pacifico-Regular.woff2
Binary file not shown.
4 changes: 2 additions & 2 deletions wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
user-select: none;
}

input:not([type="color"]) {
input:not([type="color"]), select {
height: 30px;
padding: 0 .5em;
font-size: 16px;
Expand Down Expand Up @@ -148,7 +148,7 @@

#slt-svg,
#slt-font {
max-width: 180px;
max-width: 230px;
}

.github {
Expand Down

1 comment on commit 24b9f07

@vercel
Copy link

@vercel vercel bot commented on 24b9f07 Sep 25, 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.vercel.app
resvg-js-yisibl.vercel.app
resvg-js-git-main-yisibl.vercel.app

Please sign in to comment.