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 #313: Gradients not parsing when they are not in <defs> group #362

Merged
merged 1 commit into from
May 16, 2018
Merged
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
48 changes: 25 additions & 23 deletions Source/svg/SVGParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ open class SVGParser {
if let id = element.allAttributes["id"]?.text, let clip = parseClip(node) {
self.defClip[id] = clip
}
case "linearGradient", "radialGradient":
parseDefinition(node)
case "style", "defs":
// do nothing - it was parsed on first iteration
return .none
Expand Down Expand Up @@ -205,32 +207,32 @@ open class SVGParser {
}

fileprivate func parseDefinitions(_ defs: XMLIndexer, groupStyle: [String: String] = [:]) {
for child in defs.children {
guard let id = child.element?.allAttributes["id"]?.text else {
continue
}
if let fill = parseFill(child) {
self.defFills[id] = fill
continue
}

if let _ = parseNode(child) {
// TODO we don't really need to parse node
self.defNodes[id] = child
continue
}

if let mask = parseMask(child) {
self.defMasks[id] = mask
continue
}

if let clip = parseClip(child) {
self.defClip[id] = clip
}
defs.children.forEach(parseDefinition(_:))
}

private func parseDefinition(_ child: XMLIndexer) {
guard let id = child.element?.allAttributes["id"]?.text else {
return
}
if let fill = parseFill(child) {
defFills[id] = fill
}

else if let _ = parseNode(child) {
// TODO we don't really need to parse node
defNodes[id] = child
}

else if let mask = parseMask(child) {
defMasks[id] = mask
}

else if let clip = parseClip(child) {
defClip[id] = clip
}
}


fileprivate func parseElement(_ node: XMLIndexer, groupStyle: [String: String] = [:]) -> Node? {
guard let element = node.element else { return .none }

Expand Down