refactor methods into root class
This commit is contained in:
@@ -198,4 +198,7 @@ void IJSVGAssertPaintableObject(id object);
|
||||
- (BOOL)matchesTraits:(IJSVGNodeTraits)traits;
|
||||
- (void)computeTraits;
|
||||
|
||||
- (instancetype)parentNodeMatchingClass:(Class)class;
|
||||
- (instancetype)rootNodeMatchingClass:(Class)class;
|
||||
|
||||
@end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user