Skip to content

Symbol Tag not there #487

Description

@kiranvarma

In my project I Have to handle "Symbol" tag, Earlier i have got a crash for it, I Created new Class "SVGSymbolElement" which is extended "SVGElement" (Just like SVGDefsElement), Then i used the SVGSymbolElement in "SVGKParserDefsAndUse" class.

I added "Symbol" tag in the array as below

-(NSArray*) supportedTags
{
return [NSMutableArray arrayWithObjects: @"defs",@"symbol", @"use", nil];
}

Then In the below method i just used a "defs" tag because i feel the code may take care of the functinality. I have added else if for symbol and write same code as defs.

After this the crash is fixed but I see the issue, What ever there in "Symbol" tag is not Drawing.

Can you please help

(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] )
{

NSString* qualifiedName = (prefix == nil) ? name : [NSString stringWithFormat:@"%@:%@", prefix, name];

if( [name isEqualToString:@"defs"])
{
/** NB: must supply a NON-qualified name if we have no specific prefix here ! */
SVGDefsElement *element = [[SVGDefsElement alloc] initWithQualifiedName:qualifiedName inNameSpaceURI:XMLNSURI attributes:attributes];

return element;

}
else if( [name isEqualToString:@"symbol"])
{
/
NB: must supply a NON-qualified name if we have no specific prefix here ! */
SVGSymbolElement *element = [[SVGSymbolElement alloc] initWithQualifiedName:qualifiedName inNameSpaceURI:XMLNSURI attributes:attributes];

return element;

}**

else if( [name isEqualToString:@"use"])
{
/** NB: must supply a NON-qualified name if we have no specific prefix here ! */
SVGUseElement *useElement = [[SVGUseElement alloc] initWithQualifiedName:qualifiedName inNameSpaceURI:XMLNSURI attributes:attributes];

[useElement postProcessAttributesAddingErrorsTo:parseResult]; // handles "transform" and "style"

if( [attributes valueForKey:@"x"] != nil )
    useElement.x = [SVGLength svgLengthFromNSString:[((Attr*)[attributes valueForKey:@"x"]) value]];
if( [attributes valueForKey:@"y"] != nil )
    useElement.y = [SVGLength svgLengthFromNSString:[((Attr*)[attributes valueForKey:@"y"]) value]];
if( [attributes valueForKey:@"width"] != nil )
    useElement.width = [SVGLength svgLengthFromNSString:[((Attr*)[attributes valueForKey:@"width"]) value]];
if( [attributes valueForKey:@"height"] != nil )
    useElement.height = [SVGLength svgLengthFromNSString:[((Attr*)[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 = [((Attr*)[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 );

    linkHref = [linkHref substringFromIndex:1];

    /** have to find the node in the DOM tree with id = xlink:href's value */
    SVGElement* linkedElement = (SVGElement*) [parseResult.parsedDocument getElementById:linkHref];

    NSAssert( linkedElement != nil, @"Found an SVG <use> tag that points to a non-existent element. Missing element: id = %@", linkHref );


    useElement.instanceRoot = [self convertSVGElementToElementInstanceTree:linkedElement outermostUseElement:useElement];
}

return useElement;

}
}

return nil;
}




In Demo project We have a SVG with file name "struct-use-09-b.svg" it is having "Symbol" tag. But is not used any where (I dont know the reason), I added to the "Licenses.plist" to access it but not able to open it, Attaching the screen shot

I got the below in the console

2016-10-13 13:54:02:904 Demo-iOS[11195:601351] [SVGKSourceLocalFile] MISSING FILE (not found in App-bundle, not found in Documents folder), COULD NOT CREATE DOCUMENT: filename = struct-use-09-b, extension = svg
2016-10-13 13:54:02:926 Demo-iOS[11195:601351] [SVGKFastImageView] WARNING: you have initialized an SVGKImageView with a blank image (nil). Possibly because you're using Storyboards or NIBs which Apple won't allow us to decorate. Make sure you assign an SVGKImage to the .image property!

file
simulator screen shot 13-oct-2016 1 55 23 pm

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions