@@ -4,11 +4,10 @@ import android.graphics.Path
4
4
import java.util.*
5
5
6
6
private val VALID_METHODS : Set <String > = setOf (" M" , " L" , " H" , " V" , " C" , " S" , " Q" , " R" , " A" , " Z" , " m" , " l" , " h" , " v" , " c" , " s" , " q" , " r" , " a" , " z" )
7
- private val regex = " ([a-zA-Z])" .toRegex()
8
7
9
8
class SVGAPath (originValue : String ) {
10
9
11
- private val replacedValue: String = originValue.replace(regex, " |||$1 " ) .replace(" ," , " " )
10
+ private val replacedValue: String = if ( originValue.contains( " , " )) originValue .replace(" ," , " " ) else originValue
12
11
13
12
private var cachedPath: Path ? = null
14
13
@@ -18,13 +17,17 @@ class SVGAPath(originValue: String) {
18
17
return
19
18
}
20
19
val cachedPath = Path ()
21
- val segments = StringTokenizer (this .replacedValue, " |||" )
20
+ val segments = StringTokenizer (this .replacedValue, " MLHVCSQRAZmlhvcsqraz" , true )
21
+ var currentMethod = " "
22
22
while (segments.hasMoreTokens()) {
23
23
val segment = segments.nextToken()
24
24
if (segment.isEmpty()) { continue }
25
- val firstLetter = segment.substring(0 , 1 )
26
- if (VALID_METHODS .contains(firstLetter)) {
27
- operate(cachedPath, firstLetter, StringTokenizer (segment.substring(1 ).trim(), " " ))
25
+ if (VALID_METHODS .contains(segment)) {
26
+ currentMethod = segment
27
+ if (currentMethod == " Z" || currentMethod == " z" ) { operate(cachedPath, currentMethod, StringTokenizer (" " , " " )) }
28
+ }
29
+ else {
30
+ operate(cachedPath, currentMethod, StringTokenizer (segment, " " ))
28
31
}
29
32
}
30
33
this .cachedPath = cachedPath
@@ -42,6 +45,7 @@ class SVGAPath(originValue: String) {
42
45
var index = 0
43
46
while (args.hasMoreTokens()) {
44
47
val s = args.nextToken()
48
+ if (s.isEmpty()) {continue }
45
49
if (index == 0 ) { x0 = s.toFloat() }
46
50
if (index == 1 ) { y0 = s.toFloat() }
47
51
if (index == 2 ) { x1 = s.toFloat() }
0 commit comments