From 1b31385bf81ecc6417fbc0b1a3981971ff7d5b18 Mon Sep 17 00:00:00 2001 From: Yury Popov Date: Thu, 14 May 2015 17:05:25 +0300 Subject: [PATCH] Reused objects fill override support --- pxSVG/pxSVGRenderPath.m | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pxSVG/pxSVGRenderPath.m b/pxSVG/pxSVGRenderPath.m index 302675f..47f6c78 100644 --- a/pxSVG/pxSVGRenderPath.m +++ b/pxSVG/pxSVGRenderPath.m @@ -153,12 +153,22 @@ - (pxSVGObject*)reuseObjectWithAttributes:(NSDictionary*)attributes pxSVGObject *oobj = [self findDef:href], *obj; if (!oobj) return nil; obj = [oobj.class new]; - obj.fillColor = oobj.fillColor; - obj.fillDef = oobj.fillDef; obj.strokeColor = oobj.strokeColor; obj.strokeWidth = oobj.strokeWidth; obj.opacity = oobj.opacity; obj.fillOpacity = oobj.fillOpacity; + obj.fillColor = oobj.fillColor; + obj.fillDef = oobj.fillDef; + if ([attributes objectForKey:@"fill"]) { + CGFloat a = obj.fillOpacity; + if ([[attributes objectForKey:@"fill"] hasPrefix:@"url("]) { + NSString *u = [[attributes objectForKey:@"fill"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + u = [[u substringWithRange:NSMakeRange(3, u.length-4)] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\n\r\t ()#"]]; + obj.fillDef = u; + } else obj.fillColor = [pxSVGObject colorWithSVGColor:[attributes objectForKey:@"fill"]]; + if (obj.fillColor) [obj.fillColor getWhite:nil alpha:&a]; + obj.fillOpacity = [attributes objectForKey:@"fill-opacity"]?[[attributes objectForKey:@"fill-opacity"] doubleValue]:a; + } if ([oobj respondsToSelector:@selector(d)]) [(id)obj setD:[(id)oobj d]]; if ([oobj respondsToSelector:@selector(subnodes)]) @@ -339,6 +349,8 @@ - (pxSVGObject*)parseObject:(pxXMLNode*)node inheritAttributes:(pxSVGObject*)inh objClass = pxSVGGroup.class; else if ([node.tagName isEqualToString:@"svg"]) objClass = pxSVGGroup.class; + else if ([node.tagName isEqualToString:@"clipPath"]) + objClass = pxSVGGroup.class; else if ([node.tagName isEqualToString:@"defs"]) objClass = pxSVGGroup.class; else if ([node.tagName isEqualToString:@"path"]) @@ -367,7 +379,7 @@ - (pxSVGObject*)parseObject:(pxXMLNode*)node inheritAttributes:(pxSVGObject*)inh NSMutableArray *subnodes = [NSMutableArray new]; for (pxXMLNode *n in node.childNodes) { pxSVGObject *o = [self parseObject:n inheritAttributes:obj]; - if (o && ![n.tagName isEqualToString:@"defs"]) { + if (o && ![n.tagName isEqualToString:@"defs"] && ![n.tagName isEqualToString:@"clipPath"]) { [subnodes addObject:o]; } }