Skip to content

Commit

Permalink
[svg] applying rx or ry through CSS exclusively has no effect
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259646
rdar://113500023

Reviewed by Said Abou-Hallawa.

We should not be checking the XML attribute values for `rx` and `ry`
to determine whether a <rect> is rounded, but instead go through the
`SVGRenderStyle` which will the attribute values reflected as well as
account for the CSS properties.

* LayoutTests/imported/w3c/web-platform-tests/svg/shapes/rect-rx-set-by-css-expected.svg: Added.
* LayoutTests/imported/w3c/web-platform-tests/svg/shapes/rect-rx-set-by-css-ref.svg: Added.
* LayoutTests/imported/w3c/web-platform-tests/svg/shapes/rect-rx-set-by-css.svg: Added.
* Source/WebCore/rendering/svg/RenderSVGRect.cpp:
(WebCore::RenderSVGRect::updateShapeFromElement):
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGRect.cpp:
(WebCore::LegacyRenderSVGRect::updateShapeFromElement):

Canonical link: https://commits.webkit.org/271970@main
  • Loading branch information
graouts committed Dec 13, 2023
1 parent f902162 commit 0eba4b6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions Source/WebCore/rendering/svg/RenderSVGRect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ void RenderSVGRect::updateShapeFromElement()
if (boundingBoxSize.isEmpty())
return;

if (rectElement().rx().value(lengthContext) > 0 || rectElement().ry().value(lengthContext) > 0)
auto& svgStyle = style().svgStyle();
if (lengthContext.valueForLength(svgStyle.rx(), SVGLengthMode::Width) > 0
|| lengthContext.valueForLength(svgStyle.ry(), SVGLengthMode::Height) > 0)
m_shapeType = ShapeType::RoundedRectangle;
else
m_shapeType = ShapeType::Rectangle;
Expand All @@ -79,17 +81,17 @@ void RenderSVGRect::updateShapeFromElement()
return;
}

m_fillBoundingBox = FloatRect(FloatPoint(lengthContext.valueForLength(style().svgStyle().x(), SVGLengthMode::Width),
lengthContext.valueForLength(style().svgStyle().y(), SVGLengthMode::Height)),
m_fillBoundingBox = FloatRect(FloatPoint(lengthContext.valueForLength(svgStyle.x(), SVGLengthMode::Width),
lengthContext.valueForLength(svgStyle.y(), SVGLengthMode::Height)),
boundingBoxSize);

auto strokeBoundingBox = m_fillBoundingBox;
if (style().svgStyle().hasStroke())
if (svgStyle.hasStroke())
strokeBoundingBox.inflate(this->strokeWidth() / 2);

#if USE(CG)
// CoreGraphics can inflate the stroke by 1px when drawing a rectangle with antialiasing disabled at non-integer coordinates, we need to compensate.
if (style().svgStyle().shapeRendering() == ShapeRendering::CrispEdges)
if (svgStyle.shapeRendering() == ShapeRendering::CrispEdges)
strokeBoundingBox.inflate(1);
#endif

Expand Down
12 changes: 7 additions & 5 deletions Source/WebCore/rendering/svg/legacy/LegacyRenderSVGRect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ void LegacyRenderSVGRect::updateShapeFromElement()
if (boundingBoxSize.isEmpty())
return;

if (rectElement().rx().value(lengthContext) > 0 || rectElement().ry().value(lengthContext) > 0)
auto& svgStyle = style().svgStyle();
if (lengthContext.valueForLength(svgStyle.rx(), SVGLengthMode::Width) > 0
|| lengthContext.valueForLength(svgStyle.ry(), SVGLengthMode::Height) > 0)
m_shapeType = ShapeType::RoundedRectangle;
else
m_shapeType = ShapeType::Rectangle;
Expand All @@ -76,17 +78,17 @@ void LegacyRenderSVGRect::updateShapeFromElement()
return;
}

m_fillBoundingBox = FloatRect(FloatPoint(lengthContext.valueForLength(style().svgStyle().x(), SVGLengthMode::Width),
lengthContext.valueForLength(style().svgStyle().y(), SVGLengthMode::Height)),
m_fillBoundingBox = FloatRect(FloatPoint(lengthContext.valueForLength(svgStyle.x(), SVGLengthMode::Width),
lengthContext.valueForLength(svgStyle.y(), SVGLengthMode::Height)),
boundingBoxSize);

auto strokeBoundingBox = m_fillBoundingBox;
if (style().svgStyle().hasStroke())
if (svgStyle.hasStroke())
strokeBoundingBox.inflate(this->strokeWidth() / 2);

#if USE(CG)
// CoreGraphics can inflate the stroke by 1px when drawing a rectangle with antialiasing disabled at non-integer coordinates, we need to compensate.
if (style().svgStyle().shapeRendering() == ShapeRendering::CrispEdges)
if (svgStyle.shapeRendering() == ShapeRendering::CrispEdges)
strokeBoundingBox.inflate(1);
#endif

Expand Down

0 comments on commit 0eba4b6

Please sign in to comment.