Title: [142754] trunk
Revision
142754
Author
[email protected]
Date
2013-02-13 09:01:31 -0800 (Wed, 13 Feb 2013)

Log Message

The 2D Canvas functions fillText()/strokeText() should display nothing when maxWidth is less then or equal to zero
https://bugs.webkit.org/show_bug.cgi?id=102656

Patch by Rashmi Shyamasundar <[email protected]> on 2013-02-13
Reviewed by Dirk Schulze.

The functions fillText()/strokeText() should not display anything when
maxWidth is less than or equal to zero, according to spec :
http://www.w3.org/TR/2dcontext/#text-preparation-algorithm

Source/WebCore:

Test: fast/canvas/canvas-fillText-maxWidth-zero.html

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawTextInternal):

LayoutTests:

* fast/canvas/canvas-fillText-invalid-maxWidth-expected.txt: Added.
* fast/canvas/canvas-fillText-invalid-maxWidth.html: Added.
* fast/canvas/canvas-strokeText-invalid-maxWidth-expected.txt: Added.
* fast/canvas/canvas-strokeText-invalid-maxWidth.html: Added.
* fast/canvas/script-tests/canvas-fillText-invalid-maxWidth.js: Added.
* fast/canvas/script-tests/canvas-strokeText-invalid-maxWidth.js: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (142753 => 142754)


--- trunk/LayoutTests/ChangeLog	2013-02-13 16:47:11 UTC (rev 142753)
+++ trunk/LayoutTests/ChangeLog	2013-02-13 17:01:31 UTC (rev 142754)
@@ -1,3 +1,21 @@
+2013-02-13  Rashmi Shyamasundar  <[email protected]>
+
+        The 2D Canvas functions fillText()/strokeText() should display nothing when maxWidth is less then or equal to zero
+        https://bugs.webkit.org/show_bug.cgi?id=102656
+
+        Reviewed by Dirk Schulze.
+
+        The functions fillText()/strokeText() should not display anything when 
+        maxWidth is less than or equal to zero, according to spec :
+        http://www.w3.org/TR/2dcontext/#text-preparation-algorithm
+
+        * fast/canvas/canvas-fillText-invalid-maxWidth-expected.txt: Added.
+        * fast/canvas/canvas-fillText-invalid-maxWidth.html: Added.
+        * fast/canvas/canvas-strokeText-invalid-maxWidth-expected.txt: Added.
+        * fast/canvas/canvas-strokeText-invalid-maxWidth.html: Added.
+        * fast/canvas/script-tests/canvas-fillText-invalid-maxWidth.js: Added.
+        * fast/canvas/script-tests/canvas-strokeText-invalid-maxWidth.js: Added.
+
 2013-02-13  Sergio Villar Senin  <[email protected]>
 
         Unreviewed GTK gardening.

Added: trunk/LayoutTests/fast/canvas/canvas-fillText-invalid-maxWidth-expected.txt (0 => 142754)


--- trunk/LayoutTests/fast/canvas/canvas-fillText-invalid-maxWidth-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-fillText-invalid-maxWidth-expected.txt	2013-02-13 17:01:31 UTC (rev 142754)
@@ -0,0 +1,11 @@
+Series of tests to ensure that fillText() does not display any text when maxWidth is invalid.
+
+On success, you will see no "FAIL" messages, followed by "TEST COMPLETE".
+
+
+Test canvas.fillText() with maxWidth zero
+Test canvas.fillText() with maxWidth -1
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/canvas/canvas-fillText-invalid-maxWidth.html (0 => 142754)


--- trunk/LayoutTests/fast/canvas/canvas-fillText-invalid-maxWidth.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-fillText-invalid-maxWidth.html	2013-02-13 17:01:31 UTC (rev 142754)
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>
+

Added: trunk/LayoutTests/fast/canvas/canvas-strokeText-invalid-maxWidth-expected.txt (0 => 142754)


--- trunk/LayoutTests/fast/canvas/canvas-strokeText-invalid-maxWidth-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-strokeText-invalid-maxWidth-expected.txt	2013-02-13 17:01:31 UTC (rev 142754)
@@ -0,0 +1,11 @@
+Series of tests to ensure that strokeText() does not display any text when maxWidth is invalid.
+
+On success, you will see no "FAIL" messages, followed by "TEST COMPLETE".
+
+
+Test canvas.strokeText() with maxWidth zero
+Test canvas.strokeText() with maxWidth -1
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/canvas/canvas-strokeText-invalid-maxWidth.html (0 => 142754)


--- trunk/LayoutTests/fast/canvas/canvas-strokeText-invalid-maxWidth.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-strokeText-invalid-maxWidth.html	2013-02-13 17:01:31 UTC (rev 142754)
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>
+

Added: trunk/LayoutTests/fast/canvas/script-tests/canvas-fillText-invalid-maxWidth.js (0 => 142754)


--- trunk/LayoutTests/fast/canvas/script-tests/canvas-fillText-invalid-maxWidth.js	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/script-tests/canvas-fillText-invalid-maxWidth.js	2013-02-13 17:01:31 UTC (rev 142754)
@@ -0,0 +1,46 @@
+descriptionQuiet("Series of tests to ensure that fillText() does not display any text when maxWidth is invalid.");
+
+var canvas = document.createElement('canvas');
+var ctx = canvas.getContext('2d');
+var canvasWidth = 100;
+var canvasHeight = 50;
+canvas.setWidth = canvasWidth;
+canvas.setHeight = canvasHeight;
+
+
+ctx.fillStyle = '#0f0';
+ctx.fillRect(0, 0, canvasWidth, canvasHeight);
+ctx.font = '35px Arial, sans-serif';
+
+debug("Test canvas.fillText() with maxWidth zero");
+ctx.fillStyle = '#f00';
+ctx.fillText("fail fail fail fail fail", 5, 35, 0);
+
+var imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
+var w = imageData.width, h = imageData.height, d = imageData.data;
+for (var i = 0; i < h; ++i) {
+    for (var j = 0; j < w; ++j) {
+        if (d[4 * (w * i + j) + 0] != 0) shouldBe("d[4 * (w * i + j) + 0]", "0"); 
+        if (d[4 * (w * i + j) + 1] != 255) shouldBe("d[4 * (w * i + j) + 1]", "255"); 
+        if (d[4 * (w * i + j) + 2] != 0) shouldBe("d[4 * (w * i + j) + 2]", "0"); 
+        if (d[4 * (w * i + j) + 3] != 255) shouldBe("d[4 * (w * i + j) + 3]", "255");
+    }
+}
+
+ctx.fillStyle = '#0f0';
+ctx.fillRect(0, 0, canvasWidth, canvasHeight);
+debug("Test canvas.fillText() with maxWidth -1");
+ctx.fillStyle = '#f00';
+ctx.fillText("fail fail fail fail fail", 5, 35, -1);
+
+var imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
+var w = imageData.width, h = imageData.height, d = imageData.data;
+for (var i = 0; i < h; ++i) {
+    for (var j = 0; j < w; ++j) {
+        if (d[4 * (w * i + j) + 0] != 0) shouldBe("d[4 * (w * i + j) + 0]", "0"); 
+        if (d[4 * (w * i + j) + 1] != 255) shouldBe("d[4 * (w * i + j) + 1]", "255"); 
+        if (d[4 * (w * i + j) + 2] != 0) shouldBe("d[4 * (w * i + j) + 2]", "0"); 
+        if (d[4 * (w * i + j) + 3] != 255) shouldBe("d[4 * (w * i + j) + 3]", "255");
+    }
+}
+

Added: trunk/LayoutTests/fast/canvas/script-tests/canvas-strokeText-invalid-maxWidth.js (0 => 142754)


--- trunk/LayoutTests/fast/canvas/script-tests/canvas-strokeText-invalid-maxWidth.js	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/script-tests/canvas-strokeText-invalid-maxWidth.js	2013-02-13 17:01:31 UTC (rev 142754)
@@ -0,0 +1,46 @@
+descriptionQuiet("Series of tests to ensure that strokeText() does not display any text when maxWidth is invalid.");
+
+var canvas = document.createElement('canvas');
+var ctx = canvas.getContext('2d');
+var canvasWidth = 100;
+var canvasHeight = 50;
+canvas.setWidth = canvasWidth;
+canvas.setHeight = canvasHeight;
+
+
+ctx.fillStyle = '#0f0';
+ctx.fillRect(0, 0, canvasWidth, canvasHeight);
+ctx.font = '35px Arial, sans-serif';
+
+debug("Test canvas.strokeText() with maxWidth zero");
+ctx.strokeStyle = '#f00';
+ctx.strokeText("fail fail fail fail fail", 5, 35, 0);
+
+var imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
+var w = imageData.width, h = imageData.height, d = imageData.data;
+for (var i = 0; i < h; ++i) {
+    for (var j = 0; j < w; ++j) {
+        if (d[4 * (w * i + j) + 0] != 0) shouldBe("d[4 * (w * i + j) + 0]", "0"); 
+        if (d[4 * (w * i + j) + 1] != 255) shouldBe("d[4 * (w * i + j) + 1]", "255"); 
+        if (d[4 * (w * i + j) + 2] != 0) shouldBe("d[4 * (w * i + j) + 2]", "0"); 
+        if (d[4 * (w * i + j) + 3] != 255) shouldBe("d[4 * (w * i + j) + 3]", "255");
+    }
+}
+
+ctx.fillStyle = '#0f0';
+ctx.fillRect(0, 0, canvasWidth, canvasHeight);
+debug("Test canvas.strokeText() with maxWidth -1");
+ctx.strokeStyle = '#f00';
+ctx.strokeText("fail fail fail fail fail", 5, 35, -1);
+
+var imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
+var w = imageData.width, h = imageData.height, d = imageData.data;
+for (var i = 0; i < h; ++i) {
+    for (var j = 0; j < w; ++j) {
+        if (d[4 * (w * i + j) + 0] != 0) shouldBe("d[4 * (w * i + j) + 0]", "0"); 
+        if (d[4 * (w * i + j) + 1] != 255) shouldBe("d[4 * (w * i + j) + 1]", "255"); 
+        if (d[4 * (w * i + j) + 2] != 0) shouldBe("d[4 * (w * i + j) + 2]", "0"); 
+        if (d[4 * (w * i + j) + 3] != 255) shouldBe("d[4 * (w * i + j) + 3]", "255");
+    }
+}
+

Modified: trunk/Source/WebCore/ChangeLog (142753 => 142754)


--- trunk/Source/WebCore/ChangeLog	2013-02-13 16:47:11 UTC (rev 142753)
+++ trunk/Source/WebCore/ChangeLog	2013-02-13 17:01:31 UTC (rev 142754)
@@ -1,3 +1,19 @@
+2013-02-13  Rashmi Shyamasundar  <[email protected]>
+
+        The 2D Canvas functions fillText()/strokeText() should display nothing when maxWidth is less then or equal to zero
+        https://bugs.webkit.org/show_bug.cgi?id=102656
+
+        Reviewed by Dirk Schulze.
+
+        The functions fillText()/strokeText() should not display anything when 
+        maxWidth is less than or equal to zero, according to spec :
+        http://www.w3.org/TR/2dcontext/#text-preparation-algorithm
+
+        Test: fast/canvas/canvas-fillText-maxWidth-zero.html
+
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::drawTextInternal):
+
 2013-02-13  ChangSeok Oh  <[email protected]>
 
         [GTK][AC] Implement basic transform animations with clutter ac backend

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (142753 => 142754)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2013-02-13 16:47:11 UTC (rev 142753)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2013-02-13 17:01:31 UTC (rev 142754)
@@ -2175,7 +2175,7 @@
         return;
     if (!isfinite(x) | !isfinite(y))
         return;
-    if (useMaxWidth && !isfinite(maxWidth))
+    if (useMaxWidth && (!isfinite(maxWidth) || maxWidth <= 0))
         return;
 
     // If gradient size is zero, then paint nothing.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to