@@ -6,6 +6,15 @@ import org.openrndr.extra.composition.TextNode
6
6
7
7
import java.io.*
8
8
9
+ /* *
10
+ * Saves the vector composition to a file in SVG format.
11
+ *
12
+ * Only files with the ".svg" extension are supported. Writing to files with unsupported extensions
13
+ * will result in an exception.
14
+ *
15
+ * @param file the file to which the composition should be saved. The file must have an ".svg" extension.
16
+ * @throws IllegalArgumentException if the file does not have the ".svg" extension.
17
+ */
9
18
fun Composition.saveToFile (file : File ) {
10
19
if (file.extension == " svg" ) {
11
20
val svg = writeSVG(this )
@@ -15,6 +24,18 @@ fun Composition.saveToFile(file: File) {
15
24
}
16
25
}
17
26
27
+ /* *
28
+ * Converts a [Composition] into its equivalent SVG representation.
29
+ *
30
+ * This method serializes the vector composition, including its structure, style,
31
+ * and attributes, into an SVG string. The resulting SVG can be used for rendering
32
+ * or exporting the composition to an SVG file.
33
+ *
34
+ * The method internally utilizes the [writeSVG] function for the conversion process.
35
+ *
36
+ * @receiver The [Composition] instance to be converted into SVG.
37
+ * @return A [String] representing the composition in SVG format.
38
+ */
18
39
fun Composition.toSVG () = writeSVG(this )
19
40
20
41
private val CompositionNode .svgId: String
@@ -59,6 +80,13 @@ private fun Styleable.serialize(parentStyleable: Styleable? = null): String {
59
80
return sb.trim().toString()
60
81
}
61
82
83
+ /* *
84
+ * Generates an SVG string representation of a given vector composition.
85
+ *
86
+ * @param composition the vector composition to be converted to an SVG string
87
+ * @param topLevelId an optional ID for the top-level SVG element, defaults to "openrndr-svg"
88
+ * @return a string containing the SVG representation of the composition
89
+ */
62
90
fun writeSVG (
63
91
composition : Composition ,
64
92
topLevelId : String = "openrndr-svg"
0 commit comments