Commit ef0aea3a authored by Yury Popov's avatar Yury Popov

SVG bounds calculation

parent 71cec955
......@@ -24,6 +24,7 @@
- (instancetype)initWithXML:(pxXMLNode *)xmlNode
{
self = [super init];
self.root = [self parseObject:xmlNode];
if ([xmlNode.attributes objectForKey:@"width"] &&
[xmlNode.attributes objectForKey:@"height"]) {
CGPoint o = CGPointZero;
......@@ -52,11 +53,25 @@
}
};
} 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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment