Permalink
Browse files

merging in changes from @adamgit

  • Loading branch information...
2 parents fea5874 + 0d3dba3 commit 143fde2935db830e3db97bec6bfbdebcc2ad0cbc @reklis reklis committed Dec 5, 2011
Showing with 1,769 additions and 1,229 deletions.
  1. +6 −0 Core/CGPathAdditions.h
  2. +1 −1 Core/SVGDocument+CA.m
  3. +5 −1 Core/SVGDocument.h
  4. +24 −4 Core/SVGDocument.m
  5. +20 −3 Core/SVGElement.h
  6. +19 −1 Core/SVGElement.m
  7. 0 Core/SVGGroupElement.h
  8. +19 −9 Core/SVGGroupElement.m
  9. +5 −2 Core/SVGImageElement.m
  10. +18 −1 Core/SVGParser.h
  11. +68 −107 Core/SVGParser.m
  12. +9 −0 Core/SVGParserSVG.h
  13. +164 −0 Core/SVGParserSVG.m
  14. 0 Core/SVGPathElement.m
  15. +6 −0 Core/SVGPattern.h
  16. +18 −16 Core/SVGShapeElement.m
  17. +1 −1 Core/SVGTextElement.m
  18. +6 −0 Core/SVGUtils.h
  19. +54 −4 README.mdown
  20. +0 −499 SVGKit.xcodeproj/project.pbxproj
  21. +0 −36 SVGPad/Classes/CALayerExporter.h
  22. +0 −283 SVGPad/Classes/CALayerExporter.m
  23. +0 −7 SVGPad/SVGPad.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  24. 0 { → XCodeProjects/SVGKit}/Info.plist
  25. +790 −0 XCodeProjects/SVGKit/SVGKit.xcodeproj/project.pbxproj
  26. +7 −0 XCodeProjects/SVGKit/SVGKitLibrary/SVGKitLibrary-Prefix.pch
  27. 0 { → XCodeProjects/SVGKit}/SVGKit_Prefix.pch
  28. 0 {SVGPad → XCodeProjects/SVGPadDemo}/Classes/DetailViewController.h
  29. 0 {SVGPad → XCodeProjects/SVGPadDemo}/Classes/DetailViewController.m
  30. 0 {SVGPad → XCodeProjects/SVGPadDemo}/Classes/RootViewController.h
  31. 0 {SVGPad → XCodeProjects/SVGPadDemo}/Classes/RootViewController.m
  32. 0 {SVGPad → XCodeProjects/SVGPadDemo}/Classes/SVGPadAppDelegate.h
  33. 0 {SVGPad → XCodeProjects/SVGPadDemo}/Classes/SVGPadAppDelegate.m
  34. 0 {SVGPad → XCodeProjects/SVGPadDemo}/DetailView.xib
  35. 0 {SVGPad → XCodeProjects/SVGPadDemo}/MainWindow.xib
  36. 0 {SVGPad → XCodeProjects/SVGPadDemo}/SVGPad-Info.plist
  37. +226 −193 {SVGPad → XCodeProjects/SVGPadDemo}/SVGPad.xcodeproj/project.pbxproj
  38. 0 {SVGPad → XCodeProjects/SVGPadDemo}/SVGPad_Prefix.pch
  39. 0 {SVGPad → XCodeProjects/SVGPadDemo}/main.m
  40. 0 {SVGTester → XCodeProjects/SVGTesterDemo}/Classes/ComparisonView.h
  41. 0 {SVGTester → XCodeProjects/SVGTesterDemo}/Classes/ComparisonView.m
  42. 0 {SVGTester → XCodeProjects/SVGTesterDemo}/Classes/MainWindowController.h
  43. 0 {SVGTester → XCodeProjects/SVGTesterDemo}/Classes/MainWindowController.m
  44. 0 {SVGTester → XCodeProjects/SVGTesterDemo}/Classes/SVGTesterAppDelegate.h
  45. 0 {SVGTester → XCodeProjects/SVGTesterDemo}/Classes/SVGTesterAppDelegate.m
  46. 0 {SVGTester → XCodeProjects/SVGTesterDemo}/SVGTester-Info.plist
  47. 0 {SVGTester → XCodeProjects/SVGTesterDemo}/SVGTester-Prefix.pch
  48. +95 −60 {SVGTester → XCodeProjects/SVGTesterDemo}/SVGTester.xcodeproj/project.pbxproj
  49. 0 {SVGTester → XCodeProjects/SVGTesterDemo}/en.lproj/MainMenu.xib
  50. 0 {SVGTester → XCodeProjects/SVGTesterDemo}/en.lproj/MainWindow.xib
  51. 0 {SVGTester → XCodeProjects/SVGTesterDemo}/main.m
  52. +22 −0 iOS/CALayerWithChildHitTest.h
  53. +36 −0 iOS/CALayerWithChildHitTest.m
  54. +24 −0 iOS/CAShapeLayerWithHitTest.h
  55. +27 −0 iOS/CAShapeLayerWithHitTest.m
  56. +22 −0 iOS/SVGDocumentView.h
  57. +74 −0 iOS/SVGDocumentView.m
  58. +1 −1 iOS/SVGPathView.m
  59. +2 −0 iOS/SVGView.h
View
@@ -5,4 +5,10 @@
// Copyright Matt Rajca 2011. All rights reserved.
//
+#if TARGET_OS_IPHONE
+
+#import <UIKit/UIKit.h>
+
+#endif
+
CGPathRef CGPathCreateByOffsettingPath (CGPathRef aPath, CGFloat x, CGFloat y);
View
@@ -44,7 +44,7 @@ - (CALayer *)layerTree {
}
- (CALayer *)layerWithElement:(SVGElement <SVGLayeredElement> *)element {
- CALayer *layer = [element layer];
+ CALayer *layer = [element newLayer];
if (![element.children count]) {
return layer;
View
6 Core/SVGDocument.h 100755 → 100644
@@ -9,13 +9,16 @@
#import "SVGGroupElement.h"
+#import "SVGParser.h"
+
#if NS_BLOCKS_AVAILABLE
typedef void (^SVGElementAggregationBlock)(SVGElement < SVGLayeredElement > * layeredElement);
#endif
@class SVGDefsElement;
-@interface SVGDocument : SVGElement < SVGLayeredElement > { }
+@interface SVGDocument : SVGElement < SVGLayeredElement > {
+}
// only absolute widths and heights are supported (no percentages)
@property (nonatomic, readonly) CGFloat width;
@@ -30,6 +33,7 @@ typedef void (^SVGElementAggregationBlock)(SVGElement < SVGLayeredElement > * la
/*! from the SVG spec, each "g" tag in the XML is a separate "group of graphics things" */
@property (nonatomic, retain) NSDictionary *graphicsGroups;
++ (void) addSVGParserExtension:(NSObject<SVGParserExtension>*) extension;
+ (id)documentNamed:(NSString *)name; // 'name' in mainBundle
+ (id)documentWithContentsOfFile:(NSString *)aPath;
View
28 Core/SVGDocument.m 100755 → 100644
@@ -14,6 +14,8 @@
#import "SVGTitleElement.h"
#import "SVGPathElement.h"
+#import "SVGParserSVG.h"
+
@interface SVGDocument ()
@property (nonatomic, copy) NSString *version;
@@ -35,6 +37,17 @@ @implementation SVGDocument
@dynamic title, desc, defs;
+static NSMutableArray* _parserExtensions;
++ (void) addSVGParserExtension:(NSObject<SVGParserExtension>*) extension
+{
+ if( _parserExtensions == nil )
+ {
+ _parserExtensions = [[NSMutableArray array] retain];
+ }
+
+ [_parserExtensions addObject:extension];
+}
+
/* TODO: parse 'viewBox' */
+ (id)documentNamed:(NSString *)name {
@@ -102,6 +115,12 @@ - (BOOL)parseFileAtPath:(NSString *)aPath {
NSError *error = nil;
SVGParser *parser = [[SVGParser alloc] initWithPath:aPath document:self];
+ SVGParserSVG *subParserSVG = [[[SVGParserSVG alloc] init] autorelease];
+ [parser.parserExtensions addObject:subParserSVG];
+ for( NSObject<SVGParserExtension>* extension in _parserExtensions )
+ {
+ [parser.parserExtensions addObject:extension];
+ }
if (![parser parse:&error]) {
NSLog(@"Parser error: %@", error);
@@ -115,11 +134,12 @@ - (BOOL)parseFileAtPath:(NSString *)aPath {
return YES;
}
-- (CALayer *)layer {
- CALayer *layer = [CALayer layer];
- layer.frame = CGRectMake(0.0f, 0.0f, _width, _height);
+- (CALayer *)newLayer {
+
+ CALayer* _layer = [[CALayer layer] retain];
+ _layer.frame = CGRectMake(0.0f, 0.0f, _width, _height);
- return layer;
+ return _layer;
}
- (void)layoutLayer:(CALayer *)layer { }
View
@@ -14,26 +14,43 @@
NSMutableArray *_children;
}
-@property (nonatomic, readonly) __weak SVGDocument *document;
+/*! This is used when generating CALayer objects, to store the id of the SVGElement that created the CALayer */
+#define kSVGElementIdentifier @"SVGElementIdentifier"
+
+#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
+@property (nonatomic, readonly) SVGDocument *document;
+#else
+@property (nonatomic, readonly) __weak SVGDocument *document;
+#endif
@property (nonatomic, readonly) NSArray *children;
@property (nonatomic, readonly, copy) NSString *stringValue;
@property (nonatomic, readonly) NSString *localName;
@property (nonatomic, readwrite, retain) NSString *identifier; // 'id' is reserved
+@property (nonatomic, retain) NSMutableArray* metadataChildren;
+
+ (BOOL)shouldStoreContent; // to optimize parser, default is NO
- (id)initWithDocument:(SVGDocument *)aDocument name:(NSString *)name;
- (void)loadDefaults; // should be overriden to set element defaults
-@end
+/*! Parser uses this to add non-rendering-SVG XML tags to the element they were embedded in */
+- (void) addMetadataChild:(NSObject*) child;
+@end
@protocol SVGLayeredElement < NSObject >
-- (CALayer *)layer;
+/*!
+ NB: the returned layer has - as its "name" property - the "identifier" property of the SVGElement that created it;
+ but that can be overwritten by applications (for valid reasons), so we ADDITIONALLY store the identifier into a
+ custom key - kSVGElementIdentifier - on the CALayer. Because it's a custom key, it's (almost) guaranteed not to be
+ overwritten / altered by other application code
+ */
+- (CALayer *)newLayer;
- (void)layoutLayer:(CALayer *)layer;
@end
View
20 Core/SVGElement.m 100755 → 100644
@@ -13,7 +13,16 @@ @interface SVGElement ()
@end
-
+/*! main class implementation for the base SVGElement: NOTE: in practice, most of the interesting
+ stuff happens in subclasses, e.g.:
+
+ SVGShapeElement
+ SVGGroupElement
+ SVGImageElement
+ SVGLineElement
+ SVGPathElement
+ ...etc
+ */
@implementation SVGElement
@synthesize document = _document;
@@ -24,6 +33,8 @@ @implementation SVGElement
@synthesize identifier = _identifier;
+@synthesize metadataChildren;
+
+ (BOOL)shouldStoreContent {
return NO;
}
@@ -33,6 +44,7 @@ - (id)init {
if (self) {
[self loadDefaults];
_children = [[NSMutableArray alloc] init];
+ self.metadataChildren = [NSMutableArray array];
}
return self;
}
@@ -47,6 +59,7 @@ - (id)initWithDocument:(SVGDocument *)aDocument name:(NSString *)name {
}
- (void)dealloc {
+ self.metadataChildren = nil;
[_children release];
[_stringValue release];
[_localName release];
@@ -63,6 +76,11 @@ - (void)addChild:(SVGElement *)element {
[_children addObject:element];
}
+-(void) addMetadataChild:(NSObject*) child
+{
+ [self.metadataChildren addObject:child];
+}
+
- (void)parseAttributes:(NSDictionary *)attributes {
// to be overriden by subclasses
// make sure super implementation is called
View
0 Core/SVGGroupElement.h 100755 → 100644
No changes.
View
@@ -8,12 +8,19 @@
#import "SVGGroupElement.h"
#import "SVGDocument.h"
+
#import "SVGElement+Private.h"
+#import "CALayerWithChildHitTest.h"
@implementation SVGGroupElement
@synthesize opacity = _opacity;
+- (void)dealloc {
+
+ [super dealloc];
+}
+
- (void)loadDefaults {
_opacity = 1.0f;
}
@@ -28,17 +35,20 @@ - (void)parseAttributes:(NSDictionary *)attributes {
}
}
-- (CALayer *)layer {
- CALayer *layer = [CALayer layer];
- layer.name = self.identifier;
- layer.opacity = _opacity;
+- (CALayer *)newLayer {
- if ([layer respondsToSelector:@selector(setShouldRasterize:)]) {
- [layer performSelector:@selector(setShouldRasterize:)
- withObject:[NSNumber numberWithBool:YES]];
- }
+ CALayer* _layer = [[CALayerWithChildHitTest layer] retain];// [[CALayer layer] retain];
+
+ _layer.name = self.identifier;
+ [_layer setValue:self.identifier forKey:kSVGElementIdentifier];
+ _layer.opacity = _opacity;
+
+ if ([_layer respondsToSelector:@selector(setShouldRasterize:)]) {
+ [_layer performSelector:@selector(setShouldRasterize:)
+ withObject:[NSNumber numberWithBool:YES]];
+ }
- return layer;
+ return _layer;
}
- (void)layoutLayer:(CALayer *)layer {
View
@@ -10,6 +10,8 @@
#if TARGET_OS_IPHONE
+#import <UIKit/UIKit.h>
+
#else
#endif
@@ -80,10 +82,11 @@ - (void)parseAttributes:(NSDictionary *)attributes {
}
}
-- (CALayer *)layer {
- __block CALayer *layer = [CALayer layer];
+- (CALayer *)newLayer {
+ __block CALayer *layer = [[CALayer layer] retain];
layer.name = self.identifier;
+ [layer setValue:self.identifier forKey:kSVGElementIdentifier];
layer.frame = CGRectMake(_x, _y, _width, _height);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
View
19 Core/SVGParser.h 100755 → 100644
@@ -7,19 +7,36 @@
@class SVGDocument;
+@protocol SVGParserExtension <NSObject>
+-(BOOL) createdItemShouldStoreContent:(NSObject*) item;
+- (NSObject*)handleStartElement:(NSString *)name document:(SVGDocument*) document xmlns:(NSString*) prefix attributes:(NSMutableDictionary *)attributes;
+-(void) addChildObject:(NSObject*)child toObject:(NSObject*)parent;
+-(void) parseContent:(NSMutableString*) content forItem:(NSObject*) item;
+
+-(NSArray*) supportedNamespaces;
+-(NSArray*) supportedTags;
+@end
+
@interface SVGParser : NSObject {
@private
NSString *_path;
BOOL _failed;
BOOL _storingChars;
NSMutableString *_storedChars;
NSMutableArray *_elementStack;
+#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
+ SVGDocument *_document;
+#else
__weak SVGDocument *_document;
- NSMutableDictionary *_graphicsGroups;
+#endif
}
+@property(nonatomic,retain) NSMutableArray* parserExtensions;
+
- (id)initWithPath:(NSString *)aPath document:(SVGDocument *)document;
- (BOOL)parse:(NSError **)outError;
++(NSDictionary *) NSDictionaryFromCSSAttributes: (NSString *)css;
+
@end
Oops, something went wrong.

0 comments on commit 143fde2

Please sign in to comment.