Bug 1090916 - Ignore SVG rect radii and calculate the bounds of rounded rects using Math when we have a rectilinear transform. r=longsonr
authorJonathan Watt <jwatt@jwatt.org>
Wed, 29 Oct 2014 17:07:11 +0000
changeset 212994 a492a219b80b5d0c5d7cc703f6ed4c95028061bf
parent 212993 18daec980bedf477d8d6ea1c560e3469f78ca15e
child 212995 33b93eb7e383198b49a04e026797f7eb08d5bace
push id27738
push usercbook@mozilla.com
push dateThu, 30 Oct 2014 13:46:07 +0000
treeherdermozilla-central@1aa1b23d799e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr
bugs1090916
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1090916 - Ignore SVG rect radii and calculate the bounds of rounded rects using Math when we have a rectilinear transform. r=longsonr
dom/svg/SVGRectElement.cpp
--- a/dom/svg/SVGRectElement.cpp
+++ b/dom/svg/SVGRectElement.cpp
@@ -109,39 +109,43 @@ SVGRectElement::GetLengthInfo()
 
 //----------------------------------------------------------------------
 // nsSVGPathGeometryElement methods
 
 bool
 SVGRectElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
                                   const Matrix& aTransform)
 {
-  Rect r;
+  Rect rect;
   Float rx, ry;
-  GetAnimatedLengthValues(&r.x, &r.y, &r.width, &r.height, &rx, &ry, nullptr);
+  GetAnimatedLengthValues(&rect.x, &rect.y, &rect.width,
+                          &rect.height, &rx, &ry, nullptr);
 
-  if (r.IsEmpty()) {
+  if (rect.IsEmpty()) {
     // Rendering of the element disabled
-    r.SetEmpty(); // make sure width/height are actually zero
-    *aBounds = r;
+    rect.SetEmpty(); // Make sure width/height are zero and not negative
+    *aBounds = rect; // We still want the x/y position from 'rect'
     return true;
   }
 
-  rx = std::max(rx, 0.0f);
-  ry = std::max(ry, 0.0f);
+  if (!aTransform.IsRectilinear()) {
+    // We can't ignore the radii in this case if we want tight bounds
+    rx = std::max(rx, 0.0f);
+    ry = std::max(ry, 0.0f);
 
-  if (rx != 0 || ry != 0) {
-    return false;
+    if (rx != 0 || ry != 0) {
+      return false;
+    }
   }
 
   if (aStrokeWidth > 0.f) {
-    r.Inflate(aStrokeWidth / 2.f);
+    rect.Inflate(aStrokeWidth / 2.f);
   }
 
-  *aBounds = aTransform.TransformBounds(r);
+  *aBounds = aTransform.TransformBounds(rect);
   return true;
 }
 
 void
 SVGRectElement::GetAsSimplePath(SimplePath* aSimplePath)
 {
   float x, y, width, height, rx, ry;
   GetAnimatedLengthValues(&x, &y, &width, &height, &rx, &ry, nullptr);