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.
fix: wrong text metrics if text contains chars not including in curre…
…nt font-family
- Loading branch information
1 parent
bcec165
commit cfcca26
Showing
8 changed files
with
135 additions
and
108 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
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
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
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,107 +1,110 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<script src="/node_modules/canvaskit-wasm/bin/canvaskit.js"></script> | ||
<title>Canvas</title> | ||
</head> | ||
|
||
<body> | ||
<style type="text/css"> | ||
@font-face { | ||
font-family: 'Iosevka Slab'; | ||
src: url('/__test__/fonts/iosevka-slab-regular.ttf'); | ||
} | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<script src="/node_modules/canvaskit-wasm/bin/canvaskit.js"></script> | ||
<title>Canvas</title> | ||
</head> | ||
|
||
body { | ||
font-family: 'Iosevka Slab'; | ||
} | ||
<body> | ||
<style type="text/css"> | ||
@font-face { | ||
font-family: 'Iosevka Slab'; | ||
src: url('/__test__/fonts/iosevka-slab-regular.ttf'); | ||
} | ||
|
||
canvas { | ||
margin-top: 100px; | ||
} | ||
</style> | ||
<canvas width="1024" height="768" id="canvas"></canvas> | ||
<canvas width="1024" height="768" id="canvas-text"></canvas> | ||
<canvas width="512" height="512" id="regression"></canvas> | ||
<canvas width="512" height="512" id="text"></canvas> | ||
<img width="200" height="200" id="firefox" src="/__test__/fixtures/filter-combine-contrast-brightness.jpeg" /> | ||
<script> | ||
setTimeout(() => { | ||
const canvas = document.getElementById('canvas') | ||
/** | ||
* @type {CanvasRenderingContext2D} | ||
*/ | ||
const ctx = canvas.getContext('2d') | ||
ctx.fillStyle = 'yellow' | ||
ctx.fillRect(0, 0, canvas.width, canvas.height) | ||
ctx.strokeStyle = 'black' | ||
ctx.lineWidth = 3 | ||
ctx.font = '50px Iosevka Slab' | ||
body { | ||
font-family: 'Iosevka Slab'; | ||
} | ||
|
||
const baselines = ['top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom'] | ||
canvas { | ||
margin-top: 100px; | ||
} | ||
</style> | ||
<canvas width="1024" height="768" id="canvas"></canvas> | ||
<canvas width="1024" height="768" id="canvas-text"></canvas> | ||
<canvas width="512" height="512" id="regression"></canvas> | ||
<canvas width="512" height="512" id="text"></canvas> | ||
<img width="200" height="200" id="firefox" src="/__test__/fixtures/filter-combine-contrast-brightness.jpeg" /> | ||
<script> | ||
setTimeout(() => { | ||
const canvas = document.getElementById('canvas') | ||
/** | ||
* @type {CanvasRenderingContext2D} | ||
*/ | ||
const ctx = canvas.getContext('2d') | ||
ctx.fillStyle = 'yellow' | ||
ctx.fillRect(0, 0, canvas.width, canvas.height) | ||
ctx.strokeStyle = 'black' | ||
ctx.lineWidth = 3 | ||
ctx.font = '50px Iosevka Slab' | ||
|
||
baselines.forEach(function (baseline) { | ||
ctx.textBaseline = baseline | ||
const metrics = ctx.measureText('@napi-rs/canvas') | ||
console.info(baseline, metrics) | ||
}) | ||
const metrics = ctx.measureText('@napi-rs/canvas') | ||
console.info(metrics) | ||
const baselines = ['top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom'] | ||
|
||
ctx.strokeText('skr canvas', 50, 150) | ||
ctx.strokeText('@napi-rs/canvas', 50, 300) | ||
}, 300) | ||
baselines.forEach(function (baseline) { | ||
ctx.textBaseline = baseline | ||
const metrics = ctx.measureText('@napi-rs/canvas') | ||
console.info(baseline, metrics) | ||
}) | ||
|
||
setTimeout(() => { | ||
const canvas = document.getElementById('canvas-text') | ||
/** | ||
* @type {CanvasRenderingContext2D} | ||
*/ | ||
const ctx = canvas.getContext('2d') | ||
ctx.fillStyle = 'yellow' | ||
ctx.fillRect(0, 0, canvas.width, canvas.height) | ||
const baselines = ['top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom'] | ||
ctx.font = '36px Iosevka Slab' | ||
ctx.strokeStyle = 'red' | ||
ctx.fillStyle = 'black' | ||
ctx.strokeText('skr canvas', 50, 150) | ||
ctx.strokeText('@napi-rs/canvas', 50, 300) | ||
}, 300) | ||
|
||
baselines.forEach(function (baseline, index) { | ||
ctx.textBaseline = baseline | ||
const y = 75 + index * 75 | ||
ctx.beginPath() | ||
ctx.moveTo(0, y + 0.5) | ||
ctx.lineTo(550, y + 0.5) | ||
ctx.stroke() | ||
ctx.fillText('Abcdefghijklmnop (' + baseline + ')', 0, y) | ||
}) | ||
}, 300) | ||
</script> | ||
<script> | ||
setTimeout(() => { | ||
const canvas = document.getElementById('regression') | ||
const ctx = canvas.getContext('2d') | ||
ctx.filter = 'contrast(175%) brightness(103%)' | ||
const image = document.querySelector('#firefox') | ||
ctx.drawImage(image, 0, 0) | ||
}, 1000) | ||
</script> | ||
setTimeout(() => { | ||
const canvas = document.getElementById('canvas-text') | ||
/** | ||
* @type {CanvasRenderingContext2D} | ||
*/ | ||
const ctx = canvas.getContext('2d') | ||
ctx.fillStyle = 'yellow' | ||
ctx.fillRect(0, 0, canvas.width, canvas.height) | ||
const baselines = ['top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom'] | ||
ctx.font = '50px Iosevka Slab' | ||
ctx.fillStyle = 'black' | ||
|
||
baselines.forEach(function (baseline, index) { | ||
ctx.textBaseline = baseline | ||
const y = 75 + index * 75 | ||
ctx.beginPath() | ||
ctx.moveTo(0, y + 0.5) | ||
ctx.lineTo(550, y + 0.5) | ||
ctx.stroke() | ||
ctx.fillText('Abcdefghijklmnop (' + baseline + ')', 0, y) | ||
}) | ||
}, 300) | ||
</script> | ||
<script> | ||
setTimeout(() => { | ||
const canvas = document.getElementById('regression') | ||
const ctx = canvas.getContext('2d') | ||
ctx.filter = 'contrast(175%) brightness(103%)' | ||
const image = document.querySelector('#firefox') | ||
ctx.drawImage(image, 0, 0) | ||
}, 1000) | ||
</script> | ||
|
||
<script> | ||
setTimeout(() => { | ||
const canvas = document.getElementById('text') | ||
const ctx = canvas.getContext('2d') | ||
for (const align of ['center', 'end', 'left', 'right', 'start']) { | ||
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', x, 200) | ||
} | ||
}, 1000) | ||
</script> | ||
</body> | ||
|
||
<script> | ||
setTimeout(() => { | ||
const canvas = document.getElementById('text') | ||
const ctx = canvas.getContext('2d') | ||
for (const align of ['center', 'end', 'left', 'right', 'start']) { | ||
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', x, 200) | ||
} | ||
}, 1000) | ||
</script> | ||
</body> | ||
</html> | ||
</html> |
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
cfcca26
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
18.5
ops/sec (±0.71%
)22.6
ops/sec (±0.05%
)1.22
Draw house#node-canvas
19.4
ops/sec (±0.26%
)26.3
ops/sec (±0.34%
)1.36
Draw house#@napi-rs/skia
19
ops/sec (±0.58%
)22.9
ops/sec (±0.91%
)1.21
Draw gradient#skia-canvas
17.5
ops/sec (±0.8%
)21.7
ops/sec (±0.07%
)1.24
Draw gradient#node-canvas
18.4
ops/sec (±0.46%
)25.1
ops/sec (±0.28%
)1.36
Draw gradient#@napi-rs/skia
17.1
ops/sec (±2.16%
)22.2
ops/sec (±0.08%
)1.30
This comment was automatically generated by workflow using github-action-benchmark.