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
widthWidth of the SVG
heightHeight of the SVG
-
Create a new SVG from a
SketchViewDeclaration
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
shapeShape to add
-
Group top-level elements by the specified attribute’s value.
This method is useful for generating plottable multi-color SVGs. By using
strokeas the attribute all elements will be grouped by their stroke color for easy pen switching.Declaration
Swift
public func groupElements(by attributeName: String)Parameters
attributeNameGrouping 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() -> XMLDocumentReturn Value
An
XMLDocumentrepresenting 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]) -> StringParameters
optionsOne 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]) throwsParameters
urlURL of the location to write the SVG
optionsOne or more enum constants identifying an output option; bit-OR multiple constants together.
View on GitHub
SVGContext Class Reference