diff --git a/Source/svg/SVGParser.swift b/Source/svg/SVGParser.swift index f1406535..fb4064b4 100644 --- a/Source/svg/SVGParser.swift +++ b/Source/svg/SVGParser.swift @@ -256,52 +256,57 @@ open class SVGParser { } fileprivate func parseElement(_ node: XMLIndexer, groupStyle: [String: String] = [:]) -> Node? { - if let element = node.element { - let styleAttributes = getStyleAttributes(groupStyle, element: element) - let position = getPosition(element) - switch element.name { - case "path": - if let path = parsePath(node) { - return Shape(form: path, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) - } - case "line": - if let line = parseLine(node) { - return Shape(form: line, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) - } - case "rect": - if let rect = parseRect(node) { - return Shape(form: rect, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) - } - case "circle": - if let circle = parseCircle(node) { - return Shape(form: circle, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) - } - case "ellipse": - if let ellipse = parseEllipse(node) { - return Shape(form: ellipse, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) - } - case "polygon": - if let polygon = parsePolygon(node) { - return Shape(form: polygon, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) - } - case "polyline": - if let polyline = parsePolyline(node) { - return Shape(form: polyline, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) - } - case "image": - return parseImage(node, opacity: getOpacity(styleAttributes), pos: position, clip: getClipPath(styleAttributes)) - case "text": - return parseText(node, textAnchor: getTextAnchor(styleAttributes), fill: getFillColor(styleAttributes), - stroke: getStroke(styleAttributes), opacity: getOpacity(styleAttributes), fontName: getFontName(styleAttributes), fontSize: getFontSize(styleAttributes), fontWeight: getFontWeight(styleAttributes), pos: position) - case "use": - return parseUse(node, groupStyle: styleAttributes, place: position) - case "mask": - break - default: - print("SVG parsing error. Shape \(element.name) not supported") - return .none + guard let element = node.element else { return .none } + + let styleAttributes = getStyleAttributes(groupStyle, element: element) + if styleAttributes["display"] == "none" { + return .none + } + + let position = getPosition(element) + switch element.name { + case "path": + if let path = parsePath(node) { + return Shape(form: path, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) + } + case "line": + if let line = parseLine(node) { + return Shape(form: line, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) + } + case "rect": + if let rect = parseRect(node) { + return Shape(form: rect, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) + } + case "circle": + if let circle = parseCircle(node) { + return Shape(form: circle, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) + } + case "ellipse": + if let ellipse = parseEllipse(node) { + return Shape(form: ellipse, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) } + case "polygon": + if let polygon = parsePolygon(node) { + return Shape(form: polygon, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) + } + case "polyline": + if let polyline = parsePolyline(node) { + return Shape(form: polyline, fill: getFillColor(styleAttributes), stroke: getStroke(styleAttributes), place: position, opacity: getOpacity(styleAttributes), clip: getClipPath(styleAttributes), tag: getTag(element)) + } + case "image": + return parseImage(node, opacity: getOpacity(styleAttributes), pos: position, clip: getClipPath(styleAttributes)) + case "text": + return parseText(node, textAnchor: getTextAnchor(styleAttributes), fill: getFillColor(styleAttributes), + stroke: getStroke(styleAttributes), opacity: getOpacity(styleAttributes), fontName: getFontName(styleAttributes), fontSize: getFontSize(styleAttributes), fontWeight: getFontWeight(styleAttributes), pos: position) + case "use": + return parseUse(node, groupStyle: styleAttributes, place: position) + case "mask": + break + default: + print("SVG parsing error. Shape \(element.name) not supported") + return .none } + return .none }