content/canvas/test/test_canvas_font_setter.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug </title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
michael@0 13 <canvas id="display" height="200" width="200"></canvas>
michael@0 14 <pre id="test">
michael@0 15 <script type="application/javascript">
michael@0 16
michael@0 17 var canvas = document.getElementById("display");
michael@0 18 var cx = canvas.getContext("2d");
michael@0 19
michael@0 20 is(cx.font, "10px sans-serif", "initial font of canvas context");
michael@0 21
michael@0 22 cx.font = "italic 16px sans-serif";
michael@0 23 is(cx.font, "italic 16px sans-serif", "valid font should round-trip");
michael@0 24 cx.font = "bold 12px serif; background: green";
michael@0 25 is(cx.font, "italic 16px sans-serif", "invalid font should be ignored");
michael@0 26
michael@0 27 cx.font = "bold 12px/3.0 serif";
michael@0 28 is(cx.font, "bold 12px serif", "line-height should be dropped");
michael@0 29 cx.font = "inherit";
michael@0 30 is(cx.font, "bold 12px serif", "inherit should be ignored");
michael@0 31 cx.font = "boold 18px sans-serif";
michael@0 32 is(cx.font, "bold 12px serif", "syntax error should be ignored");
michael@0 33 cx.font = "menu";
michael@0 34 todo_is(cx.font, "menu", "system fonts should work");
michael@0 35
michael@0 36 function textmeas() {
michael@0 37 return cx.measureText("hello").width;
michael@0 38 }
michael@0 39
michael@0 40 cx.font = "66px serif";
michael@0 41 var w_at_66 = textmeas();
michael@0 42 cx.font = "20px serif";
michael@0 43 var w_at_20 = textmeas();
michael@0 44 ok(w_at_66 > w_at_20, "text should be wider at 66px than at 20px");
michael@0 45
michael@0 46 canvas.style.fontSize = "33px";
michael@0 47 cx.font = "2em serif";
michael@0 48 is(cx.font, "2em serif", "serialization of em");
michael@0 49 is(textmeas(), w_at_66, "em should be relative to canvas font size");
michael@0 50 canvas.style.fontSize = "16px";
michael@0 51 is(cx.font, "2em serif", "serialization of em");
michael@0 52 is(textmeas(), w_at_66,
michael@0 53 "em should be relative to canvas font size at time of setting");
michael@0 54 document.body.removeChild(canvas);
michael@0 55 is(cx.font, "2em serif", "serialization of em");
michael@0 56 is(textmeas(), w_at_66,
michael@0 57 "em should be relative to canvas font size at time of setting");
michael@0 58 canvas.style.fontSize = "33px";
michael@0 59 cx.font = "2em serif";
michael@0 60 is(cx.font, "2em serif", "serialization of em");
michael@0 61 is(textmeas(), w_at_20,
michael@0 62 "em should be relative to 10px when canvas not in document");
michael@0 63 document.body.appendChild(canvas);
michael@0 64
michael@0 65 </script>
michael@0 66 </pre>
michael@0 67 </body>
michael@0 68 </html>

mercurial