3
3
import android .graphics .Path ;
4
4
import android .graphics .RectF ;
5
5
6
+ import java .util .ArrayList ;
7
+
8
+ class PathElement {
9
+ ElementType type ;
10
+ Point [] points ;
11
+ PathElement (ElementType type , Point [] points ) {
12
+ this .type = type ;
13
+ this .points = points ;
14
+ }
15
+ }
16
+
6
17
class PathParser {
7
18
static float mScale ;
8
19
9
20
private static int i ;
10
21
private static int l ;
11
22
private static String s ;
12
23
private static Path mPath ;
24
+ static ArrayList <PathElement > elements ;
13
25
14
26
private static float mPenX ;
15
27
private static float mPenY ;
@@ -20,6 +32,7 @@ class PathParser {
20
32
private static boolean mPenDown ;
21
33
22
34
static Path parse (String d ) {
35
+ elements = new ArrayList <>();
23
36
char prev_cmd = ' ' ;
24
37
mPath = new Path ();
25
38
l = d .length ();
@@ -189,6 +202,7 @@ private static void moveTo(float x, float y) {
189
202
mPenDownX = mPivotX = mPenX = x ;
190
203
mPenDownY = mPivotY = mPenY = y ;
191
204
mPath .moveTo (x * mScale , y * mScale );
205
+ elements .add (new PathElement (ElementType .kCGPathElementMoveToPoint , new Point []{new Point (x ,y )}));
192
206
}
193
207
194
208
private static void line (float x , float y ) {
@@ -201,6 +215,7 @@ private static void lineTo(float x, float y) {
201
215
mPivotX = mPenX = x ;
202
216
mPivotY = mPenY = y ;
203
217
mPath .lineTo (x * mScale , y * mScale );
218
+ elements .add (new PathElement (ElementType .kCGPathElementAddLineToPoint , new Point []{new Point (x ,y )}));
204
219
}
205
220
206
221
private static void curve (float c1x , float c1y , float c2x , float c2y , float ex , float ey ) {
@@ -219,6 +234,7 @@ private static void cubicTo(float c1x, float c1y, float c2x, float c2y, float ex
219
234
mPenX = ex ;
220
235
mPenY = ey ;
221
236
mPath .cubicTo (c1x * mScale , c1y * mScale , c2x * mScale , c2y * mScale , ex * mScale , ey * mScale );
237
+ elements .add (new PathElement (ElementType .kCGPathElementAddCurveToPoint , new Point []{new Point (c1x , c1y ), new Point (c2x , c2y ), new Point (ex , ey )}));
222
238
}
223
239
224
240
private static void smoothCurve (float c1x , float c1y , float ex , float ey ) {
@@ -364,6 +380,7 @@ private static void arcTo(float rx, float ry, float rotation, boolean outer, boo
364
380
(cy + rx ) * mScale );
365
381
366
382
mPath .arcTo (oval , start , sweep );
383
+ elements .add (new PathElement (ElementType .kCGPathElementAddCurveToPoint , new Point []{new Point (x , y )}));
367
384
}
368
385
}
369
386
@@ -373,6 +390,7 @@ private static void close() {
373
390
mPenY = mPenDownY ;
374
391
mPenDown = false ;
375
392
mPath .close ();
393
+ elements .add (new PathElement (ElementType .kCGPathElementCloseSubpath , new Point []{new Point (mPenX , mPenY )}));
376
394
}
377
395
}
378
396
@@ -420,6 +438,7 @@ private static void arcToBezier(float cx, float cy, float rx, float ry, float sa
420
438
float ey = (cy + xy * x + yy * y );
421
439
422
440
mPath .cubicTo (c1x * mScale , c1y * mScale , c2x * mScale , c2y * mScale , ex * mScale , ey * mScale );
441
+ elements .add (new PathElement (ElementType .kCGPathElementAddCurveToPoint , new Point []{new Point (c1x , c1y ), new Point (c2x , c2y ), new Point (ex , ey )}));
423
442
}
424
443
}
425
444
0 commit comments