SVGContext
public class SVGContext : DrawingContext
A drawing context which creates SVG files
-
The root SVG element
Declaration
Swift
public var svg: XMLElement
-
Width of the SVG
Declaration
Swift
public let width: Int
-
Height of the SVG
Declaration
Swift
public let height: Int
-
Create a new SVG with the specified dimensions
Declaration
Swift
public init(width: Int, height: Int)
Parameters
width
Width of the SVG
height
Height of the SVG
-
Create a new SVG from a
SketchView
Declaration
Swift
@available(*, deprecated, renamed: "init(sketch:﹚", message: "Initialize with a Sketch, rather than SketchView.") public convenience init(sketch: SketchView)
-
Append a shape to the SVG
Declaration
Swift
public func addShape(_ shape: SVGDrawable)
Parameters
shape
Shape to add
-
Group top-level elements by the specified attribute’s value.
This method is useful for generating plottable multi-color SVGs. By using
stroke
as the attribute all elements will be grouped by their stroke color for easy pen switching.Declaration
Swift
public func groupElements(by attributeName: String)
Parameters
attributeName
Grouping attribute name
-
Ungroup top-level elements.
If a shape draws itself as a group this method can be used to break the group apart before calling
groupElements(by:)
.Declaration
Swift
public func breakGroups()
-
Create an SVG document
Declaration
Swift
public func makeDoc() -> XMLDocument
Return Value
An
XMLDocument
representing the SVG -
Returns the string representation of the receiver as it would appear in an XML document, with one or more output options specified.
The returned string includes the string representations of all children.
See Constants for a list of valid constants for specifying output options.
Declaration
Swift
public func svgString(options: XMLNode.Options = [.documentTidyXML, .nodePrettyPrint]) -> String
Parameters
options
One or more enum constants identifying an output option; bit-OR multiple constants together.
-
Attempt to write the SVG to the specified location
See Constants for a list of valid constants for specifying output options.
Throws
Errors related to writing the SVG to diskDeclaration
Swift
public func writeSVG(to url: URL, options: XMLNode.Options = [.documentTidyXML, .nodePrettyPrint]) throws
Parameters
url
URL of the location to write the SVG
options
One or more enum constants identifying an output option; bit-OR multiple constants together.