Fix getBBox for perpendicular paths
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jan 2012 03:16:47 +0000 (03:16 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jan 2012 03:16:47 +0000 (03:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76177

Patch by Philip Rogers <pdr@google.com> 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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105231 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/svg/custom/getBBox-perpendicular-path-expected.txt [new file with mode: 0644]
LayoutTests/svg/custom/getBBox-perpendicular-path.svg [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/FloatRect.cpp
Source/WebCore/platform/graphics/FloatRect.h
Source/WebCore/rendering/svg/SVGRenderSupport.cpp

index 629e151..9e46eae 100644 (file)
@@ -1,3 +1,13 @@
+2012-01-17  Philip Rogers  <pdr@google.com>
+
+        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  <jamesr@chromium.org>
 
         [chromium] Mark some compositing tests as failing with an IMAGE diff due to video playback problem
diff --git a/LayoutTests/svg/custom/getBBox-perpendicular-path-expected.txt b/LayoutTests/svg/custom/getBBox-perpendicular-path-expected.txt
new file mode 100644 (file)
index 0000000..ae7b88f
--- /dev/null
@@ -0,0 +1 @@
+100 100 PASS
diff --git a/LayoutTests/svg/custom/getBBox-perpendicular-path.svg b/LayoutTests/svg/custom/getBBox-perpendicular-path.svg
new file mode 100644 (file)
index 0000000..cf5a8bd
--- /dev/null
@@ -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>
index 9168270..739c477 100644 (file)
@@ -1,3 +1,20 @@
+2012-01-17  Philip Rogers  <pdr@google.com>
+
+        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  <kbr@google.com>
 
         [chromium] Apply color profiles in more cases
index fa9045c..17bd8b1 100644 (file)
@@ -103,12 +103,17 @@ void FloatRect::unite(const FloatRect& other)
         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 @@ void FloatRect::uniteIfNonZero(const FloatRect& other)
         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)
index ae6c23a..1409071 100644 (file)
@@ -152,6 +152,7 @@ public:
 
     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
index bbf84d3..62e8dad 100644 (file)
@@ -167,20 +167,31 @@ void SVGRenderSupport::finishRenderSVGContent(RenderObject* object, PaintInfo& p
 
 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;
     }
 }