File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -231,13 +231,20 @@ public class SVGRenderer: Renderer{
231
231
public func drawOutput( fileName name: String ) throws {
232
232
try savePlotImage ( fileName: name)
233
233
}
234
+
235
+ /// Returns the content of the SVG generated by the renderer
236
+ public var svg : String {
237
+ // Build the document.
238
+ 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">"#
239
+ + " \n " + #"<rect width="100%" height="100%" fill="white"/>"#
240
+ let font = #"<defs><style>@import url("https://fonts.googleapis.com/css?family= \#( fontFamily) ");</style></defs>"#
241
+ let image = header + " \n " + font + " \n " + lines. joined ( separator: " \n " ) + " \n </svg> "
242
+ return image
243
+ }
234
244
235
245
func savePlotImage( fileName name: String ) throws {
236
246
// Build the document.
237
- 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">"#
238
- + " \n " + #"<rect width="100%" height="100%" fill="white"/>"#
239
- let font = #"<defs><style>@import url("https://fonts.googleapis.com/css?family= \#( fontFamily) ");</style></defs>"#
240
- let image = header + " \n " + font + " \n " + lines. joined ( separator: " \n " ) + " \n </svg> "
247
+ let image = self . svg
241
248
242
249
let url = URL ( fileURLWithPath: " \( name) .svg " )
243
250
try image. write ( to: url, atomically: true , encoding: . utf8)
You can’t perform that action at this time.
0 commit comments