Skip to content

Commit

Permalink
Merge pull request #362 from f3dm76/task/parseGradients
Browse files Browse the repository at this point in the history
Fix #313: Gradients not parsing when they are not in <defs> group
  • Loading branch information
ystrot authored May 16, 2018
2 parents 910845f + f5ee8e4 commit 85ecbf3
Showing 1 changed file with 25 additions and 23 deletions.
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

0 comments on commit 85ecbf3

Please sign in to comment.