From f5ee8e43c8b630d51d7b4ef7611f70a514f951dc Mon Sep 17 00:00:00 2001 From: Sroik Date: Thu, 12 Apr 2018 22:45:47 +0300 Subject: [PATCH] Fix #313: Gradients not parsing when they are not in group --- Source/svg/SVGParser.swift | 48 ++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/Source/svg/SVGParser.swift b/Source/svg/SVGParser.swift index 78132cb2..8eed6494 100644 --- a/Source/svg/SVGParser.swift +++ b/Source/svg/SVGParser.swift @@ -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 @@ -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 }