| Index: third_party/WebKit/LayoutTests/fast/canvas/canvas-textMetrics-all.html
|
| diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-textMetrics-all.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-textMetrics-all.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5321dffda89f574d4810f320cd2e21c9d6de787e
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-textMetrics-all.html
|
| @@ -0,0 +1,90 @@
|
| +<!DOCTYPE HTML>
|
| +<head>
|
| +<style>
|
| +@font-face {
|
| + font-family: Libertine;
|
| + src: url('../../third_party/Libertine/LinLibertine_R.woff');
|
| +}
|
| +</style>
|
| +</head>
|
| +<script src="../../resources/testharness.js"></script>
|
| +<script src="../../resources/testharnessreport.js"></script>
|
| +<script>
|
| +function testTextMetrics(textMetrics, expected)
|
| +{
|
| + var w = textMetrics.width;
|
| + var ab = textMetrics.alphabeticBaseline;
|
| + var hb = textMetrics.hangingBaseline;
|
| + var ib = textMetrics.ideographicBaseline;
|
| + var fa = textMetrics.fontBoundingBoxAscent;
|
| + var fd = textMetrics.fontBoundingBoxDescent;
|
| + var ea = textMetrics.emHeightAscent;
|
| + var ed = textMetrics.emHeightDescent;
|
| + var lb = textMetrics.actualBoundingBoxLeft;
|
| + var rb = textMetrics.actualBoundingBoxRight;
|
| + var aa = textMetrics.actualBoundingBoxAscent;
|
| + var ad = textMetrics.actualBoundingBoxDescent;
|
| +
|
| + var epsilon = 0.000001;
|
| + assert_equals(rb, Math.round(w), "testing width");
|
| + assert_approx_equals(ab, expected[0], epsilon, "testing alphabeticBaseline");
|
| + assert_approx_equals(hb, expected[1], epsilon, "testing hangingBaseline");
|
| + assert_approx_equals(ib, expected[2], epsilon, "testing ideographicBaseline");
|
| + assert_approx_equals(fa, expected[3], epsilon, "testing fontBoundingBoxAscent");
|
| + assert_approx_equals(fd, expected[4], epsilon, "testing fontBoundingBoxDescent");
|
| + assert_approx_equals(ea, expected[5], epsilon, "testing emHeightAscent");
|
| + assert_approx_equals(ed, expected[6], epsilon, "testing emHeightDescent");
|
| + assert_approx_equals(lb, expected[7], epsilon, "testing actualBoundingBoxLeft");
|
| + assert_approx_equals(aa, expected[8], epsilon, "testing actualBoundingBoxAscent");
|
| + assert_approx_equals(ad, expected[9], epsilon, "testing actualBoundingBoxDescent");
|
| +}
|
| +
|
| +function measureMetrics(ctx)
|
| +{
|
| + var text = "Hello World";
|
| +
|
| + ctx.textBaseline = "top";
|
| + var textMetrics = ctx.measureText(text);
|
| + var expected = [45, 9, 57, 0, 57, 0, 0, 0, -45, 95];
|
| + testTextMetrics(textMetrics, expected);
|
| +
|
| + ctx.textBaseline = "hanging";
|
| + var textMetrics = ctx.measureText(text);
|
| + expected = [36, 0, 48, 9, 48, 0, 0, 0, -36, 86];
|
| + testTextMetrics(textMetrics, expected);
|
| +
|
| + ctx.textBaseline = "middle";
|
| + var textMetrics = ctx.measureText(text);
|
| + expected = [16, -20, 28, 29, 28, 0, 0, 0, -16, 66];
|
| + testTextMetrics(textMetrics, expected);
|
| +
|
| + ctx.textBaseline = "alphabetic";
|
| + var textMetrics = ctx.measureText(text);
|
| + expected = [0, -36, 12, 45, 12, 0, 0, 0, 0, 50];
|
| + testTextMetrics(textMetrics, expected);
|
| +
|
| + ctx.textBaseline = "ideographic";
|
| + var textMetrics = ctx.measureText(text);
|
| + expected = [-12, -48, 0, 57, 0, 0, 0, 0, 12, 38];
|
| + testTextMetrics(textMetrics, expected);
|
| +
|
| + ctx.textBaseline = "bottom";
|
| + var textMetrics = ctx.measureText(text);
|
| + expected = [-12, -48, 0, 57, 0, 0, 0, 0, 12, 38];
|
| + testTextMetrics(textMetrics, expected);
|
| +}
|
| +
|
| +async_test(function() {
|
| + var canvas = document.createElement('canvas');
|
| + canvas.width = 100;
|
| + canvas.height = 100;
|
| + var ctx = canvas.getContext('2d');
|
| + ctx.font = '50px Libertine';
|
| + // Kick off loading of the font
|
| + ctx.fillText(" ", 0, 0);
|
| + document.fonts.addEventListener('loadingdone', function() {
|
| + measureMetrics(ctx);
|
| + });
|
| + this.done();
|
| +}, "Test all attributes of TextMetrics.");
|
| +</script>
|
|
|