diff --git a/Framework/IJSVG/IJSVG/Source/Nodes/IJSVGNode.h b/Framework/IJSVG/IJSVG/Source/Nodes/IJSVGNode.h index 5bc20ad..e6156b7 100644 --- a/Framework/IJSVG/IJSVG/Source/Nodes/IJSVGNode.h +++ b/Framework/IJSVG/IJSVG/Source/Nodes/IJSVGNode.h @@ -198,4 +198,7 @@ void IJSVGAssertPaintableObject(id object); - (BOOL)matchesTraits:(IJSVGNodeTraits)traits; - (void)computeTraits; +- (instancetype)parentNodeMatchingClass:(Class)class; +- (instancetype)rootNodeMatchingClass:(Class)class; + @end diff --git a/Framework/IJSVG/IJSVG/Source/Nodes/IJSVGNode.m b/Framework/IJSVG/IJSVG/Source/Nodes/IJSVGNode.m index 3252693..a9fa219 100644 --- a/Framework/IJSVG/IJSVG/Source/Nodes/IJSVGNode.m +++ b/Framework/IJSVG/IJSVG/Source/Nodes/IJSVGNode.m @@ -507,4 +507,31 @@ return (IJSVGRootNode*)parent; } +- (instancetype)parentNodeMatchingClass:(Class)class +{ + IJSVGNode* parent = self.parentNode; + if([parent isKindOfClass:class] == YES) { + return parent; + } + return [parent parentNodeMatchingClass:class]; +} + +- (instancetype)rootNodeMatchingClass:(Class)class +{ + IJSVGRootNode* rootNode = self.rootNode; + IJSVGNode* parentNode = self.parentNode; + IJSVGNode* foundNode = nil; + while(parentNode != nil) { + // break on root node or if its matching + if(parentNode == rootNode || parentNode == nil) { + break; + } + if([parentNode isKindOfClass:class] == YES) { + foundNode = parentNode; + } + parentNode = parentNode.parentNode; + } + return foundNode; +} + @end diff --git a/Framework/IJSVG/IJSVG/Source/Nodes/IJSVGPattern.m b/Framework/IJSVG/IJSVG/Source/Nodes/IJSVGPattern.m index 8fbef81..62cdf65 100644 --- a/Framework/IJSVG/IJSVG/Source/Nodes/IJSVGPattern.m +++ b/Framework/IJSVG/IJSVG/Source/Nodes/IJSVGPattern.m @@ -22,25 +22,6 @@ return self; } -- (IJSVGPattern*)rootPattern -{ - IJSVGRootNode* rootNode = self.rootNode; - IJSVGNode* parentNode = self.parentNode; - IJSVGPattern* parentPattern = nil; - while(parentNode != nil) { - if(parentNode == rootNode || parentNode == nil) { - break; - } - // actual check the type, if it Pattern, just store - // reference to it and keep going up the chain - if([parentNode isKindOfClass:IJSVGPattern.class]) { - parentPattern = (IJSVGPattern*)parentNode; - } - parentNode = parentNode.parentNode; - } - return parentPattern; -} - - (IJSVGUnitType)contentUnitsWithReferencingNodeBounds:(CGRect*)bounds { // as far as I can tell, units are inherited, so we need to go to the root @@ -48,7 +29,7 @@ // units as the actual units, but the bounds are based on the units of current // units defined on this node... wtf?! IJSVGNode* node = nil; - IJSVGPattern* parentPattern = [self rootPattern]; + IJSVGPattern* parentPattern = [self rootNodeMatchingClass:self.class]; IJSVGUnitType units = [self contentUnitsWithReferencingNode:&node]; if(units == IJSVGUnitUserSpaceOnUse) { *bounds = node.rootNode.bounds;