mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-11 05:05:23 +03:00
Fix #395: improvements readSegments for A,a
This commit is contained in:
parent
8affa6f988
commit
0d5a5136da
@ -1610,7 +1610,7 @@ private class PathDataReader {
|
||||
}
|
||||
|
||||
public func read() -> [PathSegment] {
|
||||
_ = readNext()
|
||||
readNext()
|
||||
var segments = [PathSegment]()
|
||||
while let array = readSegments() {
|
||||
segments.append(contentsOf: array)
|
||||
@ -1625,7 +1625,12 @@ private class PathDataReader {
|
||||
return [PathSegment(type: type)]
|
||||
}
|
||||
var result = [PathSegment]()
|
||||
let data = readData(type: type)
|
||||
let data: [Double]
|
||||
if type == .a || type == .A {
|
||||
data = readDataOfASegment()
|
||||
} else {
|
||||
data = readData()
|
||||
}
|
||||
var index = 0
|
||||
var isFirstSegment = true
|
||||
while index < data.count {
|
||||
@ -1651,11 +1656,11 @@ private class PathDataReader {
|
||||
return nil
|
||||
}
|
||||
|
||||
private func readData(type: PathSegmentType) -> [Double] {
|
||||
private func readData() -> [Double] {
|
||||
var data = [Double]()
|
||||
while true {
|
||||
skipSpaces()
|
||||
if let value = readNum(type: type, index: data.count) {
|
||||
if let value = readNum() {
|
||||
data.append(value)
|
||||
} else {
|
||||
return data
|
||||
@ -1663,6 +1668,28 @@ private class PathDataReader {
|
||||
}
|
||||
}
|
||||
|
||||
private func readDataOfASegment() -> [Double] {
|
||||
let argCount = getArgCount(segment: .A)
|
||||
var data: [Double] = []
|
||||
var index = 0
|
||||
while true {
|
||||
skipSpaces()
|
||||
let value: Double?
|
||||
let indexMod = index % argCount
|
||||
if indexMod == 3 || indexMod == 4 {
|
||||
value = readFlag()
|
||||
} else {
|
||||
value = readNum()
|
||||
}
|
||||
guard let doubleValue = value else {
|
||||
return data
|
||||
}
|
||||
data.append(doubleValue)
|
||||
index += 1
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
private func skipSpaces() {
|
||||
var ch = current
|
||||
while ch != nil && "\n\r\t ,".contains(String(ch!)) {
|
||||
@ -1670,7 +1697,22 @@ private class PathDataReader {
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func readNum(type: PathSegmentType, index: Int) -> Double? {
|
||||
private func readFlag() -> Double? {
|
||||
guard let ch = current else {
|
||||
return .none
|
||||
}
|
||||
readNext()
|
||||
switch ch {
|
||||
case "0":
|
||||
return 0
|
||||
case "1":
|
||||
return 1
|
||||
default:
|
||||
return .none
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func readNum() -> Double? {
|
||||
guard let ch = current else {
|
||||
return .none
|
||||
}
|
||||
@ -1681,9 +1723,7 @@ private class PathDataReader {
|
||||
|
||||
var chars = [ch]
|
||||
var hasDot = ch == "."
|
||||
let isFlag = (type == .a || type == .A) && (index == 3 || index == 4)
|
||||
|
||||
while let ch = readDigit(&hasDot), !isFlag {
|
||||
while let ch = readDigit(&hasDot) {
|
||||
chars.append(ch)
|
||||
}
|
||||
|
||||
@ -1692,12 +1732,6 @@ private class PathDataReader {
|
||||
guard let value = Double(buf) else {
|
||||
return .none
|
||||
}
|
||||
guard isFlag else {
|
||||
return value
|
||||
}
|
||||
guard value == 0 || value == 1 else {
|
||||
return .none
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
@ -1728,6 +1762,7 @@ private class PathDataReader {
|
||||
return false
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
private func readNext() -> UnicodeScalar? {
|
||||
previous = current
|
||||
current = iterator.next()
|
||||
@ -1744,7 +1779,7 @@ private class PathDataReader {
|
||||
private func readSegmentType() -> PathSegmentType? {
|
||||
while true {
|
||||
if let type = getPathSegmentType() {
|
||||
_ = readNext()
|
||||
readNext()
|
||||
return type
|
||||
}
|
||||
if readNext() == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user