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

Side by Side Diff: LayoutTests/fast/canvas/canvas-normalize-string.html

Issue 567543002: Avoid re-parsing of string in fillText and measureText in Canvas (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updating test expectation file Created 6 years, 2 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 <html>
2 <head>
3 <meta charset="UTF-8" />
4 <title>Canvas Normalized String Test</title>
5 </head>
6
7 <body>
8 <p>On success, two same text string with equal width will be rendered.</p>
9 <canvas id="myCanvas" width="300px" height="300px" style="border:1px solid #c3c3 c3;">
10 Your browser does not support the canvas element.
11 </canvas>
12 <div id="console"></div>
13
14 <script type="text/javascript">
15 function compareImageData(img1,img2)
16 {
17 if(img1.data.length != img2.data.length)
18 return false;
19
20 for(var i = 0; i < img1.data.length; ++i){
21 if(img1.data[i] != img2.data[i])
22 return false;
23 }
24 return true;
25 }
26
27 function compareStrings(string1, string2, fontSize, ctx, yCo)
28 {
29 ctx.fillText(string1, 10, yCo);
30 var imgDataCombinedText = ctx.getImageData(10,yCo-fontSize, ctx.measureText( string1).width,fontSize);
31
32 yCo += fontSize * 2;
33 ctx.fillText(string2, 10, yCo);
34 var imgData = ctx.getImageData(10, yCo-fontSize, ctx.measureText(string2).wi dth,fontSize);
35 return compareImageData(imgDataCombinedText, imgData);
36 }
37
38 if (window.testRunner)
39 testRunner.dumpAsText();
40
41 var c=document.getElementById("myCanvas");
42 var ctx=c.getContext("2d");
43
44 var yCo = 30;
45 var testFlag = false;
46 var fontFamily = "Arial, san-serif";
47 var fontSize = 20;
48 ctx.font = fontSize + "px " + fontFamily;
49
50 // This will test both Complex and Simple code path
51 var latinString="Sample string \u0009 \u000A \u000D string end";
52 var normalizedLatinString="Sample string \u0020 \u0020 \u0020 string end";
53
54 var HindiString="हिन्दी \u0009 \u000A \u000D हिन्दी ";
55 var normalizedHindiString="हिन्दी \u0020 \u0020 \u0020 हिन्दी ";
56
57 testFlag = compareStrings(latinString, normalizedLatinString, fontSize, ctx, yCo );
58 yCo += fontSize * 4;
59 testFlag = compareStrings(HindiString, normalizedHindiString, fontSize, ctx, yCo );
60 if (testFlag)
61 document.getElementById("console").innerHTML = "TEST PASSED";
62 else
63 document.getElementById("console").innerHTML = "TEST FAILED";
64
65 </script>
66 </body>
67 </html>
OLDNEW
« no previous file with comments | « LayoutTests/TestExpectations ('k') | LayoutTests/fast/canvas/canvas-normalize-string-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698