Skip to content

Allow SVGRenderer to export the result from memory #120

@arguiot

Description

@arguiot

Instead of saving, it would be cool to have somehting like:

let svg = svg_renderer.svg() // Result as plain string

Implementing would be very easy:

extension SVGRenderer {
    /// Returns the content of the SVG generated by the renderer
    func svg() -> String {
            // Build the document.
            let header = #"<svg height="\#(imageSize.height)" width="\#(imageSize.width)" version="4.0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink= "http://www.w3.org/1999/xlink">"#
                + "\n" + #"<rect width="100%" height="100%" fill="white"/>"#
            let font = #"<defs><style>@import url("https://fonts.googleapis.com/css?family=\#(fontFamily)");</style></defs>"#
            let image = header + "\n" + font + "\n" + lines.joined(separator: "\n") + "\n</svg>"
            return image
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions