forked from Brooooooklyn/canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
81 lines (69 loc) · 2.13 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!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">
<title>Canvas</title>
</head>
<body>
<style type="text/css">
@font-face {
font-family: "Iosevka Slab";
src: url("/__test__/fonts/iosevka-slab-regular.ttf");
}
body {
font-family: "Iosevka Slab"
}
canvas {
margin-top: 100px;
}
</style>
<canvas width="1024" height="768" id="canvas"></canvas>
<canvas width="1024" height="768" id="canvas-text"></canvas>
<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'
const baselines = ['top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom']
baselines.forEach(function (baseline) {
ctx.textBaseline = baseline
const metrics = ctx.measureText('@napi-rs/canvas')
console.info(baseline, metrics)
})
ctx.strokeText('skr canvas', 50, 150)
ctx.strokeText('@napi-rs/canvas', 50, 300)
}, 300)
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'
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>
</body>
</html>