Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yury Popov
authored and
Yury Popov
committed
May 12, 2015
1 parent
1dc3293
commit 71cec95
Showing
8 changed files
with
432 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// pxSVGGroup.h | ||
// pxSVG | ||
// | ||
// Created by Yury Popov on 12.05.15. | ||
// Copyright (c) 2015 PhoeniX. All rights reserved. | ||
// | ||
|
||
#import "pxSVGObject.h" | ||
|
||
@interface pxSVGGroup : pxSVGObject | ||
@property NSArray *subnodes; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// pxSVGGroup.m | ||
// pxSVG | ||
// | ||
// Created by Yury Popov on 12.05.15. | ||
// Copyright (c) 2015 PhoeniX. All rights reserved. | ||
// | ||
|
||
#import "pxSVGGroup.h" | ||
|
||
@implementation pxSVGGroup | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// pxSVGObject.h | ||
// pxSVG | ||
// | ||
// Created by Yury Popov on 12.05.15. | ||
// Copyright (c) 2015 PhoeniX. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface pxSVGObject : NSObject | ||
- (void) loadAttributes:(NSDictionary*)attributes; | ||
- (void) setSubnodes:(NSArray*)subnodes; | ||
@property NSString *id; | ||
@property NSArray *animations; | ||
@property UIColor *fillColor; | ||
@property UIColor *strokeColor; | ||
@property CGFloat strokeWidth; | ||
@property CGFloat opacity; | ||
@property CATransform3D transform; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// | ||
// pxSVGObject.m | ||
// pxSVG | ||
// | ||
// Created by Yury Popov on 12.05.15. | ||
// Copyright (c) 2015 PhoeniX. All rights reserved. | ||
// | ||
|
||
#import "pxSVGObject.h" | ||
|
||
@implementation pxSVGObject | ||
+ (CATransform3D) transformFromString:(NSString*)string | ||
{ | ||
CATransform3D tr = CATransform3DIdentity; | ||
if (!string.length) return tr; | ||
NSScanner *sc = [NSScanner scannerWithString:string]; | ||
sc.charactersToBeSkipped = [NSCharacterSet whitespaceAndNewlineCharacterSet]; | ||
NSString *op; double p[6]; int i; | ||
while (!sc.atEnd) { | ||
[sc scanUpToString:@"(" intoString:&op]; | ||
[sc scanString:@"(" intoString:nil]; | ||
i=0; | ||
while ([sc scanDouble:&p[i++]]) [sc scanCharactersFromSet:[NSCharacterSet characterSetWithCharactersInString:@" ,"] intoString:nil]; | ||
i--; | ||
[sc scanString:@")" intoString:nil]; | ||
|
||
if ([op isEqualToString:@"scale"]) { | ||
switch (i) { | ||
case 1: | ||
tr = CATransform3DScale(tr, p[0], p[0], 1); | ||
break; | ||
case 2: | ||
tr = CATransform3DScale(tr, p[0], p[1], 1); | ||
break; | ||
default: NSLog(@"Invalid number of operands for %@: %@",op,@(i)); break; | ||
} | ||
} else if ([op isEqualToString:@"translate"]) { | ||
switch (i) { | ||
case 1: | ||
tr = CATransform3DTranslate(tr, p[0], 0, 0); | ||
break; | ||
case 2: | ||
tr = CATransform3DTranslate(tr, p[0], p[1], 0); | ||
break; | ||
default: NSLog(@"Invalid number of operands for %@: %@",op,@(i)); break; | ||
} | ||
} else if ([op isEqualToString:@"matrix"]) { | ||
switch (i) { | ||
case 6: | ||
tr = CATransform3DConcat(tr, CATransform3DMakeAffineTransform(CGAffineTransformMake(p[0], p[1], p[2], p[3], p[4], p[5]))); | ||
break; | ||
default: NSLog(@"Invalid number of operands for %@: %@",op,@(i)); break; | ||
} | ||
} else { | ||
NSLog(@"Unknown transform: %@",op); | ||
} | ||
} | ||
return tr; | ||
} | ||
- (UIColor*) colorWithSVGColor:(NSString*)string | ||
{ | ||
if (!string) return nil; | ||
string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; | ||
if ([string isEqualToString:@"none"]) return nil; | ||
if ([string isEqualToString:@"black"]) return [UIColor blackColor]; | ||
if ([string isEqualToString:@"white"]) return [UIColor whiteColor]; | ||
NSScanner *sc = [NSScanner scannerWithString:[string lowercaseString]]; | ||
if ([sc scanString:@"#" intoString:nil]) { | ||
unsigned int cl; | ||
[sc scanHexInt:&cl]; | ||
float r,g,b; | ||
switch (string.length) { | ||
case 4: | ||
b = (cl & 0xF)<<4; cl >>= 4; | ||
g = (cl & 0xF)<<4; cl >>= 4; | ||
r = (cl & 0xF)<<4; cl >>= 4; | ||
break; | ||
case 7: | ||
b = cl & 0xFF; cl >>= 8; | ||
g = cl & 0xFF; cl >>= 8; | ||
r = cl & 0xFF; cl >>= 8; | ||
break; | ||
|
||
default: | ||
NSLog(@"Invalid hex color: %@",string); | ||
return nil; | ||
} | ||
r /= 255.f; | ||
g /= 255.f; | ||
b /= 255.f; | ||
return [UIColor colorWithRed:r green:g blue:b alpha:1]; | ||
} | ||
NSLog(@"Unknown color: %@",string); | ||
return nil; | ||
} | ||
- (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"] doubleValue]; | ||
self.transform = [self.class transformFromString:[attributes objectForKey:@"transform"]]; | ||
self.opacity = [[attributes objectForKey:@"opacity"] doubleValue]; | ||
} | ||
- (void)setSubnodes:(NSArray *)subnodes { } | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// pxSVGPath.h | ||
// pxSVG | ||
// | ||
// Created by Yury Popov on 12.05.15. | ||
// Copyright (c) 2015 PhoeniX. All rights reserved. | ||
// | ||
|
||
#import "pxSVGObject.h" | ||
|
||
@interface pxSVGPath : pxSVGObject | ||
@property UIBezierPath *d; | ||
@end |
Oops, something went wrong.