generated from napi-rs/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b77f45d
commit f95f67a
Showing
14 changed files
with
444 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { join } from 'path' | ||
|
||
import ava, { TestInterface } from 'ava' | ||
|
||
import { createCanvas, SvgCanvas, SvgExportFlag, GlobalFonts } from '../index' | ||
|
||
const test = ava as TestInterface<{ | ||
canvas: SvgCanvas | ||
}> | ||
|
||
test.beforeEach((t) => { | ||
t.context.canvas = createCanvas(1024, 768, SvgExportFlag.ConvertTextToPaths) | ||
}) | ||
|
||
test('should be able to export path/arc/rect', (t) => { | ||
const { canvas } = t.context | ||
const ctx = canvas.getContext('2d') | ||
ctx.fillStyle = 'yellow' | ||
ctx.fillRect(0, 0, canvas.width, canvas.height) | ||
ctx.lineWidth = 3 | ||
ctx.strokeStyle = 'hotpink' | ||
ctx.strokeRect(50, 450, 100, 100) | ||
ctx.fillStyle = 'hotpink' | ||
ctx.arc(500, 120, 90, 0, Math.PI * 2) | ||
ctx.fill() | ||
t.snapshot(canvas.getContent().toString('utf8')) | ||
}) | ||
|
||
test('should be able to export text', (t) => { | ||
GlobalFonts.registerFromPath(join(__dirname, 'fonts-dir', 'iosevka-curly-regular.woff2'), 'i-curly') | ||
const { canvas } = t.context | ||
const ctx = canvas.getContext('2d') | ||
ctx.fillStyle = 'yellow' | ||
ctx.fillRect(0, 0, canvas.width, canvas.height) | ||
ctx.lineWidth = 3 | ||
ctx.strokeStyle = 'hotpink' | ||
ctx.font = '50px i-curly' | ||
ctx.strokeText('@napi-rs/canvas', 50, 300) | ||
t.snapshot(canvas.getContent().toString('utf8')) | ||
}) |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { readFileSync, writeFileSync } = require('fs') | ||
const { join } = require('path') | ||
|
||
const { createCanvas, GlobalFonts, SvgExportFlag } = require('../index.js') | ||
|
||
const WoffFontPath = join(__dirname, '..', '__test__', 'fonts', 'Virgil.woff2') | ||
|
||
GlobalFonts.registerFromPath(WoffFontPath, 'Virgil') | ||
|
||
const canvas = createCanvas(1024, 768, SvgExportFlag.ConvertTextToPaths) | ||
const ctx = canvas.getContext('2d') | ||
ctx.fillStyle = 'yellow' | ||
ctx.fillRect(0, 0, canvas.width, canvas.height) | ||
ctx.strokeStyle = 'cyan' | ||
ctx.lineWidth = 3 | ||
ctx.font = '50px Virgil' | ||
ctx.strokeText('skr canvas', 50, 150) | ||
|
||
ctx.strokeStyle = 'hotpink' | ||
|
||
ctx.strokeText('@napi-rs/canvas', 50, 300) | ||
|
||
ctx.strokeStyle = 'gray' | ||
|
||
ctx.strokeRect(50, 450, 100, 100) | ||
|
||
ctx.fillStyle = 'hotpink' | ||
|
||
ctx.arc(500, 120, 90, 0, Math.PI * 2) | ||
ctx.fill() | ||
|
||
const b = canvas.getContent() | ||
|
||
writeFileSync(join(__dirname, 'export-text.svg'), b) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
nightly-2021-06-09 | ||
nightly-2021-07-29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
f95f67a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
Draw house#skia-canvas
20.6
ops/sec (±0.8%
)19.3
ops/sec (±0.95%
)0.94
Draw house#node-canvas
20.7
ops/sec (±0.93%
)20.1
ops/sec (±1.75%
)0.97
Draw house#@napi-rs/skia
19.8
ops/sec (±0.6%
)20.4
ops/sec (±1.5%
)1.03
Draw gradient#skia-canvas
19
ops/sec (±2.41%
)18
ops/sec (±1.76%
)0.95
Draw gradient#node-canvas
20.1
ops/sec (±0.76%
)19
ops/sec (±1.53%
)0.95
Draw gradient#@napi-rs/skia
19.1
ops/sec (±0.98%
)20
ops/sec (±1.22%
)1.05
This comment was automatically generated by workflow using github-action-benchmark.