Skip to content

Commit

Permalink
SVG bounds calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Popov authored and Yury Popov committed May 12, 2015
1 parent 71cec95 commit ef0aea3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pxSVG/pxSVGRenderPath.m
Expand Up @@ -24,6 +24,7 @@ + (instancetype)pathWithXML:(pxXMLNode *)xmlNode
- (instancetype)initWithXML:(pxXMLNode *)xmlNode
{
self = [super init];
self.root = [self parseObject:xmlNode];
if ([xmlNode.attributes objectForKey:@"width"] &&
[xmlNode.attributes objectForKey:@"height"]) {
CGPoint o = CGPointZero;
Expand Down Expand Up @@ -52,11 +53,25 @@ - (instancetype)initWithXML:(pxXMLNode *)xmlNode
}
};
} else {
self.bounds = CGRectNull;
self.bounds = [self objBounds:self.root];
}
self.root = [self parseObject:xmlNode];
return self;
}
- (CGRect) objBounds:(pxSVGObject*)obj
{
if ([obj respondsToSelector:@selector(d)]) {
UIBezierPath *path = [(id)obj d];
if (path) return CGRectApplyAffineTransform(path.bounds, CATransform3DGetAffineTransform(obj.transform));
}
if ([obj respondsToSelector:@selector(subnodes)]) {
CGRect f = CGRectNull;
for (pxSVGObject *o in [(id)obj subnodes]) {
f = CGRectUnion(f, [self objBounds:o]);
}
return CGRectApplyAffineTransform(f, CATransform3DGetAffineTransform(obj.transform));
}
return CGRectNull;
}
- (pxSVGObject*)parseObject:(pxXMLNode*)node
{
if ([node.tagName rangeOfString:@":"].location != NSNotFound) return nil;
Expand Down

0 comments on commit ef0aea3

Please sign in to comment.