OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Canvas test: 2d.text.draw.text.metrics</title> | 2 <title>Canvas test: 2d.text.draw.text.metrics</title> |
3 <script src="../tests.js"></script> | 3 <script src="../tests.js"></script> |
4 <link rel="stylesheet" href="../tests.css"> | 4 <link rel="stylesheet" href="../tests.css"> |
5 <style> | 5 <style> |
6 @font-face { | 6 @font-face { |
7 font-family: CanvasTest; | 7 font-family: Libertine; |
8 src: url("../fonts/CanvasTest.ttf"); | 8 src: url("../../../third_party/Libertine/LinLibertine_R.woff"); |
9 } | 9 } |
10 </style> | 10 </style> |
11 <body> | 11 <body> |
12 <p id="passtext">Pass</p> | 12 <p id="passtext">Pass</p> |
13 <p id="failtext">Fail</p> | 13 <p id="failtext">Fail</p> |
14 <span style="font-family: CanvasTest; position: absolute; visibility: hidden">A<
/span> | |
15 <p class="output">These images should be identical:</p> | 14 <p class="output">These images should be identical:</p> |
16 <canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (
fallback content)</p></canvas> | 15 <canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (
fallback content)</p></canvas> |
17 <p class="output expectedtext">Expected output:<p><img src="green-100x50.png" cl
ass="output expected" id="expected" alt=""> | 16 <p class="output expectedtext">Expected output:<p><img src="green-100x50.png" cl
ass="output expected" id="expected" alt=""> |
18 <ul id="d"></ul> | 17 <ul id="d"></ul> |
19 <script> | 18 <script> |
20 function _printTextMetrics(ctx) { | 19 function _printTextMetrics(ctx) { |
21 var someText = "Some Text"; | 20 var someText = "Some Text"; |
22 var highText = "M"; | 21 var highText = "M"; |
23 var lowText = "q"; | 22 var lowText = "q"; |
24 var textMetrics = ctx.measureText(someText); | 23 var textMetrics = ctx.measureText(someText); |
(...skipping 24 matching lines...) Expand all Loading... |
49 _warn("eM Height Ascent: " + ea); | 48 _warn("eM Height Ascent: " + ea); |
50 _warn("eM Height Descent: " + ed); | 49 _warn("eM Height Descent: " + ed); |
51 _warn("Actual Bounding Box Left: " + lb); | 50 _warn("Actual Bounding Box Left: " + lb); |
52 _warn("Actual Bounding Box Right: " + rb); | 51 _warn("Actual Bounding Box Right: " + rb); |
53 _warn("Actual Bounding Box Ascent (high): " + ah); | 52 _warn("Actual Bounding Box Ascent (high): " + ah); |
54 _warn("Actual Bounding Box Ascent (low): " + al); | 53 _warn("Actual Bounding Box Ascent (low): " + al); |
55 _warn("Actual Bounding Box Descent (high): " + dh); | 54 _warn("Actual Bounding Box Descent (high): " + dh); |
56 _warn("Actual Bounding Box Descent (low): " + dl); | 55 _warn("Actual Bounding Box Descent (low): " + dl); |
57 } | 56 } |
58 | 57 |
59 _addTest(function(canvas, ctx) { | |
60 | 58 |
61 ctx.font = '50px CanvasTest'; | 59 function measureMetrics(ctx) { |
62 deferTest(); | |
63 setTimeout(wrapFunction(function () { | |
64 ctx.fillStyle = '#f00'; | 60 ctx.fillStyle = '#f00'; |
65 ctx.fillRect(0, 0, 100, 50); | 61 ctx.fillRect(0, 0, 100, 50); |
66 ctx.fillStyle = '#0f0'; | 62 ctx.fillStyle = '#0f0'; |
67 | 63 |
68 ctx.textBaseline="top"; | 64 ctx.textBaseline="top"; |
69 _warn("Baseline: top"); | 65 _warn("Baseline: top"); |
70 _printTextMetrics(ctx); | 66 _printTextMetrics(ctx); |
71 | 67 |
72 ctx.textBaseline="hanging"; | 68 ctx.textBaseline="hanging"; |
73 _warn("Baseline: hanging"); | 69 _warn("Baseline: hanging"); |
74 _printTextMetrics(ctx); | 70 _printTextMetrics(ctx); |
75 | 71 |
76 ctx.textBaseline="middle"; | 72 ctx.textBaseline="middle"; |
77 _warn("Baseline: middle"); | 73 _warn("Baseline: middle"); |
78 _printTextMetrics(ctx); | 74 _printTextMetrics(ctx); |
79 | 75 |
80 ctx.textBaseline="alphabetic"; | 76 ctx.textBaseline="alphabetic"; |
81 _warn("Baseline: alphabetic"); | 77 _warn("Baseline: alphabetic"); |
82 _printTextMetrics(ctx); | 78 _printTextMetrics(ctx); |
83 | 79 |
84 ctx.textBaseline="ideographic"; | 80 ctx.textBaseline="ideographic"; |
85 _warn("Baseline: ideographic"); | 81 _warn("Baseline: ideographic"); |
86 _printTextMetrics(ctx); | 82 _printTextMetrics(ctx); |
87 | 83 |
88 ctx.textBaseline="bottom"; | 84 ctx.textBaseline="bottom"; |
89 _warn("Baseline: bottom"); | 85 _warn("Baseline: bottom"); |
90 _printTextMetrics(ctx); | 86 _printTextMetrics(ctx); |
91 }), 500); | |
92 | 87 |
| 88 endTest(); |
| 89 } |
93 | 90 |
| 91 function handleError() { |
| 92 _warn("Unable to load required test font."); |
| 93 endTest(); |
| 94 } |
| 95 |
| 96 _addTest(function(canvas, ctx) { |
| 97 ctx.font = '50px Libertine'; |
| 98 deferTest(); |
| 99 document.fonts.load(ctx.font) |
| 100 .then(function() { measureMetrics(ctx) }, handleError); |
94 }); | 101 }); |
95 </script> | 102 </script> |
96 | 103 |
OLD | NEW |