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

Allow 'stop' elements with CSS syle attributes to be parsed #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 6 additions & 2 deletions Source/Parser/SVG/SVGIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,16 @@ class SVGIndex {
private func parseStop(_ element: XMLElement, _ style: [String: String]) -> SVGStop? {
let offset = getDoubleValueFromPercentage(element, attribute: "offset")

// Explode any CSS styles and merge with XML style attributes
let cssAttributes = SVGParser.getStyleAttributes(xml: element, index: self)
let attributes = element.attributes.merging(cssAttributes) { current, _ in current }

var opacity: Double = 1
if let stopOpacity = element.attributes["stop-opacity"], let doubleValue = Double(stopOpacity) {
if let stopOpacity = attributes["stop-opacity"], let doubleValue = Double(stopOpacity) {
opacity = doubleValue
}
var color = SVGColor.black.opacity(opacity)
if let stopColor = element.attributes["stop-color"], let clr = SVGHelper.parseColor(stopColor, style) {
if let stopColor = attributes["stop-color"], let clr = SVGHelper.parseColor(stopColor, style) {
color = clr.opacity(opacity)
}
return SVGStop(color: color, offset: offset)
Expand Down