Title: [273986] trunk/Source/WebCore
Revision
273986
Author
[email protected]
Date
2021-03-05 11:26:47 -0800 (Fri, 05 Mar 2021)

Log Message

Canvas: drawImage should normalize srcRect before checking if it's empty
https://bugs.webkit.org/show_bug.cgi?id=222774

Reviewed by Dean Jackson.

>From 4.12.5.1.14 Drawing images, step 4:

"The source rectangle is the rectangle whose corners are the four
points (sx, sy), (sx+sw, sy), (sx+sw, sy+sh), (sx, sy+sh)."

When a negative height/width is given, e.g. y:100 and height:-50, it
should be treated like the rect with y:50, height: 50 (i.e. normalized), to
avoid FloatRect:isEmpty returning true.

Covered by existing test:

imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.negativedir.html

* html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::drawImage):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (273985 => 273986)


--- trunk/Source/WebCore/ChangeLog	2021-03-05 19:19:48 UTC (rev 273985)
+++ trunk/Source/WebCore/ChangeLog	2021-03-05 19:26:47 UTC (rev 273986)
@@ -1,3 +1,26 @@
+2021-03-05  Lauro Moura  <[email protected]>
+
+        Canvas: drawImage should normalize srcRect before checking if it's empty
+        https://bugs.webkit.org/show_bug.cgi?id=222774
+
+        Reviewed by Dean Jackson.
+
+        From 4.12.5.1.14 Drawing images, step 4:
+
+        "The source rectangle is the rectangle whose corners are the four
+        points (sx, sy), (sx+sw, sy), (sx+sw, sy+sh), (sx, sy+sh)."
+
+        When a negative height/width is given, e.g. y:100 and height:-50, it
+        should be treated like the rect with y:50, height: 50 (i.e. normalized), to
+        avoid FloatRect:isEmpty returning true.
+
+        Covered by existing test:
+
+        imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.negativedir.html
+
+        * html/canvas/CanvasRenderingContext2DBase.cpp:
+        (WebCore::CanvasRenderingContext2DBase::drawImage):
+
 2021-03-05  Don Olmstead  <[email protected]>
 
         [CMake] Bump cmake_minimum_required version to 3.12 or later

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (273985 => 273986)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp	2021-03-05 19:19:48 UTC (rev 273985)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp	2021-03-05 19:26:47 UTC (rev 273986)
@@ -1687,12 +1687,14 @@
     if (!imageBitmap.width() || !imageBitmap.height())
         return Exception { InvalidStateError };
 
-    if (srcRect.isEmpty())
+    auto normalizedSrcRect = normalizeRect(srcRect);
+
+    if (normalizedSrcRect.isEmpty())
         return { };
 
     FloatRect srcBitmapRect = FloatRect(FloatPoint(), FloatSize(imageBitmap.width(), imageBitmap.height()));
 
-    if (!srcBitmapRect.contains(normalizeRect(srcRect)) || !dstRect.width() || !dstRect.height())
+    if (!srcBitmapRect.contains(normalizedSrcRect) || !dstRect.width() || !dstRect.height())
         return { };
 
     GraphicsContext* c = drawingContext();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to