Bug 87859

Summary: Bug: Negative SVG rect rx,ry corner radii values aren't handled correctly
Product: WebKit Reporter: Hans Muller <giles_joplin>
Component: SVGAssignee: Hans Muller <giles_joplin>
Status: RESOLVED FIXED    
Severity: Normal CC: eric, rwlbuis, webkit.review.bot, zimmermann
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
HTML file contains failing SVG rect negative rx,ry test cases
none
Screenshot of the failing test cases.
none
Patch
none
Patch
none
Patch none

Hans Muller
Reported 2012-05-30 09:11:35 PDT
Created attachment 144834 [details] HTML file contains failing SVG rect negative rx,ry test cases The SVG specification says that negative values for rx,ry "rect" corner radii aren't allowed and that if "if neither rx nor ry are properly specified, then set both rx and ry to 0. (This will result in square corners.)" - http://www.w3.org/TR/SVG/shapes.html#RectElement. Similarly, if only one of rx,ry is negative then the other attribute (default 0) should be used for both. The current implementation fails in all three cases: <rect x="100" y="100" width="200" height="100" rx="-90" ry="-40"/> <rect x="100" y="100" width="200" height="100" rx="-90" ry="40"/> <rect x="100" y="100" width="200" height="100" rx="90" ry="-40"/>
Attachments
HTML file contains failing SVG rect negative rx,ry test cases (1.37 KB, text/html)
2012-05-30 09:11 PDT, Hans Muller
no flags
Screenshot of the failing test cases. (39.63 KB, image/jpeg)
2012-05-30 09:14 PDT, Hans Muller
no flags
Patch (4.90 KB, patch)
2012-05-31 09:57 PDT, Rob Buis
no flags
Patch (5.23 KB, patch)
2012-05-31 14:53 PDT, Hans Muller
no flags
Patch (5.16 KB, patch)
2012-05-31 16:01 PDT, Hans Muller
no flags
Hans Muller
Comment 1 2012-05-30 09:14:38 PDT
Created attachment 144836 [details] Screenshot of the failing test cases.
Rob Buis
Comment 2 2012-05-31 09:57:45 PDT
Hans Muller
Comment 3 2012-05-31 10:23:19 PDT
I'd assigned the bug to myself because I had a fix for it. I'd put the changes in Path::addRoundedRect(), where the other checks for the corner constraints from the SVG spec are already.
Hans Muller
Comment 4 2012-05-31 10:40:43 PDT
Not to put too fine a point on it, but here's the updated version of addRoundedRect(). I'd merged the original comments about the SVG spec with a new one. void Path::addRoundedRect(const FloatRect& rect, const FloatSize& roundingRadii, RoundedRectStrategy strategy) { if (rect.isEmpty()) return; FloatSize radius(roundingRadii); FloatSize halfSize(rect.width() / 2, rect.height() / 2); // Apply the SVG corner radius constraints, per the rect section of the SVG shapes spec: if // one of rx,ry is negative, then the other corner radius value is used. If both values are // negative then rx = ry = 0. If rx is greater than half of the width of the rectangle // then set rx to half of the width; ry is handled similarly. if (radius.width() < 0) radius.setWidth((radius.height() < 0) ? 0 : radius.height()); if (radius.height() < 0) radius.setHeight(radius.width()); if (radius.width() > halfSize.width()) radius.setWidth(halfSize.width()); if (radius.height() > halfSize.height()) radius.setHeight(halfSize.height()); addPathForRoundedRect(rect, radius, radius, radius, radius, strategy); }
Rob Buis
Comment 5 2012-05-31 10:50:49 PDT
Hi, (In reply to comment #3) > I'd assigned the bug to myself because I had a fix for it. I'd put the changes in Path::addRoundedRect(), where the other checks for the corner constraints from the SVG spec are already. I am sorry, totally missed the assigned! We are still discussing on IRC what is the best place to fix this.
Hans Muller
Comment 6 2012-05-31 14:53:20 PDT
Hans Muller
Comment 7 2012-05-31 14:56:25 PDT
I've uploaded a revised patch per the krit,rbuis IRC discussion. The reftest is essentially the same as the one Rob provided, modulo a little gratuitous reformatting.
Dirk Schulze
Comment 8 2012-05-31 15:57:28 PDT
Comment on attachment 145163 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=145163&action=review Looks good to me. Just snippets to get r+. > LayoutTests/svg/custom/rect-negative-corner-radii-expected.svg:2 > +<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.0" width="500" height="500"> xmlns:svg="http://www.w3.org/2000/svg" Is unnecessary. > LayoutTests/svg/custom/rect-negative-corner-radii.svg:2 > +<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.0" width="500" height="500"> Ditto.
Hans Muller
Comment 9 2012-05-31 16:01:42 PDT
Hans Muller
Comment 10 2012-05-31 16:02:20 PDT
Removed redundant namespace attributes from the reftest.
WebKit Review Bot
Comment 11 2012-05-31 17:59:58 PDT
Comment on attachment 145170 [details] Patch Clearing flags on attachment: 145170 Committed r119182: <http://trac.webkit.org/changeset/119182>
WebKit Review Bot
Comment 12 2012-05-31 18:00:03 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.