123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- #import "SVGKParserSVG.h"
- #import "SVGSVGElement.h"
- #import "SVGCircleElement.h"
- #import "SVGClipPathElement.h"
- #import "SVGDefsElement.h"
- #import "SVGDescriptionElement.h"
- #import "SVGEllipseElement.h"
- #import "SVGGElement.h"
- #import "SVGImageElement.h"
- #import "SVGLineElement.h"
- #import "SVGPathElement.h"
- #import "SVGPolygonElement.h"
- #import "SVGPolylineElement.h"
- #import "SVGRectElement.h"
- #import "SVGSwitchElement.h"
- #import "SVGTitleElement.h"
- #import "SVGTextElement.h"
- #import "TinySVGTextAreaElement.h"
- #import "SVGDocument_Mutable.h"
- #import "SVGKDefine_Private.h"
- @interface SVGKParserSVG ()
- @property (nonatomic) NSArray *supportedNamespaces;
- @property (nonatomic) NSDictionary *elementMap;
- @end
- @implementation SVGKParserSVG
- - (NSDictionary *)elementMap {
- if (!_elementMap) {
- _elementMap = [NSDictionary dictionaryWithObjectsAndKeys:
- [SVGSVGElement class], @"svg",
- [SVGCircleElement class], @"circle",
- [SVGDescriptionElement class], @"description",
- [SVGEllipseElement class], @"ellipse",
- [SVGGElement class], @"g",
- [SVGClipPathElement class], @"clipPath",
- [SVGImageElement class], @"image",
- [SVGLineElement class], @"line",
- [SVGPathElement class], @"path",
- [SVGPolygonElement class], @"polygon",
- [SVGPolylineElement class], @"polyline",
- [SVGRectElement class], @"rect",
- [SVGSwitchElement class], @"switch",
- [SVGTitleElement class], @"title",
- [SVGTextElement class], @"text",
- [TinySVGTextAreaElement class], @"textArea",
- nil];
- }
- return _elementMap;
- }
- -(NSArray *)supportedNamespaces
- {
- if( _supportedNamespaces == nil )
- _supportedNamespaces = @[@"http://www.w3.org/2000/svg"];
- return _supportedNamespaces;
- }
- -(NSArray*) supportedTags
- {
- return [self.elementMap allKeys];
- }
- - (Node*) handleStartElement:(NSString *)name document:(SVGKSource*) SVGKSource namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary *)attributes parseResult:(SVGKParseResult *)parseResult parentNode:(Node*) parentNode
- {
- if( [[self supportedNamespaces] containsObject:XMLNSURI] )
- {
- Class elementClass = [self.elementMap objectForKey:name];
-
- if (!elementClass) {
- elementClass = [SVGElement class];
- SVGKitLogWarn(@"Support for '%@' element has not been implemented", name);
- }
-
-
-
-
- NSString* qualifiedName = (prefix == nil) ? name : [NSString stringWithFormat:@"%@:%@", prefix, name];
-
- SVGElement *element = [[elementClass alloc] initWithQualifiedName:qualifiedName inNameSpaceURI:XMLNSURI attributes:attributes];
-
-
- [element postProcessAttributesAddingErrorsTo:parseResult];
-
-
- if( [@"svg" isEqualToString:name] )
- {
- ((SVGSVGElement *) element).source = SVGKSource;
-
- NSString* svgVersion = nil;
-
-
-
- BOOL generateAnSVGDocument = FALSE;
- BOOL overwriteRootSVGDocument = FALSE;
- BOOL overwriteRootOfTree = FALSE;
-
- if( parentNode == nil )
- {
-
- generateAnSVGDocument = overwriteRootSVGDocument = overwriteRootOfTree = TRUE;
-
- }
- else if( parseResult.rootOfSVGTree == nil )
- {
-
- overwriteRootOfTree = TRUE;
- }
- else
- {
-
-
- }
-
-
- if( overwriteRootOfTree )
- {
- parseResult.rootOfSVGTree = (SVGSVGElement*) element;
-
-
- if ((svgVersion = [attributes objectForKey:@"version"])) {
- SVGKSource.svgLanguageVersion = svgVersion;
- }
- }
- if( generateAnSVGDocument )
- {
- NSAssert( [element isKindOfClass:[SVGSVGElement class]], @"Trying to create a new internal SVGDocument from a Node that is NOT of type SVGSVGElement (tag: svg). Node was of type: %@", NSStringFromClass([element class]));
-
- SVGDocument* newDocument = [[SVGDocument alloc] init];
- newDocument.rootElement = (SVGSVGElement*) element;
-
- if( overwriteRootSVGDocument )
- {
- parseResult.parsedDocument = newDocument;
- }
- else
- {
- NSAssert( FALSE, @"Currently not supported: multiple SVG Document nodes in a single SVG file" );
- }
- }
-
- }
-
-
- return element;
- }
-
- return nil;
- }
- -(void)handleEndElement:(Node *)newNode document:(SVGKSource *)document parseResult:(SVGKParseResult *)parseResult
- {
-
- }
- @end
|