Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix : fill-opacity is applied to the overlay, if the fill is a gradient paint #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Source/Model/Primitives/SVGGradient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class SVGLinearGradient: SVGGradient {
.frame(width: width, height: height)
.offset(x: bounds.minX, y: bounds.minY)
.mask(view)
.opacity(opacity)
)
}

Expand Down Expand Up @@ -130,6 +131,7 @@ public class SVGRadialGradient: SVGGradient {
height: userSpace ? 1 : height/minimum))
.offset(x: bounds.minX, y: bounds.minY)
.mask(view)
.opacity(opacity)
)
}

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Source/Parser/SVG/SVGParserBasics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down