summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/canvas-set-font-with-updated-style.html
blob: 9290f32bf36153f01f5ca29c89f09756d9608d4b (plain)
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
31
32
33
34
35
36
<!DOCTYPE HTML>
<html>
<body onload="runTest();">
<div>
<span>Tests that setting font of Canvas 2d context always uses up-to-date style and has font value: <span id="result"></span></span><br>
<canvas id="canvasTest"></canvas>
</div>
<script type="text/javascript">
if (window.testRunner)
    testRunner.dumpAsText();

function drawCanvasText(id, text)
{
    var canvasElement = document.getElementById(id);
    var context = canvasElement.getContext('2d');

    // Pre-draw pass to add the font to the font cache. This way, the test also
    // verifies that the style change correctly invalidates the font resolution cache.
    context.font = '1em Calibri';
    context.fillText(text, 0, 100);

    canvasElement.style.fontSize = '64px';
    context.font = '1em Calibri';
    context.fillText(text, 0, 100);
    return context.font;
}

function runTest()
{
    var fontSize = drawCanvasText('canvasTest', 'Some Text');
    var resultElement = document.getElementById('result');
    resultElement.textContent = fontSize;
}
</script>
</body>
</html>