- Revision
- 166746
- Author
- k...@webkit.org
- Date
- 2014-04-03 14:44:54 -0700 (Thu, 03 Apr 2014)
Log Message
[CG] Canvas lineDashOffset does not handle negative numbers correctly
https://bugs.webkit.org/show_bug.cgi?id=80560
Reviewed by Dean Jackson.
Source/WebCore:
CG ignores negative dash array offsets. Check if we have a negative offset, if yes
then calculate the length of the dash array and modulo the dash array offset with
the dash array length.
Test: fast/canvas/canvas-negative-lineDashOffset.html
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::setLineDash):
LayoutTests:
Test correct rendering of negative offset for Canvas dash arrays.
* fast/canvas/canvas-negative-lineDashOffset-expected.txt: Added.
* fast/canvas/canvas-negative-lineDashOffset.html: Added.
* fast/canvas/script-tests/canvas-negative-lineDashOffset.js: Added.
(dataToArray):
(getPixel):
(pixelShouldBe):
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (166745 => 166746)
--- trunk/LayoutTests/ChangeLog 2014-04-03 21:40:49 UTC (rev 166745)
+++ trunk/LayoutTests/ChangeLog 2014-04-03 21:44:54 UTC (rev 166746)
@@ -1,3 +1,19 @@
+2014-04-03 Dirk Schulze <k...@webkit.org>
+
+ [CG] Canvas lineDashOffset does not handle negative numbers correctly
+ https://bugs.webkit.org/show_bug.cgi?id=80560
+
+ Reviewed by Dean Jackson.
+
+ Test correct rendering of negative offset for Canvas dash arrays.
+
+ * fast/canvas/canvas-negative-lineDashOffset-expected.txt: Added.
+ * fast/canvas/canvas-negative-lineDashOffset.html: Added.
+ * fast/canvas/script-tests/canvas-negative-lineDashOffset.js: Added.
+ (dataToArray):
+ (getPixel):
+ (pixelShouldBe):
+
2014-04-03 David Hyatt <hy...@apple.com>
Continuations casting issue.
Added: trunk/LayoutTests/fast/canvas/canvas-negative-lineDashOffset-expected.txt (0 => 166746)
--- trunk/LayoutTests/fast/canvas/canvas-negative-lineDashOffset-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-negative-lineDashOffset-expected.txt 2014-04-03 21:44:54 UTC (rev 166746)
@@ -0,0 +1,12 @@
+Test negative values for lineDashOffset
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS ctx.lineDashOffset is -100
+PASS getPixel(50,100) is [0,0,0,0]
+PASS getPixel(150,100) is [0,255,0,255]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/canvas/canvas-negative-lineDashOffset.html (0 => 166746)
--- trunk/LayoutTests/fast/canvas/canvas-negative-lineDashOffset.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-negative-lineDashOffset.html 2014-04-03 21:44:54 UTC (rev 166746)
@@ -0,0 +1,10 @@
+<!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-negative-lineDashOffset.js (0 => 166746)
--- trunk/LayoutTests/fast/canvas/script-tests/canvas-negative-lineDashOffset.js (rev 0)
+++ trunk/LayoutTests/fast/canvas/script-tests/canvas-negative-lineDashOffset.js 2014-04-03 21:44:54 UTC (rev 166746)
@@ -0,0 +1,39 @@
+description("Test negative values for lineDashOffset");
+
+var canvas = document.createElement('canvas');
+document.body.appendChild(canvas);
+canvas.setAttribute('width', '200');
+canvas.setAttribute('height', '200');
+var ctx = canvas.getContext('2d');
+
+ctx.lineWidth = 200;
+ctx.setLineDash([100,100]);
+ctx.strokeStyle = "rgb(0,255,0)";
+ctx.moveTo(0,100);
+ctx.lineTo(200,100);
+ctx.lineDashOffset = -100;
+ctx.stroke();
+
+// Verify value.
+shouldBe('ctx.lineDashOffset', '-100');
+
+function dataToArray(data) {
+ var result = new Array(data.length)
+ for (var i = 0; i < data.length; i++)
+ result[i] = data[i];
+ return result;
+}
+
+function getPixel(x, y) {
+ var data = ""
+ if (!data) // getImageData failed, which should never happen
+ return [-1,-1,-1,-1];
+ return dataToArray(data.data);
+}
+
+function pixelShouldBe(x, y, colour) {
+ shouldBe("getPixel(" + [x, y] +")", "["+colour+"]");
+}
+
+pixelShouldBe(50,100,[0,0,0,0]);
+pixelShouldBe(150,100,[0,255,0,255]);
\ No newline at end of file
Modified: trunk/Source/WebCore/ChangeLog (166745 => 166746)
--- trunk/Source/WebCore/ChangeLog 2014-04-03 21:40:49 UTC (rev 166745)
+++ trunk/Source/WebCore/ChangeLog 2014-04-03 21:44:54 UTC (rev 166746)
@@ -1,3 +1,19 @@
+2014-04-03 Dirk Schulze <k...@webkit.org>
+
+ [CG] Canvas lineDashOffset does not handle negative numbers correctly
+ https://bugs.webkit.org/show_bug.cgi?id=80560
+
+ Reviewed by Dean Jackson.
+
+ CG ignores negative dash array offsets. Check if we have a negative offset, if yes
+ then calculate the length of the dash array and modulo the dash array offset with
+ the dash array length.
+
+ Test: fast/canvas/canvas-negative-lineDashOffset.html
+
+ * platform/graphics/cg/GraphicsContextCG.cpp:
+ (WebCore::GraphicsContext::setLineDash):
+
2014-04-03 David Hyatt <hy...@apple.com>
REGRESSION: fast/css/relative-positioned-block-nested-with-inline-parent-multiple-descendant-blocks-dynamic.html broken
Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (166745 => 166746)
--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp 2014-04-03 21:40:49 UTC (rev 166745)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp 2014-04-03 21:44:54 UTC (rev 166746)
@@ -1183,6 +1183,13 @@
void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset)
{
+ if (dashOffset < 0) {
+ float length = 0;
+ for (size_t i = 0; i < dashes.size(); ++i)
+ length += static_cast<float>(dashes[i]);
+ if (length)
+ dashOffset = fmod(dashOffset, length) + length;
+ }
CGContextSetLineDash(platformContext(), dashOffset, dashes.data(), dashes.size());
}