Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-textMetrics-all.html

Issue 2232243002: Rewrite canvas/philip/tests/2d.text.draw.text.metrics.html test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: needs to be a async_test Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE HTML>
2 <head>
3 <style>
4 @font-face {
5 font-family: Libertine;
6 src: url('../../third_party/Libertine/LinLibertine_R.woff');
7 }
8 </style>
9 </head>
10 <script src="../../resources/testharness.js"></script>
11 <script src="../../resources/testharnessreport.js"></script>
12 <script>
13 function testTextMetrics(textMetrics, expected)
14 {
15 var w = textMetrics.width;
16 var ab = textMetrics.alphabeticBaseline;
17 var hb = textMetrics.hangingBaseline;
18 var ib = textMetrics.ideographicBaseline;
19 var fa = textMetrics.fontBoundingBoxAscent;
20 var fd = textMetrics.fontBoundingBoxDescent;
21 var ea = textMetrics.emHeightAscent;
22 var ed = textMetrics.emHeightDescent;
23 var lb = textMetrics.actualBoundingBoxLeft;
24 var rb = textMetrics.actualBoundingBoxRight;
25 var aa = textMetrics.actualBoundingBoxAscent;
26 var ad = textMetrics.actualBoundingBoxDescent;
27
28 var epsilon = 0.000001;
29 assert_equals(rb, Math.round(w), "testing width");
30 assert_approx_equals(ab, expected[0], epsilon, "testing alphabeticBaseline") ;
31 assert_approx_equals(hb, expected[1], epsilon, "testing hangingBaseline");
32 assert_approx_equals(ib, expected[2], epsilon, "testing ideographicBaseline" );
33 assert_approx_equals(fa, expected[3], epsilon, "testing fontBoundingBoxAscen t");
34 assert_approx_equals(fd, expected[4], epsilon, "testing fontBoundingBoxDesce nt");
35 assert_approx_equals(ea, expected[5], epsilon, "testing emHeightAscent");
36 assert_approx_equals(ed, expected[6], epsilon, "testing emHeightDescent");
37 assert_approx_equals(lb, expected[7], epsilon, "testing actualBoundingBoxLef t");
38 assert_approx_equals(aa, expected[8], epsilon, "testing actualBoundingBoxAsc ent");
39 assert_approx_equals(ad, expected[9], epsilon, "testing actualBoundingBoxDes cent");
40 }
41
42 function measureMetrics(ctx)
43 {
44 var text = "Hello World";
45
46 ctx.textBaseline = "top";
47 var textMetrics = ctx.measureText(text);
48 var expected = [45, 9, 57, 0, 57, 0, 0, 0, -45, 95];
49 testTextMetrics(textMetrics, expected);
50
51 ctx.textBaseline = "hanging";
52 var textMetrics = ctx.measureText(text);
53 expected = [36, 0, 48, 9, 48, 0, 0, 0, -36, 86];
54 testTextMetrics(textMetrics, expected);
55
56 ctx.textBaseline = "middle";
57 var textMetrics = ctx.measureText(text);
58 expected = [16, -20, 28, 29, 28, 0, 0, 0, -16, 66];
59 testTextMetrics(textMetrics, expected);
60
61 ctx.textBaseline = "alphabetic";
62 var textMetrics = ctx.measureText(text);
63 expected = [0, -36, 12, 45, 12, 0, 0, 0, 0, 50];
64 testTextMetrics(textMetrics, expected);
65
66 ctx.textBaseline = "ideographic";
67 var textMetrics = ctx.measureText(text);
68 expected = [-12, -48, 0, 57, 0, 0, 0, 0, 12, 38];
69 testTextMetrics(textMetrics, expected);
70
71 ctx.textBaseline = "bottom";
72 var textMetrics = ctx.measureText(text);
73 expected = [-12, -48, 0, 57, 0, 0, 0, 0, 12, 38];
74 testTextMetrics(textMetrics, expected);
75 }
76
77 async_test(function() {
78 var canvas = document.createElement('canvas');
79 canvas.width = 100;
80 canvas.height = 100;
81 var ctx = canvas.getContext('2d');
82 ctx.font = '50px Libertine';
83 // Kick off loading of the font
84 ctx.fillText(" ", 0, 0);
85 document.fonts.addEventListener('loadingdone', function() {
86 measureMetrics(ctx);
87 });
88 this.done();
89 }, "Test all attributes of TextMetrics.");
90 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698