Skip to content

Commit adac9d9

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
Fix markerUnits=strokeWidth combined with non-scaling-stroke
https://bugs.webkit.org/show_bug.cgi?id=304893 Reviewed by Simon Fraser. This patch aligns WebKit with Gecko / Firefox and Blink / Chromium. Additionally, it also fixes it for both LegacySVG and Layer Based SVG engine (LBSE). Merge: https://chromium.googlesource.com/chromium/src/+/ef238963f2eaf1add1f8c3a0b3cb20c74310e67d When vector-effect=non-scaling-stroke applies to an element we need to adjust the stroke width used to compute the local coordinate space for a marker with markerUnits=strokeWidth. This also do clean-up of removing local test in favor of WPT. * Source/WebCore/rendering/svg/RenderSVGPath.cpp: (WebCore::RenderSVGPath::drawMarkers): * Source/WebCore/rendering/svg/RenderSVGShape.cpp: (WebCore::RenderSVGShape::strokeWidthForMarkerUnits const): * Source/WebCore/rendering/svg/RenderSVGShape.h: * Source/WebCore/rendering/svg/legacy/LegacyRenderSVGPath.cpp: (WebCore::LegacyRenderSVGPath::drawMarkers): * Source/WebCore/rendering/svg/legacy/LegacyRenderSVGShape.cpp: (WebCore::LegacyRenderSVGShape::strokeWidthForMarkerUnits const): * Source/WebCore/rendering/svg/legacy/LegacyRenderSVGShape.h: * LayoutTests/TestExpectations: Progression > Clean-up (Removed Local Test): * LayoutTests/platform/mac-sonoma-wk2-lbse-text/svg/custom/non-scaling-stroke-markers-expected.txt: Removed. * LayoutTests/platform/mac-sonoma-wk2-pixel/svg/custom/non-scaling-stroke-markers-expected.png: Removed. * LayoutTests/platform/mac/svg/custom/non-scaling-stroke-markers-expected.png: Removed. * LayoutTests/svg/custom/non-scaling-stroke-markers-expected.txt: Removed. * LayoutTests/svg/custom/non-scaling-stroke-markers.svg: Removed. Canonical link: https://commits.webkit.org/305077@main
1 parent 84eae22 commit adac9d9

File tree

12 files changed

+38
-46
lines changed

12 files changed

+38
-46
lines changed

LayoutTests/TestExpectations

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7638,7 +7638,6 @@ webkit.org/b/250795 imported/w3c/web-platform-tests/html/semantics/interactive-e
76387638
imported/w3c/web-platform-tests/svg/painting/reftests/marker-implicit-subpaths.html [ ImageOnlyFailure ]
76397639
imported/w3c/web-platform-tests/svg/painting/reftests/marker-path-003.svg [ ImageOnlyFailure ]
76407640
imported/w3c/web-platform-tests/svg/painting/reftests/marker-path-013.svg [ ImageOnlyFailure ]
7641-
imported/w3c/web-platform-tests/svg/painting/reftests/marker-units-strokewidth-non-scaling-stroke.svg [ ImageOnlyFailure ]
76427641
imported/w3c/web-platform-tests/svg/painting/reftests/markers-orient-002.svg [ ImageOnlyFailure ]
76437642
imported/w3c/web-platform-tests/svg/painting/reftests/paint-context-001.svg [ ImageOnlyFailure ]
76447643
imported/w3c/web-platform-tests/svg/painting/reftests/paint-context-002.svg [ ImageOnlyFailure ]

LayoutTests/platform/mac-sonoma-wk2-lbse-text/svg/custom/non-scaling-stroke-markers-expected.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.

LayoutTests/svg/custom/non-scaling-stroke-markers-expected.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

LayoutTests/svg/custom/non-scaling-stroke-markers.svg

Lines changed: 0 additions & 14 deletions
This file was deleted.

Source/WebCore/rendering/svg/RenderSVGPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void RenderSVGPath::drawMarkers(PaintInfo& paintInfo)
228228
if (!markerStart && !markerMid && !markerEnd)
229229
return;
230230

231-
float strokeWidth = this->strokeWidth();
231+
float strokeWidth = this->strokeWidthForMarkerUnits();
232232
for (auto& markerPosition : m_markerPositions) {
233233
if (auto* marker = markerForType(markerPosition.type, markerStart.get(), markerMid.get(), markerEnd.get()); marker && marker->hasLayer()) {
234234
auto& context = paintInfo.context();

Source/WebCore/rendering/svg/RenderSVGShape.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,23 @@ float RenderSVGShape::strokeWidth() const
394394
return std::isnan(strokeWidth) ? 0 : strokeWidth;
395395
}
396396

397+
float RenderSVGShape::strokeWidthForMarkerUnits() const
398+
{
399+
float strokeWidth = RenderSVGShape::strokeWidth();
400+
if (hasNonScalingStroke()) {
401+
auto nonScalingTransform = nonScalingStrokeTransform();
402+
if (!nonScalingTransform.isInvertible())
403+
return 0.f;
404+
405+
double xScale = nonScalingTransform.xScale();
406+
double yScale = nonScalingTransform.yScale();
407+
float scaleFactor = clampTo<float>(std::sqrt((xScale * xScale + yScale * yScale) / 2));
408+
409+
strokeWidth /= scaleFactor;
410+
}
411+
return strokeWidth;
412+
}
413+
397414
Path& RenderSVGShape::ensurePath()
398415
{
399416
if (!hasPath())

Source/WebCore/rendering/svg/RenderSVGShape.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class RenderSVGShape : public RenderSVGModelObject {
111111
virtual bool shapeDependentStrokeContains(const FloatPoint&, PointCoordinateSpace = GlobalCoordinateSpace);
112112
virtual bool shapeDependentFillContains(const FloatPoint&, const WindRule) const;
113113
float strokeWidth() const;
114+
float strokeWidthForMarkerUnits() const;
114115

115116
inline bool hasNonScalingStroke() const;
116117
Path* nonScalingStrokePath(const Path*, const AffineTransform&) const;

Source/WebCore/rendering/svg/legacy/LegacyRenderSVGPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void LegacyRenderSVGPath::drawMarkers(PaintInfo& paintInfo)
250250
if (!markerStart && !markerMid && !markerEnd)
251251
return;
252252

253-
float strokeWidth = this->strokeWidth();
253+
float strokeWidth = this->strokeWidthForMarkerUnits();
254254
unsigned size = m_markerPositions.size();
255255
for (unsigned i = 0; i < size; ++i) {
256256
if (auto* marker = markerForType(m_markerPositions[i].type, markerStart, markerMid, markerEnd)) {

0 commit comments

Comments
 (0)