Skip to content
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
49 changes: 45 additions & 4 deletions Source/svg/SVGParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -896,11 +896,16 @@ open class SVGParser {
return 0
}

fileprivate func getTag(_ element: XMLHash.XMLElement) -> [String] {
let id = element.allAttributes["id"]?.text
return id.map { [$0] } ?? []
}
// fileprivate func getTag(_ element: XMLHash.XMLElement) -> [String] {
// let id = element.allAttributes["id"]?.text
// return id.map { [$0] } ?? []
// }

fileprivate func getTag(_ element: SWXMLHash.XMLElement) -> [String] {
return ["id","data-inventory-class","data-seat-properties"]
.compactMap { element.allAttributes[$0]?.text }
}

fileprivate func getOpacity(_ styleParts: [String: String]) -> Double {
if let opacityAttr = styleParts["opacity"] {
return getOpacity(opacityAttr)
Expand Down Expand Up @@ -2269,3 +2274,39 @@ fileprivate extension CharacterSet {

static let transformationAttributeCharacters = CharacterSet.latinAlphabet
}

extension SVGParser {

public struct CoachNode {
public let node: Group
public let defs: [String: Image]
}

public class func parse(coachSVG: String) -> CoachNode? {
let parser = SVGParser(coachSVG)

guard let node = try? parser.parse() else {
return nil
}

let defs = parser.defNodes
.filter { $0.key.hasPrefix("sfseat") || $0.key.hasPrefix("sbseat") }
.compactMap { try? parser.parseNode($0.value) }
.filter { !$0.tag.isEmpty }
.reduce(into: [String: Image]()) {

guard let tag = $1.tag.first,
let group = $1 as? Group,
let image = group.contents.first as? Image else {
return
}

$0[tag] = image
}

return CoachNode(
node: node,
defs: defs
)
}
}