Title: [105231] trunk
Revision
105231
Author
[email protected]
Date
2012-01-17 19:16:47 -0800 (Tue, 17 Jan 2012)

Log Message

Fix getBBox for perpendicular paths
https://bugs.webkit.org/show_bug.cgi?id=76177

Patch by Philip Rogers <[email protected]> on 2012-01-17
Reviewed by Darin Adler.

Source/WebCore:

Test: svg/custom/getBBox-perpendicular-path.svg

* platform/graphics/FloatRect.cpp:
(WebCore::FloatRect::unite):
(WebCore::FloatRect::uniteEvenIfEmpty):
(WebCore::FloatRect::uniteIfNonZero):
* platform/graphics/FloatRect.h:
* rendering/svg/SVGRenderSupport.cpp:
(WebCore::SVGRenderSupport::computeContainerBoundingBoxes):

LayoutTests:

* svg/custom/getBBox-perpendicular-path-expected.txt: Added.
* svg/custom/getBBox-perpendicular-path.svg: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (105230 => 105231)


--- trunk/LayoutTests/ChangeLog	2012-01-18 03:09:16 UTC (rev 105230)
+++ trunk/LayoutTests/ChangeLog	2012-01-18 03:16:47 UTC (rev 105231)
@@ -1,3 +1,13 @@
+2012-01-17  Philip Rogers  <[email protected]>
+
+        Fix getBBox for perpendicular paths
+        https://bugs.webkit.org/show_bug.cgi?id=76177
+
+        Reviewed by Darin Adler.
+
+        * svg/custom/getBBox-perpendicular-path-expected.txt: Added.
+        * svg/custom/getBBox-perpendicular-path.svg: Added.
+
 2012-01-17  James Robinson  <[email protected]>
 
         [chromium] Mark some compositing tests as failing with an IMAGE diff due to video playback problem

Added: trunk/LayoutTests/svg/custom/getBBox-perpendicular-path-expected.txt (0 => 105231)


--- trunk/LayoutTests/svg/custom/getBBox-perpendicular-path-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/svg/custom/getBBox-perpendicular-path-expected.txt	2012-01-18 03:16:47 UTC (rev 105231)
@@ -0,0 +1 @@
+100 100 PASS

Added: trunk/LayoutTests/svg/custom/getBBox-perpendicular-path.svg (0 => 105231)


--- trunk/LayoutTests/svg/custom/getBBox-perpendicular-path.svg	                        (rev 0)
+++ trunk/LayoutTests/svg/custom/getBBox-perpendicular-path.svg	2012-01-18 03:16:47 UTC (rev 105231)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Test the bounding box calculated for two perpendicular lines of length 100px -->
+<!-- If the bounding box is 100x100, we consider this test passing. -->
+<svg xmlns="http://www.w3.org/2000/svg" _onload_="init()">
+  <script type="text/_javascript_">
+  <![CDATA[
+    function init()
+    {
+        if (window.layoutTestController)
+            layoutTestController.dumpAsText();
+        var txt = document.getElementById("text");
+        size = document.getElementById("shape").getBBox();
+        var passState = "FAIL";
+        if(size.width == 100 && size.height == 100)
+            passState = "PASS";
+        var textNode = document.createTextNode(size.width + " " + size.height + " " + passState);
+        txt.appendChild(textNode);
+    }
+  ]]>
+  </script>
+  <g id="shape">
+    <path stroke="#666666" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="M5 5L5 105" fill-rule="nonzero"></path>
+    <path stroke="#666666" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="M5 5L105 5" fill-rule="nonzero"></path>
+  </g>
+  <text id="text" x="50" y="50" />
+</svg>

Modified: trunk/Source/WebCore/ChangeLog (105230 => 105231)


--- trunk/Source/WebCore/ChangeLog	2012-01-18 03:09:16 UTC (rev 105230)
+++ trunk/Source/WebCore/ChangeLog	2012-01-18 03:16:47 UTC (rev 105231)
@@ -1,3 +1,20 @@
+2012-01-17  Philip Rogers  <[email protected]>
+
+        Fix getBBox for perpendicular paths
+        https://bugs.webkit.org/show_bug.cgi?id=76177
+
+        Reviewed by Darin Adler.
+
+        Test: svg/custom/getBBox-perpendicular-path.svg
+
+        * platform/graphics/FloatRect.cpp:
+        (WebCore::FloatRect::unite):
+        (WebCore::FloatRect::uniteEvenIfEmpty):
+        (WebCore::FloatRect::uniteIfNonZero):
+        * platform/graphics/FloatRect.h:
+        * rendering/svg/SVGRenderSupport.cpp:
+        (WebCore::SVGRenderSupport::computeContainerBoundingBoxes):
+
 2012-01-17  Kenneth Russell  <[email protected]>
 
         [chromium] Apply color profiles in more cases

Modified: trunk/Source/WebCore/platform/graphics/FloatRect.cpp (105230 => 105231)


--- trunk/Source/WebCore/platform/graphics/FloatRect.cpp	2012-01-18 03:09:16 UTC (rev 105230)
+++ trunk/Source/WebCore/platform/graphics/FloatRect.cpp	2012-01-18 03:16:47 UTC (rev 105231)
@@ -103,12 +103,17 @@
         return;
     }
 
-    float l = min(x(), other.x());
-    float t = min(y(), other.y());
-    float r = max(maxX(), other.maxX());
-    float b = max(maxY(), other.maxY());
+    uniteEvenIfEmpty(other);
+}
 
-    setLocationAndSizeFromEdges(l, t, r, b);
+void FloatRect::uniteEvenIfEmpty(const FloatRect& other)
+{
+    float minX = min(x(), other.x());
+    float minY = min(y(), other.y());
+    float maxX = max(this->maxX(), other.maxX());
+    float maxY = max(this->maxY(), other.maxY());
+
+    setLocationAndSizeFromEdges(minX, minY, maxX, maxY);
 }
 
 void FloatRect::uniteIfNonZero(const FloatRect& other)
@@ -121,12 +126,7 @@
         return;
     }
 
-    float left = min(x(), other.x());
-    float top = min(y(), other.y());
-    float right = max(maxX(), other.maxX());
-    float bottom = max(maxY(), other.maxY());
-
-    setLocationAndSizeFromEdges(left, top, right, bottom);
+    uniteEvenIfEmpty(other);
 }
 
 void FloatRect::scale(float sx, float sy)

Modified: trunk/Source/WebCore/platform/graphics/FloatRect.h (105230 => 105231)


--- trunk/Source/WebCore/platform/graphics/FloatRect.h	2012-01-18 03:09:16 UTC (rev 105230)
+++ trunk/Source/WebCore/platform/graphics/FloatRect.h	2012-01-18 03:16:47 UTC (rev 105231)
@@ -152,6 +152,7 @@
 
     void intersect(const FloatRect&);
     void unite(const FloatRect&);
+    void uniteEvenIfEmpty(const FloatRect&);
     void uniteIfNonZero(const FloatRect&);
 
     // Note, this doesn't match what IntRect::contains(IntPoint&) does; the int version

Modified: trunk/Source/WebCore/rendering/svg/SVGRenderSupport.cpp (105230 => 105231)


--- trunk/Source/WebCore/rendering/svg/SVGRenderSupport.cpp	2012-01-18 03:09:16 UTC (rev 105230)
+++ trunk/Source/WebCore/rendering/svg/SVGRenderSupport.cpp	2012-01-18 03:16:47 UTC (rev 105231)
@@ -167,20 +167,31 @@
 
 void SVGRenderSupport::computeContainerBoundingBoxes(const RenderObject* container, FloatRect& objectBoundingBox, FloatRect& strokeBoundingBox, FloatRect& repaintBoundingBox)
 {
+    bool isFirstChild = true;
+
     for (RenderObject* current = container->firstChild(); current; current = current->nextSibling()) {
         if (current->isSVGHiddenContainer())
             continue;
 
         const AffineTransform& transform = current->localToParentTransform();
         if (transform.isIdentity()) {
-            objectBoundingBox.unite(current->objectBoundingBox());
+            if (isFirstChild)
+                objectBoundingBox = current->objectBoundingBox();
+            else
+                objectBoundingBox.uniteEvenIfEmpty(current->objectBoundingBox());
             strokeBoundingBox.unite(current->strokeBoundingBox());
             repaintBoundingBox.unite(current->repaintRectInLocalCoordinates());
         } else {
-            objectBoundingBox.unite(transform.mapRect(current->objectBoundingBox()));
+            if (isFirstChild)
+                objectBoundingBox = transform.mapRect(current->objectBoundingBox());
+            else
+                objectBoundingBox.uniteEvenIfEmpty(transform.mapRect(current->objectBoundingBox()));
             strokeBoundingBox.unite(transform.mapRect(current->strokeBoundingBox()));
             repaintBoundingBox.unite(transform.mapRect(current->repaintRectInLocalCoordinates()));
         }
+
+        if (isFirstChild)
+            isFirstChild = false;
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to