1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-09-21 01:47:44 +03:00

Fix #185: Implement px m Stroke-dasharray

This commit is contained in:
Alisa Mylnikova 2018-04-18 18:28:21 +07:00
parent 7844137b34
commit 6efee3b536

View File

@ -667,7 +667,7 @@ open class SVGParser {
characterSet.insert(",")
let separatedValues = strokeDashes.components(separatedBy: characterSet)
separatedValues.forEach { value in
if let doubleValue = Double(value) {
if let doubleValue = doubleFromString(value) {
dashes.append(doubleValue)
}
}
@ -1189,10 +1189,35 @@ open class SVGParser {
}
fileprivate func getDoubleValue(_ element: SWXMLHash.XMLElement, attribute: String) -> Double? {
guard let attributeValue = element.allAttributes[attribute]?.text, let doubleValue = Double(attributeValue) else {
guard let attributeValue = element.allAttributes[attribute]?.text else {
return .none
}
return doubleValue
return doubleFromString(attributeValue)
}
fileprivate func doubleFromString(_ string: String) -> Double? {
if let doubleValue = Double(string) {
return doubleValue
}
do {
let matcher = try NSRegularExpression(pattern: "([a-zA-Z]+)", options: .caseInsensitive)
let fullRange = NSRange(location: 0, length: string.count)
if let match = matcher.firstMatch(in: string, options: .reportCompletion, range: fullRange) {
let unitString = (string as NSString).substring(with: match.range(at: 1))
let numberString = String(string.dropLast(unitString.count))
switch unitString {
case "px" :
return Double(numberString)
default:
print("SVG parsing error. Unit \(unitString) not supported")
return Double(numberString)
}
}
} catch {
print(error.localizedDescription)
}
return .none
}
fileprivate func getDoubleValueFromPercentage(_ element: SWXMLHash.XMLElement, attribute: String) -> Double? {