generated from napi-rs/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
085d74e
commit 435e102
Showing
11 changed files
with
108 additions
and
16 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { readFileSync } from 'fs' | ||
import { join } from 'path' | ||
|
||
import ava, { TestInterface } from 'ava' | ||
|
||
import { GlobalFonts, createCanvas, Canvas, SKRSContext2D } from '../index' | ||
import { snapshotImage } from './image-snapshot' | ||
|
||
const test = ava as TestInterface<{ | ||
canvas: Canvas | ||
ctx: SKRSContext2D | ||
}> | ||
|
||
const fontIosevka = readFileSync(join(__dirname, 'fonts', 'iosevka-slab-regular.ttf')) | ||
|
||
console.assert(GlobalFonts.register(fontIosevka), 'Register Iosevka font failed') | ||
|
||
test.beforeEach((t) => { | ||
const canvas = createCanvas(512, 512) | ||
t.context.canvas = canvas | ||
t.context.ctx = canvas.getContext('2d')! | ||
}) | ||
|
||
for (const align of ['center', 'end', 'left', 'right', 'start'] as CanvasTextAlign[]) { | ||
test(`text-align-${align}`, async (t) => { | ||
const { ctx, canvas } = t.context | ||
const x = canvas.width / 2 | ||
ctx.strokeStyle = 'black' | ||
ctx.moveTo(x, 0) | ||
ctx.lineTo(x, canvas.height) | ||
ctx.stroke() | ||
ctx.textAlign = align | ||
ctx.font = '16px Iosevka Slab' | ||
ctx.fillText('Hello Canvas', 0, 200) | ||
await snapshotImage(t) | ||
}) | ||
} |
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
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
435e102
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
27
ops/sec (±0.11%
)26
ops/sec (±0.25%
)0.96
Draw house#node-canvas
21
ops/sec (±0.23%
)21
ops/sec (±0.32%
)1
Draw house#@napi-rs/skia
25
ops/sec (±0.17%
)25
ops/sec (±0.8%
)1
Draw gradient#skia-canvas
26
ops/sec (±0.07%
)25.5
ops/sec (±0.48%
)0.98
Draw gradient#node-canvas
20
ops/sec (±0.16%
)20.4
ops/sec (±0.19%
)1.02
Draw gradient#@napi-rs/skia
24
ops/sec (±0.11%
)24.6
ops/sec (±0.05%
)1.03
This comment was automatically generated by workflow using github-action-benchmark.