Skip to content

Commit

Permalink
Layer creation refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed May 15, 2015
1 parent 1b03714 commit 125ceff
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions pxSVG/pxSVGRenderPath.m
Expand Up @@ -43,7 +43,7 @@ @implementation pxSVGPatternLayer

+ (instancetype)layer
{
return [self new];
return [super layer];
}

- (instancetype)init
Expand Down Expand Up @@ -421,35 +421,35 @@ - (CALayer *)makeLayerWithNode:(pxSVGObject*)node rootBounds:(CGRect)bounds;
{
CALayer *l;
if ([node respondsToSelector:@selector(d)]) {
CAShapeLayer *sl = [CAShapeLayer new];
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]]) {
CAGradientLayer *gl = [CAGradientLayer new];
CAGradientLayer *gl = [CAGradientLayer 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;
CAShapeLayer *ml = [CAShapeLayer new];
ml.frame = (CGRect){{-p.bounds.origin.x,-p.bounds.origin.y},{p.bounds.size.width+p.bounds.origin.x,p.bounds.size.height+p.bounds.origin.y}};
CAShapeLayer *ml = [CAShapeLayer layer];
ml.frame = (CGRect){{-p.bounds.origin.x,-p.bounds.origin.y},{ceil(p.bounds.size.width+p.bounds.origin.x),ceil(p.bounds.size.height+p.bounds.origin.y)}};
ml.path = sl.path;
gl.mask = ml;
[sl addSublayer:gl];
}
if ([def isKindOfClass:[pxSVGPattern class]]) {
pxSVGPatternLayer *tl = [pxSVGPatternLayer new];
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;
CAShapeLayer *ml = [CAShapeLayer new];
ml.frame = (CGRect){{-p.bounds.origin.x,-p.bounds.origin.y},{p.bounds.size.width+p.bounds.origin.x,p.bounds.size.height+p.bounds.origin.y}};
CAShapeLayer *ml = [CAShapeLayer layer];
ml.frame = (CGRect){{-p.bounds.origin.x,-p.bounds.origin.y},{ceil(p.bounds.size.width+p.bounds.origin.x),ceil(p.bounds.size.height+p.bounds.origin.y)}};
ml.path = sl.path;
tl.mask = ml;
[sl addSublayer:tl];
Expand All @@ -460,14 +460,15 @@ - (CALayer *)makeLayerWithNode:(pxSVGObject*)node rootBounds:(CGRect)bounds;
sl.lineWidth = isnan(node.strokeWidth)?0:node.strokeWidth;
l = sl;
} else {
l = [CALayer new];
l = [CALayer layer];
}
if (node.clipDef) {
id def = [self findDef:node.clipDef];
if ([def isKindOfClass:[pxSVGObject class]]) {
CAShapeLayer *ml = [CAShapeLayer new];
ml.frame = (CGRect){CGPointZero,bounds.size};
ml.path = [self mergePath:def].CGPath;
UIBezierPath *bp = [self mergePath:def];
CAShapeLayer *ml = [CAShapeLayer layer];
ml.frame = (CGRect){CGPointZero,{ceil(bp.bounds.size.width),ceil(bp.bounds.size.height)}};
ml.path = bp.CGPath;
l.mask = ml;
}
}
Expand Down

0 comments on commit 125ceff

Please sign in to comment.