Skip to content

Commit 484d03a

Browse files
committed
Add ellipseLayer.
1 parent 73a69f9 commit 484d03a

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

Source/SVGAVectorLayer.m

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ - (void)createSublayers:(SVGAVectorLayer *)previous {
3535
if ([shape[@"type"] isEqualToString:@"shape"]) {
3636
[self addSublayer:[self createCurveLayer:shape]];
3737
}
38+
else if ([shape[@"type"] isEqualToString:@"ellipse"]) {
39+
[self addSublayer:[self createEllipseLayer:shape]];
40+
}
3841
else if ([shape[@"type"] isEqualToString:@"keep"] && previous != nil) {
3942
for (CALayer *item in previous.sublayers) {
4043
[self addSublayer:[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:item]]];
@@ -53,6 +56,36 @@ - (CALayer *)createCurveLayer:(NSDictionary *)shape {
5356
}
5457
}
5558
CAShapeLayer *shapeLayer = [bezierPath createLayer];
59+
[self resetStyles:shapeLayer shape:shape];
60+
return shapeLayer;
61+
}
62+
63+
- (CALayer *)createEllipseLayer:(NSDictionary *)shape {
64+
UIBezierPath *bezierPath;
65+
if ([shape[@"args"] isKindOfClass:[NSDictionary class]]) {
66+
if ([shape[@"args"][@"x"] isKindOfClass:[NSNumber class]] &&
67+
[shape[@"args"][@"y"] isKindOfClass:[NSNumber class]] &&
68+
[shape[@"args"][@"radiusX"] isKindOfClass:[NSNumber class]] &&
69+
[shape[@"args"][@"radiusY"] isKindOfClass:[NSNumber class]]) {
70+
CGFloat x = [shape[@"args"][@"x"] floatValue];
71+
CGFloat y = [shape[@"args"][@"x"] floatValue];
72+
CGFloat rx = [shape[@"args"][@"radiusX"] floatValue];
73+
CGFloat ry = [shape[@"args"][@"radiusY"] floatValue];
74+
bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x - rx, y - ry, rx * 2, ry * 2)];
75+
}
76+
}
77+
if (bezierPath != nil) {
78+
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
79+
[shapeLayer setPath:[bezierPath CGPath]];
80+
[self resetStyles:shapeLayer shape:shape];
81+
return shapeLayer;
82+
}
83+
else {
84+
return [CALayer layer];
85+
}
86+
}
87+
88+
- (void)resetStyles:(CAShapeLayer *)shapeLayer shape:(NSDictionary *)shape {
5689
shapeLayer.masksToBounds = NO;
5790
if ([shape[@"styles"] isKindOfClass:[NSDictionary class]]) {
5891
if ([shape[@"styles"][@"fill"] isKindOfClass:[NSArray class]]) {
@@ -85,7 +118,6 @@ - (CALayer *)createCurveLayer:(NSDictionary *)shape {
85118
shapeLayer.lineWidth = [shape[@"styles"][@"strokeWidth"] floatValue];
86119
}
87120
}
88-
return shapeLayer;
89121
}
90122

91123
@end

0 commit comments

Comments
 (0)