A utility & library for interacting with SVG documents.
VectorPlus is distributed using the Swift Package Manager. To install it into a project, add it as a dependency within your Package.swift
manifest:
let package = Package(
...
dependencies: [
.package(url: "https://github.com/richardpiazza/VectorPlus.git", from: "0.3.0")
],
...
)
Then import the VectorPlus packages wherever you'd like to use it:
import VectorPlus
VectorPlus acts primarily as a wrapper over SwiftSVG
providing extensions for interacting with:
CoreGraphics
UIKit
AppKit
SwiftUI
When linked to a target that supports one of these frameworks, multiple options become available.
-
CGMutablePath.addCommand(_:from:to:)
: Adds aPath.Command
to the mutable path. The addition of theRect
s allow for correct placement and scaling. -
CGContext.render(path:from:to:) throws
: Rendered aPath
in the given context. Uses information about fills and strokes to fill and/or stroke the path.
-
SVG.uiImage(size:) -> UIImage?
: ACoreGraphics
renderedUIImage
representation of the SVG paths. -
SVG.pngData(size:) -> Data?
: AData
representation of theUIImage
. -
SVGImageView
: AUIImageView
subclass that supports the assignment of anSVG
object. The.image
will automatically be generated using the viewbounds
.
-
SVG.nsImage(size:) -> NSImage?
: ACoreGraphics
renderedNSImage
representation of the SVG paths. -
SVG.pngData(size:) -> Data?
: AData
representation of theNSImage
.
SVGView(svg:)
: ASwiftUI.View
that renders aSVG
document.
Parses an SVG document and prints out the document description.
Parses an SVG document and creates a PNG rendered version of the Command
s.
Supported conversion options are:
-
absolute: Translates all elements to 'absolute' paths.
-
symbols: Generates an Apple Symbols compatible SVG.
-
uikit: A
UIImageView
subclass that supports dynamic sizing.
macOS only
Parses an SVG document displaying the results in an Application window. Do to limitations, this sub-command is only available when the AppKit
framework is present.
macOS only
Parses an SVG document and creates a PNG rendered version of the Command
s. Do to limitations, this sub-command is only available when the AppKit
framework is present.