From 52acb03aca8d2bae5719b77ccf9f8ab1d7675a18 Mon Sep 17 00:00:00 2001 From: Yury Popov Date: Wed, 13 May 2015 15:01:26 +0300 Subject: [PATCH] SVG style parser fix --- pxSVG/pxSVGObject.m | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pxSVG/pxSVGObject.m b/pxSVG/pxSVGObject.m index a37dc19..e1ff1d8 100644 --- a/pxSVG/pxSVGObject.m +++ b/pxSVG/pxSVGObject.m @@ -92,12 +92,22 @@ - (UIColor*) colorWithSVGColor:(NSString*)string } - (void)loadAttributes:(NSDictionary *)attributes { - self.id = [attributes objectForKey:@"id"]; - self.fillColor = [self colorWithSVGColor:[attributes objectForKey:@"fill"]]; - self.strokeColor = [self colorWithSVGColor:[attributes objectForKey:@"stroke"]]; - self.strokeWidth = [attributes objectForKey:@"stroke-width"]?[[attributes objectForKey:@"stroke-width"] doubleValue]:NAN; - self.transform = [self.class transformFromString:[attributes objectForKey:@"transform"]]; - self.opacity = [attributes objectForKey:@"opacity"]?[[attributes objectForKey:@"opacity"] doubleValue]:1; + NSMutableDictionary *ma = [attributes mutableCopy]; + if ([attributes objectForKey:@"style"]) { + for (NSString *s in [[attributes objectForKey:@"style"] componentsSeparatedByString:@";"]) { + NSUInteger sep = [s rangeOfString:@":"].location; + if (sep == NSNotFound) continue; + NSString *k = [[s substringToIndex:sep] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *v = [[s substringFromIndex:sep+1] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + [ma setObject:v forKey:k]; + } + } + self.id = [ma objectForKey:@"id"]; + self.fillColor = [self colorWithSVGColor:[ma objectForKey:@"fill"]]; + self.strokeColor = [self colorWithSVGColor:[ma objectForKey:@"stroke"]]; + self.strokeWidth = [ma objectForKey:@"stroke-width"]?[[ma objectForKey:@"stroke-width"] doubleValue]:NAN; + self.transform = [self.class transformFromString:[ma objectForKey:@"transform"]]; + self.opacity = [ma objectForKey:@"opacity"]?[[ma objectForKey:@"opacity"] doubleValue]:1; } - (void)setSubnodes:(NSArray *)subnodes { } @end