Skip to content

Conversation

efc
Copy link

@efc efc commented Feb 9, 2017

This pull request provides SwiftSVG with the ability to read in an SVG file and provide named access to the individual paths in the file. The names used to access the paths will correspond to the id attributes path elements in the SVG file.

For example, given an SVG file named "shapes.svg" like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="100" height="100" viewBox="0, 0, 100, 100">
  <g id="Background">
    <rect x="0" y="0" width="100" height="100" fill="#FFFFFF"/>
  </g>
  <g id="shapes">
    <path d="M10,10 L90,10 L90,90 L10,90 L10,10 z" fill="#B10000" id="square"/>
    <path d="M50,90 C27.909,90 10,72.091 10,50 C10,27.909 27.909,10 50,10 C72.091,10 90,27.909 90,50 C90,72.091 72.091,90 50,90 z" fill="#B1B100" id="circle"/>
  </g>
</svg>

We could use this feature to read in the file like this:

let pathsByName = Bundle.main.url(forResource: "shapes", withExtension: "svg")?.pathsByName()

Then draw the square with:

let parsedPath = pathsByName?["square"];
parsedPath?.stroke()

Or draw the circle with:

let parsedPath = pathsByName?["circle"];
parsedPath?.stroke()

@Superolo
Copy link

Superolo commented Mar 9, 2017

I would like to use this feature. Why is not pulled yet?

@gh-clement-taboulot
Copy link

Any news on this feature ?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants