From 8350ddeb7629b2711d8573597f7313cbdd76af01 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Fri, 24 Jan 2025 16:22:28 +0100 Subject: [PATCH] [orx-svg] And generated and verified documentation --- orx-svg/src/jvmMain/kotlin/SVGWriter.kt | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/orx-svg/src/jvmMain/kotlin/SVGWriter.kt b/orx-svg/src/jvmMain/kotlin/SVGWriter.kt index 58613ee1..6807ceca 100644 --- a/orx-svg/src/jvmMain/kotlin/SVGWriter.kt +++ b/orx-svg/src/jvmMain/kotlin/SVGWriter.kt @@ -6,6 +6,15 @@ import org.openrndr.extra.composition.TextNode import java.io.* +/** + * Saves the vector composition to a file in SVG format. + * + * Only files with the ".svg" extension are supported. Writing to files with unsupported extensions + * will result in an exception. + * + * @param file the file to which the composition should be saved. The file must have an ".svg" extension. + * @throws IllegalArgumentException if the file does not have the ".svg" extension. + */ fun Composition.saveToFile(file: File) { if (file.extension == "svg") { val svg = writeSVG(this) @@ -15,6 +24,18 @@ fun Composition.saveToFile(file: File) { } } +/** + * Converts a [Composition] into its equivalent SVG representation. + * + * This method serializes the vector composition, including its structure, style, + * and attributes, into an SVG string. The resulting SVG can be used for rendering + * or exporting the composition to an SVG file. + * + * The method internally utilizes the [writeSVG] function for the conversion process. + * + * @receiver The [Composition] instance to be converted into SVG. + * @return A [String] representing the composition in SVG format. + */ fun Composition.toSVG() = writeSVG(this) private val CompositionNode.svgId: String @@ -59,6 +80,13 @@ private fun Styleable.serialize(parentStyleable: Styleable? = null): String { return sb.trim().toString() } +/** + * Generates an SVG string representation of a given vector composition. + * + * @param composition the vector composition to be converted to an SVG string + * @param topLevelId an optional ID for the top-level SVG element, defaults to "openrndr-svg" + * @return a string containing the SVG representation of the composition + */ fun writeSVG( composition: Composition, topLevelId: String = "openrndr-svg"