/
pxSVGRenderPath.m
560 lines (537 loc) · 21 KB
/
pxSVGRenderPath.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
//
// pxSVGRenderPath.m
// pxSVG
//
// Created by Yury Popov on 12 мая.
// Copyright (c) 2015 PhoeniX. All rights reserved.
//
#import "pxSVGRenderPath.h"
#import "pxSVGGroup.h"
#import "pxSVGPath.h"
@interface pxSVGGradient : NSObject
@property NSArray *colors;
@property NSArray *locations;
@property CGPoint startPoint, endPoint;
@end
@implementation pxSVGGradient
@end
@interface pxSVGPattern : pxSVGGroup
@property CATransform3D patternTransform;
@property CGRect patternBounds;
@end
@implementation pxSVGPattern
@end
@interface pxSVGRenderPath ()
@property NSMutableDictionary *defCache;
@property pxXMLNode *xml;
@property pxSVGObject *root;
@property CGRect bounds;
@end
@interface pxSVGPatternLayer : CALayer
@property (nonatomic) CALayer *patternLayer;
@property (nonatomic) CATransform3D patternTransform;
@property UIBezierPath *clipPath;
@end
@implementation pxSVGPatternLayer
+ (instancetype)layer
{
return [super layer];
}
- (instancetype)init
{
self = [super init];
[self setNeedsDisplayOnBoundsChange:YES];
[self setNeedsDisplay];
return self;
}
- (void)setPatternLayer:(CALayer *)patternLayer
{
_patternLayer = patternLayer;
[self setNeedsDisplay];
}
- (void)setPatternTransform:(CATransform3D)patternTransform
{
_patternTransform = patternTransform;
[self setNeedsDisplay];
}
- (void)setNeedsDisplay
{
if ([NSThread isMainThread]) return [super setNeedsDisplay];
__weak id weakself = self;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if (weakself) [weakself setNeedsDisplay];
}];
}
- (void)drawInContext:(CGContextRef)ctx
{
if (self.clipPath) {
UIBezierPath *cp = [self.clipPath copy];
[cp applyTransform:CGAffineTransformMakeTranslation(-cp.bounds.origin.x, -cp.bounds.origin.y)];
CGContextAddPath(ctx, cp.CGPath);
CGContextClip(ctx);
}
CGRect r = CGContextGetClipBoundingBox(ctx);
CGAffineTransform tr = CATransform3DGetAffineTransform(self.patternTransform);
CGSize sz = self.patternLayer.frame.size;
sz = CGSizeApplyAffineTransform(sz, tr);
CGPoint off = CGPointApplyAffineTransform((CGPoint){0,0}, tr); tr.tx = 0; tr.ty = 0;
off.x = fmod(off.x,sz.width);
off.y = fmod(off.y,sz.height);
while (off.y < r.size.height) {
CGFloat x = off.x;
while (x < r.size.width) {
CGContextSaveGState(ctx);
CGContextTranslateCTM(ctx, x, off.y);
CGContextConcatCTM(ctx, tr);
CGContextTranslateCTM(ctx, self.patternLayer.frame.origin.x, self.patternLayer.frame.origin.y);
[self.patternLayer renderInContext:ctx];
CGContextRestoreGState(ctx);
x += sz.width;
}
off.y += sz.height;
}
}
@end
@interface pxSVGGradientLayer : CALayer
@property UIBezierPath *clipPath;
@property NSArray *colors;
@property NSArray *locations;
@property CGPoint startPoint, endPoint;
@end
@implementation pxSVGGradientLayer
+ (instancetype)layer
{
return [super layer];
}
- (instancetype)init
{
self = [super init];
[self setNeedsDisplayOnBoundsChange:YES];
[self setNeedsDisplay];
return self;
}
- (void)setNeedsDisplay
{
if ([NSThread isMainThread]) return [super setNeedsDisplay];
__weak id weakself = self;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if (weakself) [weakself setNeedsDisplay];
}];
}
- (void)drawInContext:(CGContextRef)ctx
{
CGContextSaveGState(ctx);
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
CGFloat locs[self.locations.count];
for (NSUInteger i=0; i<self.locations.count; i++)
locs[i] = [self.locations[i] doubleValue];
CGGradientRef gr = CGGradientCreateWithColors(cs, (__bridge CFArrayRef)self.colors, locs);
if (self.clipPath) {
UIBezierPath *cp = [self.clipPath copy];
[cp applyTransform:CGAffineTransformMakeTranslation(-cp.bounds.origin.x, -cp.bounds.origin.y)];
CGContextAddPath(ctx, cp.CGPath);
CGContextClip(ctx);
}
CGContextDrawLinearGradient(ctx, gr, self.startPoint, self.endPoint, 0);
CGGradientRelease(gr);
CGColorSpaceRelease(cs);
CGContextRestoreGState(ctx);
}
@end
@implementation pxSVGRenderPath
+ (instancetype)pathWithXML:(pxXMLNode *)xmlNode
{
return [[self alloc] initWithXML:xmlNode];
}
- (instancetype)initWithXML:(pxXMLNode *)xmlNode
{
self = [super init];
self.xml = xmlNode;
self.defCache = [NSMutableDictionary new];
self.root = [self parseObject:self.xml inheritAttributes:nil];
if ([xmlNode.attributes objectForKey:@"viewBox"]) {
NSArray *vb = [[xmlNode.attributes objectForKey:@"viewBox"] componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
self.bounds = (CGRect){
{
[vb[0] doubleValue],
[vb[1] doubleValue]
},{
[vb[2] doubleValue],
[vb[3] doubleValue]
}
};
} else if ([xmlNode.attributes objectForKey:@"width"] &&
[xmlNode.attributes objectForKey:@"height"]) {
CGPoint o = CGPointZero;
if ([xmlNode.attributes objectForKey:@"x"] &&
[xmlNode.attributes objectForKey:@"y"]) {
o = (CGPoint){
[[xmlNode.attributes objectForKey:@"x"] doubleValue],
[[xmlNode.attributes objectForKey:@"y"] doubleValue]
};
}
self.bounds = (CGRect){
o,{
[[xmlNode.attributes objectForKey:@"width"] doubleValue],
[[xmlNode.attributes objectForKey:@"height"] doubleValue]
}
};
} else {
self.bounds = self.root.bounds;
}
self.xml = nil;
return self;
}
- (pxSVGObject*)findDef:(NSString*)name inNode:(pxXMLNode*)xml
{
id def;
for (pxXMLNode *n in xml.childNodes) {
if ([[n.attributes objectForKey:@"id"] isEqualToString:name]) {
def = [self parseObject:n inheritAttributes:nil];
if (def) return def;
}
def = [self findDef:name inNode:n];
if (def) {
[self.defCache setObject:def forKey:name];
return def;
}
}
return nil;
}
- (pxSVGObject*)findDef:(NSString*)name
{
if (!name) return nil;
id def = [self.defCache objectForKey:name];
if (def) return def;
return [self findDef:name inNode:self.xml];
}
- (pxSVGObject*)reuseObjectWithAttributes:(NSDictionary*)attributes
{
NSString *href = [attributes objectForKey:@"xlink:href"];
if (!href) href = [attributes objectForKey:@"href"];
if (!href) return nil;
href = [href substringFromIndex:1];
pxSVGObject *oobj = [self findDef:href], *obj;
if (!oobj) return nil;
obj = [oobj.class new];
obj.strokeColor = oobj.strokeColor;
obj.strokeWidth = oobj.strokeWidth;
obj.opacity = oobj.opacity;
obj.fillOpacity = oobj.fillOpacity;
obj.fillColor = oobj.fillColor;
obj.fillDef = oobj.fillDef;
obj.clipDef = oobj.clipDef;
if ([attributes objectForKey:@"fill"]) {
CGFloat a = obj.fillOpacity;
if ([[attributes objectForKey:@"fill"] hasPrefix:@"url("]) {
NSString *u = [[attributes objectForKey:@"fill"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
u = [[u substringWithRange:NSMakeRange(3, u.length-4)] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\n\r\t ()#"]];
obj.fillDef = u;
} else obj.fillColor = [pxSVGObject colorWithSVGColor:[attributes objectForKey:@"fill"]];
if (obj.fillColor) [obj.fillColor getWhite:nil alpha:&a];
obj.fillOpacity = [attributes objectForKey:@"fill-opacity"]?[[attributes objectForKey:@"fill-opacity"] doubleValue]:a;
}
if ([oobj respondsToSelector:@selector(d)])
[(id)obj setD:[(id)oobj d]];
if ([oobj respondsToSelector:@selector(subnodes)])
[(id)obj setSubnodes:[(id)oobj subnodes]];
CATransform3D tr = oobj.transform;
if ([attributes objectForKey:@"x"]) tr = CATransform3DTranslate(tr, [[attributes objectForKey:@"x"] doubleValue], 0, 0);
if ([attributes objectForKey:@"y"]) tr = CATransform3DTranslate(tr, 0, [[attributes objectForKey:@"y"] doubleValue], 0);
if ([attributes objectForKey:@"width"]) {
CGFloat ow = oobj.bounds.size.width, w = [[attributes objectForKey:@"width"] doubleValue];
tr = CATransform3DScale(tr, ow/w, 1, 1);
}
if ([attributes objectForKey:@"height"]) {
CGFloat oh = oobj.bounds.size.height, h = [[attributes objectForKey:@"height"] doubleValue];
tr = CATransform3DScale(tr, 1, oh/h, 1);
}
if ([attributes objectForKey:@"transform"]) tr = CATransform3DConcat(tr, [pxSVGObject transformFromString:[attributes objectForKey:@"transform"]]);
obj.transform = tr;
obj.animations = oobj.animations;
return obj;
}
- (pxSVGGradient*)parseLinearGradient:(pxXMLNode*)node
{
NSString *gid = [node.attributes objectForKey:@"id"];
if (!gid) return nil;
NSString *href = [node.attributes objectForKey:@"xlink:href"];
if (!href) href = [node.attributes objectForKey:@"href"];
CGPoint sp = CGPointZero, ep = (CGPoint){INFINITY,INFINITY};
NSMutableArray *cls, *locs;
if (href) {
href = [href substringFromIndex:1];
pxSVGGradient *g = (id)[self findDef:href];
if (![g isKindOfClass:[pxSVGGradient class]]) return nil;
sp = g.startPoint;
ep = g.endPoint;
cls = (id)g.colors;
locs = (id)g.locations;
} else {
cls = [NSMutableArray new], locs = [NSMutableArray new];
for (pxXMLNode *s in node.childNodes) {
if (![s.tagName isEqualToString:@"stop"]) {
NSLog(@"Unknown gradient node: %@",s);
}
NSMutableDictionary *ma = [s.attributes mutableCopy];
if ([s.attributes objectForKey:@"style"]) {
for (NSString *ss in [[s.attributes objectForKey:@"style"] componentsSeparatedByString:@";"]) {
NSUInteger sep = [ss rangeOfString:@":"].location;
if (sep == NSNotFound) continue;
NSString *k = [[ss substringToIndex:sep] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *v = [[ss substringFromIndex:sep+1] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[ma setObject:v forKey:k];
}
}
if ([ma objectForKey:@"stop-color"] && [ma objectForKey:@"offset"]) {
UIColor *cl = [pxSVGObject colorWithSVGColor:[ma objectForKey:@"stop-color"]];
if ([ma objectForKey:@"stop-opacity"])
cl = [cl colorWithAlphaComponent:[[ma objectForKey:@"stop-opacity"] doubleValue]];
[cls addObject:(__bridge id)cl.CGColor];
[locs addObject:@([[ma objectForKey:@"offset"] doubleValue])];
}
}
}
if ([node.attributes objectForKey:@"x1"]) sp.x = [[node.attributes objectForKey:@"x1"] doubleValue];
if ([node.attributes objectForKey:@"y1"]) sp.y = [[node.attributes objectForKey:@"y1"] doubleValue];
if ([node.attributes objectForKey:@"x2"]) ep.x = [[node.attributes objectForKey:@"x2"] doubleValue];
if ([node.attributes objectForKey:@"y2"]) ep.y = [[node.attributes objectForKey:@"y2"] doubleValue];
if (cls.count) {
pxSVGGradient *g = [pxSVGGradient new];
g.colors = cls;
g.locations = locs;
g.startPoint = sp;
g.endPoint = ep;
[self.defCache setObject:g forKey:gid];
return g;
}
return nil;
}
- (pxSVGPattern*)parsePattern:(pxXMLNode*)node
{
NSString *pid = [node.attributes objectForKey:@"id"];
if (!pid) return nil;
NSString *href = [node.attributes objectForKey:@"xlink:href"];
if (!href) href = [node.attributes objectForKey:@"href"];
pxSVGPattern *p = nil;
if (href) {
href = [href substringFromIndex:1];
pxSVGPattern *op = (id)[self findDef:href];
if (![op isKindOfClass:[pxSVGPattern class]]) return nil;
p = [pxSVGPattern new];
p.id = pid;
p.opacity = op.opacity;
p.fillOpacity = op.fillOpacity;
p.fillColor = op.fillColor;
p.fillDef = op.fillDef;
p.clipDef = op.clipDef;
p.strokeColor = op.strokeColor;
p.strokeWidth = op.strokeWidth;
p.subnodes = op.subnodes;
p.transform = op.transform;
p.patternTransform = op.patternTransform;
p.patternBounds = op.patternBounds;
} else {
p = [pxSVGPattern new];
p.id = pid;
p.opacity = NAN;
p.fillOpacity = NAN;
[p loadAttributes:node.attributes];
NSMutableArray *sub = [NSMutableArray new];
for (pxXMLNode *n in node.childNodes) {
pxSVGObject *o = [self parseObject:n inheritAttributes:p];
if (o) [sub addObject:o];
}
p.subnodes = [NSArray arrayWithArray:sub];
p.transform = CATransform3DIdentity;
p.patternTransform = CATransform3DIdentity;
p.patternBounds = CGRectNull;
}
if ([node.attributes objectForKey:@"viewBox"]) {
NSArray *vb = [[node.attributes objectForKey:@"viewBox"] componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
p.patternBounds = (CGRect){
{
[vb[0] doubleValue],
[vb[1] doubleValue]
},{
[vb[2] doubleValue],
[vb[3] doubleValue]
}
};
} else if ([node.attributes objectForKey:@"width"] &&
[node.attributes objectForKey:@"height"]) {
CGPoint o = CGPointZero;
if ([node.attributes objectForKey:@"x"] &&
[node.attributes objectForKey:@"y"]) {
o = (CGPoint){
[[node.attributes objectForKey:@"x"] doubleValue],
[[node.attributes objectForKey:@"y"] doubleValue]
};
}
p.patternBounds = (CGRect){
o,{
[[node.attributes objectForKey:@"width"] doubleValue],
[[node.attributes objectForKey:@"height"] doubleValue]
}
};
} else if (CGRectIsNull(p.patternBounds)) {
p.patternBounds = p.bounds;
}
if ([node.attributes objectForKey:@"patternTransform"]) {
p.patternTransform = CATransform3DConcat(p.patternTransform, [pxSVGObject transformFromString:[node.attributes objectForKey:@"patternTransform"]]);
}
[self.defCache setObject:p forKey:pid];
return p;
}
- (pxSVGObject*)parseObject:(pxXMLNode*)node inheritAttributes:(pxSVGObject*)inherit
{
if ([node.tagName rangeOfString:@":"].location != NSNotFound) return nil;
if ([node.tagName isEqualToString:@"metadata"]) return nil;
if ([node.tagName isEqualToString:@"marker"]) return nil;
if ([node.tagName isEqualToString:@"filter"]) return nil;
if ([node.tagName isEqualToString:@"a"]) return nil;
if ([node.tagName isEqualToString:@"use"]) return [self reuseObjectWithAttributes:node.attributes];
if ([node.tagName isEqualToString:@"linearGradient"]) {
[self parseLinearGradient:node];
return nil;
}
if ([node.tagName isEqualToString:@"pattern"]) return [self parsePattern:node];;
Class objClass = pxSVGObject.class;
if ([node.tagName isEqualToString:@"g"])
objClass = pxSVGGroup.class;
else if ([node.tagName isEqualToString:@"svg"])
objClass = pxSVGGroup.class;
else if ([node.tagName isEqualToString:@"clipPath"])
objClass = pxSVGGroup.class;
else if ([node.tagName isEqualToString:@"defs"])
objClass = pxSVGGroup.class;
else if ([node.tagName isEqualToString:@"path"])
objClass = pxSVGPath.class;
else if ([node.tagName isEqualToString:@"polygon"])
objClass = pxSVGPath.class;
else if ([node.tagName isEqualToString:@"ellipse"])
objClass = pxSVGPath.class;
else if ([node.tagName isEqualToString:@"circle"])
objClass = pxSVGPath.class;
else if ([node.tagName isEqualToString:@"rect"])
objClass = pxSVGPath.class;
else NSLog(@"Unknown tag: %@",node.tagName);
pxSVGObject *obj = [objClass new];
[obj loadAttributes:node.attributes];
if (!obj.fillColor)
obj.fillColor = inherit?inherit.fillColor:[UIColor blackColor];
if (isnan(obj.strokeWidth))
obj.strokeWidth = inherit?inherit.strokeWidth:0;
if (isnan(obj.fillOpacity))
obj.fillOpacity = inherit?inherit.fillOpacity:1;
if (!obj.strokeColor)
obj.strokeColor = inherit?inherit.strokeColor:nil;
if (obj.id) [self.defCache setObject:obj forKey:obj.id];
if (obj.fillDef) [self findDef:obj.fillDef];
if (obj.clipDef) [self findDef:obj.clipDef];
if (node.childNodes.count) {
NSMutableArray *subnodes = [NSMutableArray new];
for (pxXMLNode *n in node.childNodes) {
pxSVGObject *o = [self parseObject:n inheritAttributes:obj];
if (o && ![n.tagName isEqualToString:@"defs"] && ![n.tagName isEqualToString:@"clipPath"]) {
[subnodes addObject:o];
}
}
[obj setSubnodes:[NSArray arrayWithArray:subnodes]];
}
return obj;
}
- (UIBezierPath*)mergePath:(pxSVGObject*)node
{
UIBezierPath *bp = [UIBezierPath new];
if ([node respondsToSelector:@selector(d)]) {
[bp appendPath:[(id)node d]];
}
if ([node respondsToSelector:@selector(subnodes)]) {
for (pxSVGObject *o in [(id)node subnodes]) {
[bp appendPath:[self mergePath:o]];
}
}
return bp;
}
- (void)clipLayer:(CALayer*)layer byPath:(UIBezierPath*)path
{
if ([layer isKindOfClass:[CAShapeLayer class]]) {
CAShapeLayer *ml = [CAShapeLayer layer];
ml.path = path.CGPath;
layer.mask = ml;
}
for (CALayer *l in [layer.sublayers copy]) {
[self clipLayer:l byPath:path];
}
}
- (CALayer *)makeLayerWithNode:(pxSVGObject*)node rootBounds:(CGRect)bounds;
{
CALayer *l;
if ([node respondsToSelector:@selector(d)]) {
CAShapeLayer *sl = [CAShapeLayer layer];
UIBezierPath *p = [(id)node d];
sl.path = p.CGPath;
if (node.fillDef) {
sl.fillColor = [UIColor clearColor].CGColor;
id def = [self findDef:node.fillDef];
if ([def isKindOfClass:[pxSVGGradient class]]) {
pxSVGGradientLayer *gl = [pxSVGGradientLayer layer];
gl.frame = p.bounds;
gl.startPoint = (CGPoint){([def startPoint].x-gl.frame.origin.x)/gl.frame.size.width,([def startPoint].y-gl.frame.origin.y)/gl.frame.size.height};
gl.endPoint = (CGPoint){([def endPoint].x-gl.frame.origin.x)/gl.frame.size.width,([def endPoint].y-gl.frame.origin.y)/gl.frame.size.height};
gl.locations = [def locations];
gl.colors = [def colors];
gl.opacity = isnan(node.fillOpacity)?1:node.fillOpacity;
gl.clipPath = p;
[sl addSublayer:gl];
}
if ([def isKindOfClass:[pxSVGPattern class]]) {
pxSVGPatternLayer *tl = [pxSVGPatternLayer layer];
CALayer *pl = [self makeLayerWithNode:def rootBounds:[def patternBounds]];
tl.patternLayer = pl;
tl.patternTransform = CATransform3DTranslate([def patternTransform],p.bounds.origin.x,p.bounds.origin.y,0);
tl.frame = p.bounds;
tl.opacity = isnan(node.fillOpacity)?1:node.fillOpacity;
tl.clipPath = p;
[sl addSublayer:tl];
}
} else
sl.fillColor = [(node.fillColor?:[UIColor blackColor]) colorWithAlphaComponent:isnan(node.fillOpacity)?1:node.fillOpacity].CGColor;
sl.strokeColor = node.strokeColor.CGColor;
sl.lineWidth = isnan(node.strokeWidth)?0:node.strokeWidth;
l = sl;
} else {
l = [CALayer layer];
}
l.frame = (CGRect){{-bounds.origin.x,-bounds.origin.y},bounds.size};
l.opacity = node.opacity;
if ([node respondsToSelector:@selector(subnodes)]) {
for (pxSVGObject *n in [(id)node subnodes]) {
CALayer *sl = [self makeLayerWithNode:n rootBounds:l.bounds];
if ([l respondsToSelector:@selector(clipPath)] && [sl respondsToSelector:@selector(clipPath)])
[(id)sl setClipPath:[(id)l clipPath]];
if (sl) [l addSublayer:sl];
}
}
if (node.clipDef) {
id def = [self findDef:node.clipDef];
if ([def isKindOfClass:[pxSVGObject class]]) {
if ([l respondsToSelector:@selector(clipPath)])
[(id)l setClipPath:[self mergePath:def]];
else
[self clipLayer:l byPath:[self mergePath:def]];
}
}
CATransform3D tr = node.transform;
tr = CATransform3DConcat(CATransform3DMakeTranslation( bounds.size.width/2, bounds.size.height/2, 0), tr);
tr = CATransform3DConcat(tr, CATransform3DMakeTranslation(-bounds.size.width/2, -bounds.size.height/2, 0));
l.transform = tr;
bounds.origin = CGPointZero;
return l;
}
- (CALayer *)makeLayer
{
return [self makeLayerWithNode:self.root rootBounds:self.bounds];
}
@end