From 181ff5b8ca99fc8dae292fd3bddb5b1c8b14d629 Mon Sep 17 00:00:00 2001 From: Steve Park Date: Mon, 4 Sep 2023 20:42:05 +1200 Subject: [PATCH] fix : fill-opacity is applied to the overlay, if the fill is a gradient paint --- Source/Model/Primitives/SVGGradient.swift | 8 ++++++++ Source/Parser/SVG/SVGParserBasics.swift | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/Model/Primitives/SVGGradient.swift b/Source/Model/Primitives/SVGGradient.swift index 42cafb5..a96970b 100644 --- a/Source/Model/Primitives/SVGGradient.swift +++ b/Source/Model/Primitives/SVGGradient.swift @@ -83,6 +83,7 @@ public class SVGLinearGradient: SVGGradient { .frame(width: width, height: height) .offset(x: bounds.minX, y: bounds.minY) .mask(view) + .opacity(opacity) ) } @@ -130,6 +131,7 @@ public class SVGRadialGradient: SVGGradient { height: userSpace ? 1 : height/minimum)) .offset(x: bounds.minX, y: bounds.minY) .mask(view) + .opacity(opacity) ) } @@ -151,12 +153,18 @@ public class SVGGradient: SVGPaint, Equatable { public let userSpace: Bool public let stops: [SVGStop] + public private(set) var opacity: Double = 1.0 public init(userSpace: Bool = false, stops: [SVGStop] = []) { self.userSpace = userSpace self.stops = stops } + public override func opacity(_ opacity: Double) -> SVGGradient { + self.opacity = opacity + return self + } + } public class SVGStop: Equatable { diff --git a/Source/Parser/SVG/SVGParserBasics.swift b/Source/Parser/SVG/SVGParserBasics.swift index a37688e..39c566e 100644 --- a/Source/Parser/SVG/SVGParserBasics.swift +++ b/Source/Parser/SVG/SVGParserBasics.swift @@ -89,7 +89,7 @@ extension SVGHelper { static func parseFillInternal(_ colorString: String, _ style: [String: String], _ index: SVGIndex) -> SVGPaint? { if let colorId = SVGHelper.parseIdFromUrl(colorString) { if let paint = index.paint(by: colorId) { - return paint + return paint.opacity(parseOpacity(style, "fill-opacity", alternativeKeys: ["opacity"])) } } if let color = parseColor(colorString, style) {