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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/TestExpectations ('k') | LayoutTests/fast/canvas/canvas-normalize-string-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/fast/canvas/canvas-normalize-string.html
diff --git a/LayoutTests/fast/canvas/canvas-normalize-string.html b/LayoutTests/fast/canvas/canvas-normalize-string.html
new file mode 100644
index 0000000000000000000000000000000000000000..fd1ed62b38aef4cf99334c6a414d670196150ae2
--- /dev/null
+++ b/LayoutTests/fast/canvas/canvas-normalize-string.html
@@ -0,0 +1,67 @@
+<html>
+<head>
+<meta charset="UTF-8" />
+<title>Canvas Normalized String Test</title>
+</head>
+
+<body>
+<p>On success, two same text string with equal width will be rendered.</p>
+<canvas id="myCanvas" width="300px" height="300px" style="border:1px solid #c3c3c3;">
+Your browser does not support the canvas element.
+</canvas>
+<div id="console"></div>
+
+<script type="text/javascript">
+function compareImageData(img1,img2)
+{
+ if(img1.data.length != img2.data.length)
+ return false;
+
+ for(var i = 0; i < img1.data.length; ++i){
+ if(img1.data[i] != img2.data[i])
+ return false;
+ }
+ return true;
+}
+
+function compareStrings(string1, string2, fontSize, ctx, yCo)
+{
+ ctx.fillText(string1, 10, yCo);
+ var imgDataCombinedText = ctx.getImageData(10,yCo-fontSize, ctx.measureText(string1).width,fontSize);
+
+ yCo += fontSize * 2;
+ ctx.fillText(string2, 10, yCo);
+ var imgData = ctx.getImageData(10, yCo-fontSize, ctx.measureText(string2).width,fontSize);
+ return compareImageData(imgDataCombinedText, imgData);
+}
+
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+var c=document.getElementById("myCanvas");
+var ctx=c.getContext("2d");
+
+var yCo = 30;
+var testFlag = false;
+var fontFamily = "Arial, san-serif";
+var fontSize = 20;
+ctx.font = fontSize + "px " + fontFamily;
+
+// This will test both Complex and Simple code path
+var latinString="Sample string \u0009 \u000A \u000D string end";
+var normalizedLatinString="Sample string \u0020 \u0020 \u0020 string end";
+
+var HindiString="हिन्दी \u0009 \u000A \u000D हिन्दी ";
+var normalizedHindiString="हिन्दी \u0020 \u0020 \u0020 हिन्दी ";
+
+testFlag = compareStrings(latinString, normalizedLatinString, fontSize, ctx, yCo);
+yCo += fontSize * 4;
+testFlag = compareStrings(HindiString, normalizedHindiString, fontSize, ctx, yCo);
+if (testFlag)
+ document.getElementById("console").innerHTML = "TEST PASSED";
+else
+ document.getElementById("console").innerHTML = "TEST FAILED";
+
+</script>
+</body>
+</html>
« 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