Skip to content

Commit 8350dde

Browse files
committed
[orx-svg] And generated and verified documentation
1 parent 45d4580 commit 8350dde

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

orx-svg/src/jvmMain/kotlin/SVGWriter.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import org.openrndr.extra.composition.TextNode
66

77
import java.io.*
88

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+
*/
918
fun Composition.saveToFile(file: File) {
1019
if (file.extension == "svg") {
1120
val svg = writeSVG(this)
@@ -15,6 +24,18 @@ fun Composition.saveToFile(file: File) {
1524
}
1625
}
1726

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+
*/
1839
fun Composition.toSVG() = writeSVG(this)
1940

2041
private val CompositionNode.svgId: String
@@ -59,6 +80,13 @@ private fun Styleable.serialize(parentStyleable: Styleable? = null): String {
5980
return sb.trim().toString()
6081
}
6182

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+
*/
6290
fun writeSVG(
6391
composition: Composition,
6492
topLevelId: String = "openrndr-svg"

0 commit comments

Comments
 (0)