gecko-dev/content/canvas/test/test_text.measure.html

40 строки
1.1 KiB
HTML

<!DOCTYPE HTML>
<title>Canvas test: text.measure</title>
<script src="/MochiKit/MochiKit.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
<body>
<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
<script>
var _deferred = false;
SimpleTest.waitForExplicitFinish();
MochiKit.DOM.addLoadEvent(function () {
var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');
ctx.font = "10px sans-serif";
ctx.textAlign = "left";
ctx.textBaseline = "top";
var str = 'Test String';
var wid = ctx.measureText(str).width;
ok(wid > 0, "measureText returns nonpositive value for non-empty string");
ctx.font = "20px sans-serif";
isnot(wid, ctx.measureText(str).width, "measureText does not change with a different font size");
ctx.font = "10px sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "alphabetic";
is(wid, ctx.measureText(str).width, "measureText changes when alignement/baseline is changed");
if (!_deferred) SimpleTest.finish();
});
</script>