Permalink
Browse files

Add generics metadata to the SVGKParserExtension protocol.

  • Loading branch information...
MaddTheSane committed Oct 8, 2016
1 parent 976b44e commit a7dae2d0d46c19fe52785a269510203123979f6a
@@ -20,7 +20,7 @@ -(NSArray*) supportedTags
return [NSMutableArray array];
}
-- (SVGKNode*) handleStartElement:(NSString *)name document:(SVGKSource*) SVGKSource namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary *)attributeObjects parseResult:(SVGKParseResult *)parseResult parentNode:(SVGKNode*) parentNode
+- (SVGKNode*) handleStartElement:(NSString *)name document:(SVGKSource*) SVGKSource namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary<NSString*,SVGKAttr*> *)attributeObjects parseResult:(SVGKParseResult *)parseResult parentNode:(SVGKNode*) parentNode
{
if( [[self supportedNamespaces] count] == 0
|| [[self supportedNamespaces] containsObject:XMLNSURI] ) // unnecesary here, but allows safe updates to this parser's matching later
@@ -46,7 +46,7 @@ -(SVGElementInstance*) convertSVGElementToElementInstanceTree:(SVGElement*) orig
return instance;
}
-- (SVGKNode*) handleStartElement:(NSString *)name document:(SVGKSource*) SVGKSource namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary *)attributes parseResult:(SVGKParseResult *)parseResult parentNode:(SVGKNode*) parentNode
+- (SVGKNode*) handleStartElement:(NSString *)name document:(SVGKSource*) SVGKSource namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary<NSString*,SVGKAttr*> *)attributes parseResult:(SVGKParseResult *)parseResult parentNode:(SVGKNode*) parentNode
{
if( [[self supportedNamespaces] containsObject:XMLNSURI] )
{
@@ -67,20 +67,20 @@ - (SVGKNode*) handleStartElement:(NSString *)name document:(SVGKSource*) SVGKSou
[useElement postProcessAttributesAddingErrorsTo:parseResult]; // handles "transform" and "style"
if( [attributes valueForKey:@"x"] != nil )
- useElement.x = [SVGLength svgLengthFromNSString:[((SVGKAttr*)[attributes valueForKey:@"x"]) value]];
+ useElement.x = [SVGLength svgLengthFromNSString:[[attributes valueForKey:@"x"] value]];
if( [attributes valueForKey:@"y"] != nil )
- useElement.y = [SVGLength svgLengthFromNSString:[((SVGKAttr*)[attributes valueForKey:@"y"]) value]];
+ useElement.y = [SVGLength svgLengthFromNSString:[[attributes valueForKey:@"y"] value]];
if( [attributes valueForKey:@"width"] != nil )
- useElement.width = [SVGLength svgLengthFromNSString:[((SVGKAttr*)[attributes valueForKey:@"width"]) value]];
+ useElement.width = [SVGLength svgLengthFromNSString:[[attributes valueForKey:@"width"] value]];
if( [attributes valueForKey:@"height"] != nil )
- useElement.height = [SVGLength svgLengthFromNSString:[((SVGKAttr*)[attributes valueForKey:@"height"]) value]];
+ useElement.height = [SVGLength svgLengthFromNSString:[[attributes valueForKey:@"height"] value]];
NSString* hrefAttribute = [useElement getAttributeNS:@"http://www.w3.org/1999/xlink" localName:@"href"];
NSAssert( [hrefAttribute length] > 0, @"Found an SVG <use> tag that has no 'xlink:href' attribute. File is invalid / don't know how to parse this" );
if( [hrefAttribute length] > 0 )
{
- NSString* linkHref = [((SVGKAttr*)[attributes valueForKey:@"xlink:href"]) value];
+ NSString* linkHref = [[attributes valueForKey:@"xlink:href"] value];
NSAssert( [linkHref hasPrefix:@"#"], @"Not supported: <use> tags that declare an href to something that DOESN'T begin with #. Href supplied = %@", linkHref );
@@ -31,7 +31,7 @@ -(NSSet *)supportedTags
return _svgGradientParserSupportedTags;
}
--(SVGKNode *)handleStartElement:(NSString *)name document:(SVGKSource *)document namePrefix:(NSString *)prefix namespaceURI:(NSString *)XMLNSURI attributes:(NSMutableDictionary *)attributes parseResult:(SVGKParseResult *)parseResult parentNode:(SVGKNode *)parentNode
+-(SVGKNode *)handleStartElement:(NSString *)name document:(SVGKSource *)document namePrefix:(NSString *)prefix namespaceURI:(NSString *)XMLNSURI attributes:(NSMutableDictionary<NSString*,SVGKAttr*> *)attributes parseResult:(SVGKParseResult *)parseResult parentNode:(SVGKNode *)parentNode
{
// SVGColor startColor = SVGColorFromString(<#const char *string#>)
// CGPoint startPos = CGPointMake([attributes objectFor, <#CGFloat y#>)
@@ -35,7 +35,7 @@ -(NSArray*) supportedTags
return [NSMutableArray arrayWithObject:@"pattern"];
}
-- (SVGKNode*)handleStartElement:(NSString *)name document:(SVGKSource*) document namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary *)attributes parseResult:(SVGKParseResult*) parseResult parentNode:(SVGKNode*) parentNode
+- (SVGKNode*)handleStartElement:(NSString *)name document:(SVGKSource*) document namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary<NSString*,SVGKAttr*> *)attributes parseResult:(SVGKParseResult*) parseResult parentNode:(SVGKNode*) parentNode
{
NSAssert( FALSE, @"Patterns are not supported by SVGKit yet - no-one has implemented them" );
@@ -63,7 +63,7 @@ -(NSArray*) supportedTags
return [NSMutableArray arrayWithArray:[elementMap allKeys]];
}
-- (SVGKNode*) handleStartElement:(NSString *)name document:(SVGKSource*) SVGKSource namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary *)attributes parseResult:(SVGKParseResult *)parseResult parentNode:(SVGKNode*) parentNode
+- (SVGKNode*) handleStartElement:(NSString *)name document:(SVGKSource*) SVGKSource namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary<NSString*,SVGKAttr*> *)attributes parseResult:(SVGKParseResult *)parseResult parentNode:(SVGKNode*) parentNode
{
if( [[self supportedNamespaces] containsObject:XMLNSURI] )
{
@@ -32,7 +32,7 @@ -(NSSet *)supportedTags
return _svgParserStylesSupportedTags;
}
--(SVGKNode *)handleStartElement:(NSString *)name document:(SVGKSource *)document namePrefix:(NSString *)prefix namespaceURI:(NSString *)XMLNSURI attributes:(NSMutableDictionary *)attributes parseResult:(SVGKParseResult *)parseResult parentNode:(SVGKNode *)parentNode
+-(SVGKNode *)handleStartElement:(NSString *)name document:(SVGKSource *)document namePrefix:(NSString *)prefix namespaceURI:(NSString *)XMLNSURI attributes:(NSMutableDictionary<NSString*,SVGKAttr*> *)attributes parseResult:(SVGKParseResult *)parseResult parentNode:(SVGKNode *)parentNode
{
if( [[self supportedNamespaces] containsObject:XMLNSURI] )
{
@@ -733,15 +733,15 @@ static void charactersFoundSAX (void *ctx, const xmlChar *chars, int len) {
static void errorEncounteredSAX (void *ctx, const char *msg, ...) {
va_list va;
NSString *errStr = nil;
- SVGKParser *self = (__bridge SVGKParser *)(ctx);
+ SVGKParser *self = (__bridge SVGKParser *)(ctx);
va_start(va, msg);
errStr = [[NSString alloc] initWithFormat:@(msg) arguments:va];
va_end(va);
- SVGKitLogWarn(@"Error encountered during parse: %@", errStr);
- SVGKParseResult* parseResult = self.currentParseRun;
+ SVGKitLogWarn(@"Error encountered during parse: %@", errStr);
+ SVGKParseResult* parseResult = self.currentParseRun;
- [parseResult addSAXError:[NSError errorWithDomain:@"SVG-SAX" code:1 userInfo:@{NSLocalizedDescriptionKey: errStr}]];
+ [parseResult addSAXError:[NSError errorWithDomain:@"SVG-SAX" code:1 userInfo:@{NSLocalizedDescriptionKey: errStr}]];
}
static void unparsedEntityDeclaration(void * ctx,
@@ -776,7 +776,7 @@ static void structuredError (void * userData,
if( error->str3 )
details[@"bonusInfo3"] = @(error->str3);
- NSError* objcError = [NSError errorWithDomain:[@(error->domain) stringValue] code:error->code userInfo:details];
+ NSError* objcError = [NSError errorWithDomain:[NSString stringWithFormat:@"libxml error domain %i", error->domain] code:error->code userInfo:details];
SVGKParser *NSctx = (__bridge SVGKParser*)(userData);
SVGKParseResult* parseResult = NSctx.currentParseRun;
@@ -792,6 +792,8 @@ static void structuredError (void * userData,
case XML_ERR_FATAL:
[parseResult addParseErrorFatal:objcError];
+ break;
+
default:
break;
}
@@ -891,7 +893,6 @@ static void structuredError (void * userData,
#define MAX_NAME 256
+(NSDictionary *) NSDictionaryFromCSSAttributes: (SVGKAttr*) styleAttribute {
-
if( styleAttribute == nil )
{
SVGKitLogWarn(@"[%@] WARNING: asked to convert an empty CSS string into a CSS dictionary; returning empty dictionary", [self class] );
@@ -17,6 +17,7 @@
@class SVGKSource;
@class SVGKParseResult;
@class SVGKNode;
+@class SVGKAttr;
/*! Experimental: allow SVGKit parser-extensions to insert custom data into an SVGKParseResult */
#define ENABLE_PARSER_EXTENSIONS_CUSTOM_DATA 0
@@ -39,7 +40,7 @@
Because SVG-DOM uses DOM, custom parsers can return any object they like - so long as its some kind of
subclass of DOM's Node class
*/
-- (SVGKNode*)handleStartElement:(NSString *)name document:(SVGKSource*) document namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary *)attributes parseResult:(SVGKParseResult*) parseResult parentNode:(SVGKNode*) parentNode;
+- (SVGKNode*)handleStartElement:(NSString *)name document:(SVGKSource*) document namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary<NSString*,SVGKAttr*> *)attributes parseResult:(SVGKParseResult*) parseResult parentNode:(SVGKNode*) parentNode;
/**
Primarily used by the few nodes - <TEXT> and <TSPAN> - that need to post-process their text-content.

0 comments on commit a7dae2d

Please sign in to comment.