-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.html
30 lines (29 loc) · 932 Bytes
/
example.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
<!doctype html>
<html>
<head>
<title>em.js Example</title>
</head>
<body>
<canvas id="canvas" width="600" height="300" style="border:1px solid black;">
You have no HTML5 canvas support.
</canvas>
<p style="font-weight: bold;">
Below is the output of the CanvasRenderingContext2D.measureText function which provides information about rendered text:
</p>
<p id="output"></p>
<script src="em.js" type="text/javascript"></script>
<script language="javascript">
document.addEventListener("DOMContentLoaded", function(event) {
var text = "Hello"
var font = "50px Georgia";
var canvas = document.getElementById('canvas');
var cx = canvas.getContext("2d");
cx.font = font;
metrics = cx.measureText(text);
cx.fillStyle = "#000000"
cx.fillText(text,0,metrics.actualBoundingBoxAscent);
document.getElementById('output').innerHTML = JSON.stringify(metrics);
});
</script>
</body>
</html>