Allow SVGRenderer to export the result from memory
arguiot opened this issue · 3 comments
arguiot commented
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
}
}
KarthikRIyer commented
@arguiot thanks a lot for creating the issue! Is it something you'd like to take up?
arguiot commented
Well, I can submit a PR if you want
KarthikRIyer commented
Sure! @arguiot