--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg
+
+internal const val EIGHT_BIT_START = 127.toChar()
+
+/**
+ * Escapes special characters of an Appendable for HTML output. Handles double quotes,
+ * greater than, less than, ampersand, and characters greater than eight bit.
+ * @param csq A sequence of characters to HTML escape.
+ */
+fun Appendable.escapeHTML(csq: CharSequence) {
+ for (c in csq) {
+ when {
+ c > EIGHT_BIT_START || c == '"' || c == '<' || c == '>' || c == '&' -> {
+ append("&#")
+ append(c.code.toString())
+ append(';')
+ }
+
+ else -> append(c)
+ }
+ }
+}
+
+/**
+ * Escapes special characters of a String for HTML output. Handles double quotes,
+ * greater than, less than, ampersand, and characters greater than eight bit.
+ */
+fun String.escapeHTML(): String {
+ return usingAppendable(Appendable::escapeHTML)
+}
+
+fun Appendable.toAttributeName(csq: CharSequence) {
+ csq.forEach {
+ if (it in 'A'..'Z') {
+ append('-')
+ append(it.lowercase())
+ } else {
+ append(it)
+ }
+ }
+}
+
+fun String.toAttributeName(): String = usingAppendable(Appendable::toAttributeName)
+
+fun String.usingAppendable(function: Appendable.(CharSequence) -> Unit): String =
+ StringBuilder().also { it.function(this) }.toString()
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg
+
+/**
+ * The mode to employ when rendering. Some Elements must render differently when used inline in HTML5 or in a
+ * standalone SVG file.
+ */
+enum class RenderMode {
+ /**
+ * Render as inline SVG designed to appear inline in HTML5.
+ */
+ INLINE,
+
+ /**
+ * Render as an SVG `.svg` file format.
+ */
+ FILE
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+import com.github.nwillc.ksvg.toAttributeName
+import kotlin.properties.ReadWriteProperty
+import kotlin.reflect.KProperty
+
+/**
+ * A property delegate to allow attributes to be rendered with a different name and to validate content by type.
+ * @param renamed The name to use when rendering the property.
+ * @param type The attribute type to use for validation.
+ */
+class AttributeProperty(
+ private val renamed: String? = null,
+ private val type: AttributeType = AttributeType.None
+) : ReadWriteProperty<Any?, String?> {
+ override operator fun getValue(thisRef: Any?, property: KProperty<*>): String? = if (thisRef is HasAttributes) {
+ thisRef.attributes[renamed ?: property.name.toAttributeName()]
+ } else {
+ null
+ }
+
+ override operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String?) {
+ if (value != null && thisRef is HasAttributes) {
+ if (thisRef.validation)
+ type.verify(value)
+ thisRef.attributes[renamed ?: property.name.toAttributeName()] = value
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+/**
+ * An enumeration of attribute types and how to verify if a value is of this type.
+ */
+enum class AttributeType {
+ /**
+ * No validations will be performed on type none.
+ */
+ None,
+
+ /**
+ * A length value, a number and optional unit.
+ */
+ Length {
+ override fun verify(value: String) {
+ require(value matches length) { "Value ($value) is not a valid length or percentage: $length" }
+ }
+ },
+
+ /**
+ * A length or percentage, a number and optional unit or percent sign.
+ */
+ LengthOrPercentage {
+ override fun verify(value: String) {
+ require(value matches lengthPercent) {
+ "Value ($value) is not a valid length or percentage: $lengthPercent"
+ }
+ }
+ },
+
+ /**
+ * A list of numbers separated by white space or commas.
+ */
+ NumberList {
+ override fun verify(value: String) {
+ require(value matches numberList) { "Value ($value) is not a valid number list: $number" }
+ }
+ },
+
+ /**
+ * Fill rule
+ */
+ FillRule {
+ override fun verify(value: String) {
+ require(value matches fillRule) { "Value ($value) is not a valid `fill-rule` value: $fillRule" }
+ }
+ },
+
+ /**
+ * Stroke linecap
+ */
+ StrokeLinecap {
+ override fun verify(value: String) {
+ require(value matches strokeLinecap) { "Value ($value) is not a valid `stroke-linecap` value: $strokeLinecap" }
+ }
+ },
+
+ /**
+ * Stroke linejoin
+ */
+ StrokeLinejoin {
+ override fun verify(value: String) {
+ require(value matches strokeLinejoin) { "Value ($value) is not a valid `stroke-linejoin` value: $strokeLinejoin" }
+ }
+ },
+
+ /**
+ * Text anchor
+ */
+ TextAnchor {
+ override fun verify(value: String) {
+ require(value matches textAnchor) { "Value ($value) is not a valid `text-anchor` value: $textAnchor" }
+ }
+ },
+
+ /**
+ * Any non empty character string without whitespace.
+ */
+ IdName {
+ override fun verify(value: String) {
+ require(value matches idName) { "Value ($value) is not a valid id: $idName" }
+ }
+ },
+
+ /**
+ * A relative URL by id URL.
+ */
+ RelativeURL {
+ override fun verify(value: String) {
+ require(value matches relativeUrl) { "Value ($value) is not a valid id url: $relativeUrl" }
+ }
+ },
+
+ /**
+ * A set of commands and coordinates.
+ */
+ Path {
+ override fun verify(value: String) {
+ require(value matches path) { "Value ($value) is not a valid path: $path" }
+ }
+ },
+
+ /**
+ * CSS class names work imperfectly in some browsers so warn about them.
+ */
+ CssClass;
+
+ /**
+ * Constants.
+ */
+ private companion object {
+ private val number = Regex("[+-]?[0-9]*.?[0-9]+")
+ private val separator = Regex("\\s*,?\\s+")
+ private const val LENGTH_UNITS = "em|rem|ex|px|in|cm|mm|pt|pc"
+ private val length = Regex("$number($LENGTH_UNITS)?")
+ private val lengthPercent = Regex("$number($LENGTH_UNITS|%)?")
+ private val numberList = Regex("($number($separator)?)+")
+ private val fillRule = Regex("nonzero|evenodd")
+ private val strokeLinecap = Regex("butt|round|square")
+ private val strokeLinejoin = Regex("miter|round|bevel")
+ private val textAnchor = Regex("start|middle|end")
+ private val idName = Regex("\\S+")
+ private val relative = Regex("#$idName")
+ private val relativeUrl = Regex("url\\($relative\\)")
+ private val path = Regex("(($number)|[\\smMlLhHvVcCsSqQtTaAzZ])+")
+ }
+
+ /**
+ * Verify a value is of the AttributeType.
+ */
+ open fun verify(value: String) { /* No verifications by default */
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+import com.github.nwillc.ksvg.RenderMode
+
+/**
+ * This interface describes how SVG handles attributes.
+ */
+interface HasAttributes {
+ /**
+ * The attributes are simply labels with associated values.
+ */
+ val attributes: MutableMap<String, String>
+
+ /**
+ * Should we attempt to validated values correctness when assign them?
+ */
+ var validation: Boolean
+
+ /**
+ * Return the attribute map, with possible processing based on the renderMode.
+ * @param renderMode which rendering mode the attributes are being accessed for.
+ */
+ fun getAttributes(renderMode: RenderMode): Map<String, String>
+
+ /**
+ * All things that can have attributes can have an id attribute.
+ */
+ var id: String?
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+import com.github.nwillc.ksvg.RenderMode
+
+/**
+ * A basic implementation of HasAttributes.
+ */
+open class HasAttributesImpl(override var validation: Boolean) : HasAttributes {
+ override val attributes: MutableMap<String, String> = hashMapOf()
+ override var id: String? by AttributeProperty(type = AttributeType.IdName)
+ override fun getAttributes(renderMode: RenderMode) = attributes
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+/**
+ * An Element has a clip path.
+ */
+interface HasClipPath {
+ /**
+ * The clip path ID.
+ */
+ var clipPath: String?
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+/**
+ * A basic implementation of HasDimensions.
+ */
+class HasClipPathImpl(hasAttributes: HasAttributes) : HasClipPath, HasAttributes by hasAttributes {
+ override var clipPath: String? by AttributeProperty(type = AttributeType.RelativeURL)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+/**
+ * An Element has height and width dimensions.
+ */
+interface HasDimensions {
+ /**
+ * The height dimension.
+ */
+ var height: String?
+
+ /**
+ * The width dimension.
+ */
+ var width: String?
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+/**
+ * A basic implementation of HasDimensions.
+ */
+class HasDimensionsImpl(hasAttributes: HasAttributes) : HasDimensions, HasAttributes by hasAttributes {
+ override var height: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
+ override var width: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+/**
+ * An Element can have a fill color.
+ */
+interface HasFill {
+ /**
+ * The fill color.
+ */
+ var fill: String?
+
+ /**
+ * The fill rule.
+ */
+ var fillRule: String?
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+/**
+ * A basic implementation of HasFill.
+ */
+class HasFillImpl(hasAttributes: HasAttributes) : HasFill, HasAttributes by hasAttributes {
+ override var fill: String? by AttributeProperty()
+ override var fillRule: String? by AttributeProperty(type = AttributeType.FillRule)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+/**
+ * An Element has x,y origin.
+ */
+interface HasOrigin {
+ /**
+ * Origin's X coordinate.
+ */
+ var x: String?
+
+ /**
+ * Origin's Y coordinate.
+ */
+ var y: String?
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+/**
+ * A Basic implementation of HasOrigin.
+ */
+class HasOriginImpl(hasAttributes: HasAttributes) : HasOrigin, HasAttributes by hasAttributes {
+ override var x: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
+ override var y: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+/**
+ * An Element has a stroke associated.
+ */
+interface HasStroke {
+ /**
+ * The stroke color.
+ */
+ var stroke: String?
+
+ /**
+ * The stroke width.
+ */
+ var strokeWidth: String?
+
+ /**
+ * The stroke dash array.
+ */
+ var strokeDashArray: String?
+
+ /**
+ * The stroke line cap.
+ */
+ var strokeLinecap: String?
+
+ /**
+ * The stroke line join.
+ */
+ var strokeLinejoin: String?
+
+ /**
+ * The paint order.
+ */
+ var paintOrder: String?
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.attributes
+
+/**
+ * A basic implementation of HasStroke.
+ */
+class HasStrokeImpl(hasAttributes: HasAttributes) : HasStroke, HasAttributes by hasAttributes {
+ override var stroke: String? by AttributeProperty()
+ override var strokeWidth: String? by AttributeProperty()
+ override var strokeDashArray: String? by AttributeProperty(type = AttributeType.NumberList)
+ override var strokeLinecap: String? by AttributeProperty(type = AttributeType.StrokeLinecap)
+ override var strokeLinejoin: String? by AttributeProperty(type = AttributeType.StrokeLinejoin)
+ override var paintOrder: String? by AttributeProperty()
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.RenderMode
+import com.github.nwillc.ksvg.attributes.AttributeProperty
+
+/**
+ * An SVG A reference element.
+ */
+class A(validation: Boolean = false) : Element("a", validation) {
+ /**
+ * The reference URL.
+ */
+ var href: String? by AttributeProperty()
+
+ /**
+ * Create a rect element inside the reference.
+ */
+ fun rect(block: RECT.() -> Unit): RECT = add(RECT(validation), block)
+
+ /**
+ * Create a text element inside the reference.
+ */
+ fun text(block: TEXT.() -> Unit): TEXT = add(TEXT(validation), block)
+
+ override fun getAttributes(renderMode: RenderMode): Map<String, String> =
+ if (renderMode == RenderMode.INLINE) HashMap(attributes).apply {
+ remove("href")?.let { href ->
+ put("xlink:href", href)
+ }
+ } else {
+ attributes
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.attributes.AttributeProperty
+import com.github.nwillc.ksvg.attributes.AttributeType
+
+/**
+ * An SVG circle element.
+ */
+class CIRCLE(validation: Boolean = false) : Region("circle", validation) {
+ /**
+ * The x coordinate of the circle's center.
+ */
+ var cx: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
+
+ /**
+ * The r coordinate of the circle's center.
+ */
+ var cy: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
+
+ /**
+ * The radius or the circle.
+ */
+ var r: String? by AttributeProperty(type = AttributeType.Length)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+/**
+ * An SVG container element used to group other SVG elements.
+ */
+class CLIPPATH(id: String, validation: Boolean = false) : Container("clipPath", validation) {
+ init {
+ this.id = id
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.attributes.HasAttributes
+import com.github.nwillc.ksvg.attributes.HasAttributesImpl
+
+/**
+ * An abstract container element which provides factories for general sub elements.
+ */
+abstract class Container(
+ name: String,
+ validation: Boolean,
+ hasAttributes: HasAttributes = HasAttributesImpl(validation)
+) : Element(name, validation, hasAttributes) {
+ /**
+ * Create a rect element in this svg.
+ */
+ fun rect(block: RECT.() -> Unit): RECT = add(RECT(validation), block)
+
+ /**
+ * Create a text element in this svg.
+ */
+ fun text(block: TEXT.() -> Unit): TEXT = add(TEXT(validation), block)
+
+ /**
+ * Create a circle element in this svg.
+ */
+ fun circle(block: CIRCLE.() -> Unit): CIRCLE = add(CIRCLE(validation), block)
+
+ /**
+ * Create a polygon element in this svg.
+ */
+ fun polygon(block: POLYGON.() -> Unit): POLYGON = add(POLYGON(validation), block)
+
+ /**
+ * Create a line element in this svg.
+ */
+ fun line(block: LINE.() -> Unit): LINE = add(LINE(validation), block)
+
+ /**
+ * Create a reference element in this svg.
+ */
+ fun a(block: A.() -> Unit): A = add(A(validation), block)
+
+ /**
+ * Create a path element in this svg.
+ */
+ fun path(block: PATH.() -> Unit): PATH = add(PATH(validation), block)
+
+ /**
+ * Create an image element in this svg.
+ */
+ fun image(block: IMAGE.() -> Unit): IMAGE = add(IMAGE(validation), block)
+
+ /**
+ * Create a group element in this svg.
+ */
+ fun g(block: G.() -> Unit): G = add(G(validation), block)
+
+ /**
+ * Create a use element in this svg.
+ */
+ fun use(block: USE.() -> Unit): USE = add(USE(validation), block)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+/**
+ * An SVG defs element which can define groups to be used later.
+ */
+class DEFS(validation: Boolean) : Element("defs", validation) {
+ /**
+ * Create a group element in this def.
+ */
+ fun g(block: G.() -> Unit): G = add(G(validation), block)
+
+ /**
+ * Create a clipPath element in this def.
+ */
+ fun clipPath(id: String, block: CLIPPATH.() -> Unit): CLIPPATH = add(CLIPPATH(id, validation), block)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.RenderMode
+import com.github.nwillc.ksvg.attributes.AttributeProperty
+import com.github.nwillc.ksvg.attributes.AttributeType
+import com.github.nwillc.ksvg.attributes.HasAttributes
+import com.github.nwillc.ksvg.attributes.HasAttributesImpl
+import com.github.nwillc.ksvg.escapeHTML
+
+/**
+ * Abstract SVG named element with attributes and child elements.
+ * @param name The svg tag of the element.
+ * @param validation Should attribute and other validations be performed?
+ */
+@SvgTagMarker
+abstract class Element(
+ private val name: String,
+ validation: Boolean,
+ hasAttributes: HasAttributes = HasAttributesImpl(validation)
+) : HasAttributes by hasAttributes {
+ /**
+ * Child Element contained in this Element.
+ */
+ val children = arrayListOf<Element>()
+
+ /**
+ * The CSS class.
+ */
+ var cssClass: String? by AttributeProperty("class", AttributeType.CssClass)
+
+ /**
+ * The CSS transformation.
+ */
+ var transform: String? by AttributeProperty()
+
+ /**
+ * Raw text body of the Element.
+ */
+ var body: String = ""
+
+ /**
+ * Add a child element.
+ */
+ protected fun <E : Element> add(element: E, block: E.() -> Unit): E = element.also {
+ it.block()
+ children.add(it)
+ }
+
+ /**
+ * Render the Element as SVG.
+ * @param appendable A Writer to append the SVG to.
+ * @param renderMode Should the Elements render for inline SVG or file SVG.
+ */
+ open fun render(appendable: Appendable, renderMode: RenderMode) {
+ appendable.append("<$name")
+ getAttributes(renderMode)
+ .entries
+ .sortedBy { it.key }
+ .forEach { entry ->
+ appendable.append(' ')
+ appendable.append(entry.key)
+ appendable.append("=\"")
+ appendable.append(entry.value)
+ appendable.append('"')
+ }
+ if (!hasContent()) {
+ appendable.append("/>\n")
+ } else {
+ appendable.append('>')
+ if (hasBody()) {
+ appendable.escapeHTML(body)
+ } else {
+ appendable.append('\n')
+ }
+ children.forEach {
+ it.render(appendable, renderMode)
+ }
+ appendable.append("</$name>\n")
+ }
+ }
+
+ /**
+ * Has raw text body.
+ */
+ fun hasBody(): Boolean = body.isNotBlank()
+
+ /**
+ * Has Children.
+ */
+ fun hasChildren(): Boolean = children.isNotEmpty()
+
+
+ /**
+ * Has any content, i.e. a body and/or children.
+ */
+ fun hasContent(): Boolean = hasBody() || hasChildren()
+
+ /**
+ * Returns the rendered inline SVG as a String.
+ */
+ override fun toString(): String = StringBuilder().apply {
+ render(this, RenderMode.INLINE)
+ }.toString()
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.attributes.HasAttributes
+import com.github.nwillc.ksvg.attributes.HasAttributesImpl
+import com.github.nwillc.ksvg.attributes.HasClipPath
+import com.github.nwillc.ksvg.attributes.HasClipPathImpl
+
+/**
+ * An SVG container element used to group other SVG elements.
+ */
+class G(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) : Container("g", validation, hasAttributes), HasClipPath by HasClipPathImpl(hasAttributes)
--- /dev/null
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.attributes.*
+
+class IMAGE(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) :
+ Element("image", validation, hasAttributes),
+ HasOrigin by HasOriginImpl(hasAttributes),
+ HasDimensions by HasDimensionsImpl(hasAttributes),
+ HasClipPath by HasClipPathImpl(hasAttributes) {
+ var href: String? by AttributeProperty(type = AttributeType.None)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.attributes.*
+
+/**
+ * An SVG line element.
+ */
+class LINE(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) :
+ Element("line", validation, hasAttributes),
+ HasStroke by HasStrokeImpl(hasAttributes) {
+
+ /**
+ * The X1 coordinate of the line.
+ */
+ var x1: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
+
+ /**
+ * The Y1 coordinate of the line.
+ */
+ var y1: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
+
+ /**
+ * The X2 coordinate of the line.
+ */
+ var x2: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
+
+ /**
+ * The Y2 coordinate of the line.
+ */
+ var y2: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.attributes.AttributeProperty
+import com.github.nwillc.ksvg.attributes.AttributeType
+
+/**
+ * An SVG path element.
+ */
+class PATH(validation: Boolean = false) : Region("path", validation) {
+ /**
+ * The path definition.
+ */
+ var d: String? by AttributeProperty(type = AttributeType.Path)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.attributes.AttributeProperty
+import com.github.nwillc.ksvg.attributes.AttributeType
+
+/**
+ * An SVG polygon element.
+ */
+class POLYGON(validation: Boolean = false) : Region("polygon", validation) {
+ /**
+ * The points defining the x and y coordinates for each corner of the polygon.
+ */
+ var points: String? by AttributeProperty(type = AttributeType.Path)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.attributes.*
+
+/**
+ * An SVG rect element.
+ */
+class RECT(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) :
+ Region("rect", validation, hasAttributes),
+ HasOrigin by HasOriginImpl(hasAttributes),
+ HasDimensions by HasDimensionsImpl(hasAttributes) {
+ /**
+ * Add a title to the rect.
+ */
+ fun title(block: TITLE.() -> Unit): TITLE = add(TITLE(validation), block)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.attributes.*
+
+/**
+ * An abstract element that is a region and therefore has stroke and fill.
+ */
+abstract class Region(
+ name: String,
+ validation: Boolean,
+ hasAttributes: HasAttributes = HasAttributesImpl(validation)
+) :
+ Element(name, validation, hasAttributes),
+ HasStroke by HasStrokeImpl(hasAttributes),
+ HasFill by HasFillImpl(hasAttributes),
+ HasClipPath by HasClipPathImpl(hasAttributes)
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+/**
+ * An SVG style element.
+ */
+class STYLE(validation: Boolean) : Element("style", validation)
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.RenderMode
+import com.github.nwillc.ksvg.attributes.*
+
+/**
+ * The SVG element itself.
+ */
+class SVG(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) :
+ Container("svg", validation, hasAttributes),
+ HasDimensions by HasDimensionsImpl(hasAttributes) {
+ /**
+ * Top level functions.
+ */
+ companion object {
+ /**
+ * Create an SVG element.
+ */
+ inline fun svg(validation: Boolean = false, block: SVG.() -> Unit): SVG = SVG(validation).apply(block)
+ }
+
+ /**
+ * The viewBox attribute.
+ */
+ var viewBox: String? by AttributeProperty("viewBox", AttributeType.NumberList)
+
+ /**
+ * Create a group element in this svg.
+ */
+ fun defs(block: DEFS.() -> Unit): DEFS = add(DEFS(validation), block)
+
+ /**
+ * Create a style element.
+ */
+ fun style(block: STYLE.() -> Unit): STYLE = add(STYLE(validation), block)
+
+ override fun getAttributes(renderMode: RenderMode): Map<String, String> = if (renderMode == RenderMode.FILE) {
+ mutableMapOf(
+ "xmlns" to "http://www.w3.org/2000/svg",
+ "xmlns:xlink" to "http://www.w3.org/1999/xlink",
+ ).also {
+ it.putAll(attributes)
+ }
+ } else {
+ super.getAttributes(renderMode)
+ }
+
+ override fun render(appendable: Appendable, renderMode: RenderMode) {
+ if (renderMode == RenderMode.FILE) {
+ appendable.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n")
+ }
+ super.render(appendable, renderMode)
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+/**
+ * Indicates something is an SVG DSL marker.
+ */
+@DslMarker
+annotation class SvgTagMarker
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.attributes.*
+
+/**
+ * An SVG text element.
+ */
+class TEXT(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) :
+ Element("text", validation, hasAttributes),
+ HasOrigin by HasOriginImpl(hasAttributes),
+ HasFill by HasFillImpl(hasAttributes),
+ HasStroke by HasStrokeImpl(hasAttributes),
+ HasClipPath by HasClipPathImpl(hasAttributes) {
+
+ /**
+ * The font size attributes.
+ */
+ var fontSize: String? by AttributeProperty(type = AttributeType.Length)
+
+ /**
+ * The font family.
+ */
+ var fontFamily: String? by AttributeProperty()
+
+ /**
+ * The textLength attribute.
+ */
+ var textLength: String? by AttributeProperty(renamed = "textLength", type = AttributeType.LengthOrPercentage)
+
+ /**
+ * The text-anchor attribute.
+ */
+ var textAnchor: String? by AttributeProperty(type = AttributeType.TextAnchor)
+}
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+/**
+ * An SVG title element.
+ */
+class TITLE(validation: Boolean = false) : Element("title", validation)
--- /dev/null
+/*
+ * Copyright (c) 2020, nwillc@gmail.com
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.github.nwillc.ksvg.elements
+
+import com.github.nwillc.ksvg.RenderMode
+import com.github.nwillc.ksvg.attributes.*
+
+/**
+ * An SVG use element.
+ */
+class USE(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) :
+ Element("use", validation, hasAttributes),
+ HasOrigin by HasOriginImpl(hasAttributes),
+ HasDimensions by HasDimensionsImpl(hasAttributes) {
+
+ /**
+ * The reference URL.
+ */
+ var href: String? by AttributeProperty()
+
+ override fun getAttributes(renderMode: RenderMode): Map<String, String> =
+ if (renderMode == RenderMode.INLINE) HashMap(attributes).apply {
+ remove("href")?.let { href ->
+ put("xlink:href", href)
+ }
+ } else {
+ attributes
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg
-
-internal const val EIGHT_BIT_START = 127.toChar()
-
-/**
- * Escapes special characters of an Appendable for HTML output. Handles double quotes,
- * greater than, less than, ampersand, and characters greater than eight bit.
- * @param csq A sequence of characters to HTML escape.
- */
-fun Appendable.escapeHTML(csq: CharSequence) {
- for (c in csq) {
- when {
- c > EIGHT_BIT_START || c == '"' || c == '<' || c == '>' || c == '&' -> {
- append("&#")
- append(c.code.toString())
- append(';')
- }
-
- else -> append(c)
- }
- }
-}
-
-/**
- * Escapes special characters of a String for HTML output. Handles double quotes,
- * greater than, less than, ampersand, and characters greater than eight bit.
- */
-fun String.escapeHTML(): String {
- return usingAppendable(Appendable::escapeHTML)
-}
-
-fun Appendable.toAttributeName(csq: CharSequence) {
- csq.forEach {
- if (it in 'A'..'Z') {
- append('-')
- append(it.lowercase())
- } else {
- append(it)
- }
- }
-}
-
-fun String.toAttributeName(): String = usingAppendable(Appendable::toAttributeName)
-
-fun String.usingAppendable(function: Appendable.(CharSequence) -> Unit): String =
- StringBuilder().also { it.function(this) }.toString()
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg
-
-/**
- * The mode to employ when rendering. Some Elements must render differently when used inline in HTML5 or in a
- * standalone SVG file.
- */
-enum class RenderMode {
- /**
- * Render as inline SVG designed to appear inline in HTML5.
- */
- INLINE,
-
- /**
- * Render as an SVG `.svg` file format.
- */
- FILE
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-import com.github.nwillc.ksvg.toAttributeName
-import kotlin.properties.ReadWriteProperty
-import kotlin.reflect.KProperty
-
-/**
- * A property delegate to allow attributes to be rendered with a different name and to validate content by type.
- * @param renamed The name to use when rendering the property.
- * @param type The attribute type to use for validation.
- */
-class AttributeProperty(
- private val renamed: String? = null,
- private val type: AttributeType = AttributeType.None
-) : ReadWriteProperty<Any?, String?> {
- override operator fun getValue(thisRef: Any?, property: KProperty<*>): String? = if (thisRef is HasAttributes) {
- thisRef.attributes[renamed ?: property.name.toAttributeName()]
- } else {
- null
- }
-
- override operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String?) {
- if (value != null && thisRef is HasAttributes) {
- if (thisRef.validation)
- type.verify(value)
- thisRef.attributes[renamed ?: property.name.toAttributeName()] = value
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-/**
- * An enumeration of attribute types and how to verify if a value is of this type.
- */
-enum class AttributeType {
- /**
- * No validations will be performed on type none.
- */
- None,
-
- /**
- * A length value, a number and optional unit.
- */
- Length {
- override fun verify(value: String) {
- require(value matches length) { "Value ($value) is not a valid length or percentage: $length" }
- }
- },
-
- /**
- * A length or percentage, a number and optional unit or percent sign.
- */
- LengthOrPercentage {
- override fun verify(value: String) {
- require(value matches lengthPercent) {
- "Value ($value) is not a valid length or percentage: $lengthPercent"
- }
- }
- },
-
- /**
- * A list of numbers separated by white space or commas.
- */
- NumberList {
- override fun verify(value: String) {
- require(value matches numberList) { "Value ($value) is not a valid number list: $number" }
- }
- },
-
- /**
- * Fill rule
- */
- FillRule {
- override fun verify(value: String) {
- require(value matches fillRule) { "Value ($value) is not a valid `fill-rule` value: $fillRule" }
- }
- },
-
- /**
- * Stroke linecap
- */
- StrokeLinecap {
- override fun verify(value: String) {
- require(value matches strokeLinecap) { "Value ($value) is not a valid `stroke-linecap` value: $strokeLinecap" }
- }
- },
-
- /**
- * Stroke linejoin
- */
- StrokeLinejoin {
- override fun verify(value: String) {
- require(value matches strokeLinejoin) { "Value ($value) is not a valid `stroke-linejoin` value: $strokeLinejoin" }
- }
- },
-
- /**
- * Text anchor
- */
- TextAnchor {
- override fun verify(value: String) {
- require(value matches textAnchor) { "Value ($value) is not a valid `text-anchor` value: $textAnchor" }
- }
- },
-
- /**
- * Any non empty character string without whitespace.
- */
- IdName {
- override fun verify(value: String) {
- require(value matches idName) { "Value ($value) is not a valid id: $idName" }
- }
- },
-
- /**
- * A relative URL by id URL.
- */
- RelativeURL {
- override fun verify(value: String) {
- require(value matches relativeUrl) { "Value ($value) is not a valid id url: $relativeUrl" }
- }
- },
-
- /**
- * A set of commands and coordinates.
- */
- Path {
- override fun verify(value: String) {
- require(value matches path) { "Value ($value) is not a valid path: $path" }
- }
- },
-
- /**
- * CSS class names work imperfectly in some browsers so warn about them.
- */
- CssClass;
-
- /**
- * Constants.
- */
- private companion object {
- private val number = Regex("[+-]?[0-9]*.?[0-9]+")
- private val separator = Regex("\\s*,?\\s+")
- private const val lengthUnits = "em|rem|ex|px|in|cm|mm|pt|pc"
- private val length = Regex("$number($lengthUnits)?")
- private val lengthPercent = Regex("$number($lengthUnits|%)?")
- private val numberList = Regex("($number($separator)?)+")
- private val fillRule = Regex("nonzero|evenodd")
- private val strokeLinecap = Regex("butt|round|square")
- private val strokeLinejoin = Regex("miter|round|bevel")
- private val textAnchor = Regex("start|middle|end")
- private val idName = Regex("\\S+")
- private val relative = Regex("#$idName")
- private val relativeUrl = Regex("url\\($relative\\)")
- private val path = Regex("(($number)|[\\smMlLhHvVcCsSqQtTaAzZ])+")
- }
-
- /**
- * Verify a value is of the AttributeType.
- */
- open fun verify(value: String) { /* No verifications by default */
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-import com.github.nwillc.ksvg.RenderMode
-
-/**
- * This interface describes how SVG handles attributes.
- */
-interface HasAttributes {
- /**
- * The attributes are simply labels with associated values.
- */
- val attributes: MutableMap<String, String>
-
- /**
- * Should we attempt to validated values correctness when assign them?
- */
- var validation: Boolean
-
- /**
- * Return the attribute map, with possible processing based on the renderMode.
- * @param renderMode which rendering mode the attributes are being accessed for.
- */
- fun getAttributes(renderMode: RenderMode): Map<String, String>
-
- /**
- * All things that can have attributes can have an id attribute.
- */
- var id: String?
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-import com.github.nwillc.ksvg.RenderMode
-
-/**
- * A basic implementation of HasAttributes.
- */
-open class HasAttributesImpl(override var validation: Boolean) : HasAttributes {
- override val attributes: MutableMap<String, String> = hashMapOf()
- override var id: String? by AttributeProperty(type = AttributeType.IdName)
- override fun getAttributes(renderMode: RenderMode) = attributes
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-/**
- * An Element has a clip path.
- */
-interface HasClipPath {
- /**
- * The clip path ID.
- */
- var clipPath: String?
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-/**
- * A basic implementation of HasDimensions.
- */
-class HasClipPathImpl(hasAttributes: HasAttributes) : HasClipPath, HasAttributes by hasAttributes {
- override var clipPath: String? by AttributeProperty(type = AttributeType.RelativeURL)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-/**
- * An Element has height and width dimensions.
- */
-interface HasDimensions {
- /**
- * The height dimension.
- */
- var height: String?
-
- /**
- * The width dimension.
- */
- var width: String?
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-/**
- * A basic implementation of HasDimensions.
- */
-class HasDimensionsImpl(hasAttributes: HasAttributes) : HasDimensions, HasAttributes by hasAttributes {
- override var height: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
- override var width: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-/**
- * An Element can have a fill color.
- */
-interface HasFill {
- /**
- * The fill color.
- */
- var fill: String?
-
- /**
- * The fill rule.
- */
- var fillRule: String?
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-/**
- * A basic implementation of HasFill.
- */
-class HasFillImpl(hasAttributes: HasAttributes) : HasFill, HasAttributes by hasAttributes {
- override var fill: String? by AttributeProperty()
- override var fillRule: String? by AttributeProperty(type = AttributeType.FillRule)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-/**
- * An Element has x,y origin.
- */
-interface HasOrigin {
- /**
- * Origin's X coordinate.
- */
- var x: String?
-
- /**
- * Origin's Y coordinate.
- */
- var y: String?
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-/**
- * A Basic implementation of HasOrigin.
- */
-class HasOriginImpl(hasAttributes: HasAttributes) : HasOrigin, HasAttributes by hasAttributes {
- override var x: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
- override var y: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-/**
- * An Element has a stroke associated.
- */
-interface HasStroke {
- /**
- * The stroke color.
- */
- var stroke: String?
-
- /**
- * The stroke width.
- */
- var strokeWidth: String?
-
- /**
- * The stroke dash array.
- */
- var strokeDashArray: String?
-
- /**
- * The stroke line cap.
- */
- var strokeLinecap: String?
-
- /**
- * The stroke line join.
- */
- var strokeLinejoin: String?
-
- /**
- * The paint order.
- */
- var paintOrder: String?
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.attributes
-
-/**
- * A basic implementation of HasStroke.
- */
-class HasStrokeImpl(hasAttributes: HasAttributes) : HasStroke, HasAttributes by hasAttributes {
- override var stroke: String? by AttributeProperty()
- override var strokeWidth: String? by AttributeProperty()
- override var strokeDashArray: String? by AttributeProperty(type = AttributeType.NumberList)
- override var strokeLinecap: String? by AttributeProperty(type = AttributeType.StrokeLinecap)
- override var strokeLinejoin: String? by AttributeProperty(type = AttributeType.StrokeLinejoin)
- override var paintOrder: String? by AttributeProperty()
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.RenderMode
-import com.github.nwillc.ksvg.attributes.AttributeProperty
-
-/**
- * An SVG A reference element.
- */
-class A(validation: Boolean = false) : Element("a", validation) {
- /**
- * The reference URL.
- */
- var href: String? by AttributeProperty()
-
- /**
- * Create a rect element inside the reference.
- */
- fun rect(block: RECT.() -> Unit): RECT = add(RECT(validation), block)
-
- /**
- * Create a text element inside the reference.
- */
- fun text(block: TEXT.() -> Unit): TEXT = add(TEXT(validation), block)
-
- override fun getAttributes(renderMode: RenderMode): Map<String, String> =
- if (renderMode == RenderMode.INLINE) HashMap(attributes).apply {
- remove("href")?.let { href ->
- put("xlink:href", href)
- }
- } else {
- attributes
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.attributes.AttributeProperty
-import com.github.nwillc.ksvg.attributes.AttributeType
-
-/**
- * An SVG circle element.
- */
-class CIRCLE(validation: Boolean = false) : Region("circle", validation) {
- /**
- * The x coordinate of the circle's center.
- */
- var cx: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
-
- /**
- * The r coordinate of the circle's center.
- */
- var cy: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
-
- /**
- * The radius or the circle.
- */
- var r: String? by AttributeProperty(type = AttributeType.Length)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-/**
- * An SVG container element used to group other SVG elements.
- */
-class CLIPPATH(id: String, validation: Boolean = false) : Container("clipPath", validation) {
- init {
- this.id = id
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.attributes.HasAttributes
-import com.github.nwillc.ksvg.attributes.HasAttributesImpl
-
-/**
- * An abstract container element which provides factories for general sub elements.
- */
-abstract class Container(
- name: String,
- validation: Boolean,
- hasAttributes: HasAttributes = HasAttributesImpl(validation)
-) : Element(name, validation, hasAttributes) {
- /**
- * Create a rect element in this svg.
- */
- fun rect(block: RECT.() -> Unit): RECT = add(RECT(validation), block)
-
- /**
- * Create a text element in this svg.
- */
- fun text(block: TEXT.() -> Unit): TEXT = add(TEXT(validation), block)
-
- /**
- * Create a circle element in this svg.
- */
- fun circle(block: CIRCLE.() -> Unit): CIRCLE = add(CIRCLE(validation), block)
-
- /**
- * Create a polygon element in this svg.
- */
- fun polygon(block: POLYGON.() -> Unit): POLYGON = add(POLYGON(validation), block)
-
- /**
- * Create a line element in this svg.
- */
- fun line(block: LINE.() -> Unit): LINE = add(LINE(validation), block)
-
- /**
- * Create a reference element in this svg.
- */
- fun a(block: A.() -> Unit): A = add(A(validation), block)
-
- /**
- * Create a path element in this svg.
- */
- fun path(block: PATH.() -> Unit): PATH = add(PATH(validation), block)
-
- /**
- * Create an image element in this svg.
- */
- fun image(block: IMAGE.() -> Unit): IMAGE = add(IMAGE(validation), block)
-
- /**
- * Create a group element in this svg.
- */
- fun g(block: G.() -> Unit): G = add(G(validation), block)
-
- /**
- * Create a use element in this svg.
- */
- fun use(block: USE.() -> Unit): USE = add(USE(validation), block)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-/**
- * An SVG defs element which can define groups to be used later.
- */
-class DEFS(validation: Boolean) : Element("defs", validation) {
- /**
- * Create a group element in this def.
- */
- fun g(block: G.() -> Unit): G = add(G(validation), block)
-
- /**
- * Create a clipPath element in this def.
- */
- fun clipPath(id: String, block: CLIPPATH.() -> Unit): CLIPPATH = add(CLIPPATH(id, validation), block)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.RenderMode
-import com.github.nwillc.ksvg.attributes.AttributeProperty
-import com.github.nwillc.ksvg.attributes.AttributeType
-import com.github.nwillc.ksvg.attributes.HasAttributes
-import com.github.nwillc.ksvg.attributes.HasAttributesImpl
-import com.github.nwillc.ksvg.escapeHTML
-
-/**
- * Abstract SVG named element with attributes and child elements.
- * @param name The svg tag of the element.
- * @param validation Should attribute and other validations be performed?
- */
-@SvgTagMarker
-abstract class Element(
- private val name: String,
- validation: Boolean,
- hasAttributes: HasAttributes = HasAttributesImpl(validation)
-) : HasAttributes by hasAttributes {
- /**
- * Child Element contained in this Element.
- */
- val children = arrayListOf<Element>()
-
- /**
- * The CSS class.
- */
- var cssClass: String? by AttributeProperty("class", AttributeType.CssClass)
-
- /**
- * The CSS transformation.
- */
- var transform: String? by AttributeProperty()
-
- /**
- * Raw text body of the Element.
- */
- var body: String = ""
-
- /**
- * Add a child element.
- */
- protected fun <E : Element> add(element: E, block: E.() -> Unit): E = element.also {
- it.block()
- children.add(it)
- }
-
- /**
- * Render the Element as SVG.
- * @param appendable A Writer to append the SVG to.
- * @param renderMode Should the Elements render for inline SVG or file SVG.
- */
- open fun render(appendable: Appendable, renderMode: RenderMode) {
- appendable.append("<$name")
- getAttributes(renderMode)
- .entries
- .sortedBy { it.key }
- .forEach { entry ->
- appendable.append(' ')
- appendable.append(entry.key)
- appendable.append("=\"")
- appendable.append(entry.value)
- appendable.append('"')
- }
- if (!hasContent()) {
- appendable.append("/>\n")
- } else {
- appendable.append('>')
- if (hasBody()) {
- appendable.escapeHTML(body)
- } else {
- appendable.append('\n')
- }
- children.forEach {
- it.render(appendable, renderMode)
- }
- appendable.append("</$name>\n")
- }
- }
-
- /**
- * Has raw text body.
- */
- fun hasBody(): Boolean = body.isNotBlank()
-
- /**
- * Has Children.
- */
- fun hasChildren(): Boolean = children.isNotEmpty()
-
-
- /**
- * Has any content, i.e. a body and/or children.
- */
- fun hasContent(): Boolean = hasBody() || hasChildren()
-
- /**
- * Returns the rendered inline SVG as a String.
- */
- override fun toString(): String = StringBuilder().apply {
- render(this, RenderMode.INLINE)
- }.toString()
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.attributes.HasAttributes
-import com.github.nwillc.ksvg.attributes.HasAttributesImpl
-import com.github.nwillc.ksvg.attributes.HasClipPath
-import com.github.nwillc.ksvg.attributes.HasClipPathImpl
-
-/**
- * An SVG container element used to group other SVG elements.
- */
-class G(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) : Container("g", validation, hasAttributes), HasClipPath by HasClipPathImpl(hasAttributes)
+++ /dev/null
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.attributes.*
-
-class IMAGE(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) :
- Element("image", validation, hasAttributes),
- HasOrigin by HasOriginImpl(hasAttributes),
- HasDimensions by HasDimensionsImpl(hasAttributes),
- HasClipPath by HasClipPathImpl(hasAttributes) {
- var href: String? by AttributeProperty(type = AttributeType.None)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.attributes.*
-
-/**
- * An SVG line element.
- */
-class LINE(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) :
- Element("line", validation, hasAttributes),
- HasStroke by HasStrokeImpl(hasAttributes) {
-
- /**
- * The X1 coordinate of the line.
- */
- var x1: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
-
- /**
- * The Y1 coordinate of the line.
- */
- var y1: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
-
- /**
- * The X2 coordinate of the line.
- */
- var x2: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
-
- /**
- * The Y2 coordinate of the line.
- */
- var y2: String? by AttributeProperty(type = AttributeType.LengthOrPercentage)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.attributes.AttributeProperty
-import com.github.nwillc.ksvg.attributes.AttributeType
-
-/**
- * An SVG path element.
- */
-class PATH(validation: Boolean = false) : Region("path", validation) {
- /**
- * The path definition.
- */
- var d: String? by AttributeProperty(type = AttributeType.Path)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.attributes.AttributeProperty
-import com.github.nwillc.ksvg.attributes.AttributeType
-
-/**
- * An SVG polygon element.
- */
-class POLYGON(validation: Boolean = false) : Region("polygon", validation) {
- /**
- * The points defining the x and y coordinates for each corner of the polygon.
- */
- var points: String? by AttributeProperty(type = AttributeType.Path)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.attributes.*
-
-/**
- * An SVG rect element.
- */
-class RECT(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) :
- Region("rect", validation, hasAttributes),
- HasOrigin by HasOriginImpl(hasAttributes),
- HasDimensions by HasDimensionsImpl(hasAttributes) {
- /**
- * Add a title to the rect.
- */
- fun title(block: TITLE.() -> Unit): TITLE = add(TITLE(validation), block)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.attributes.*
-
-/**
- * An abstract element that is a region and therefore has stroke and fill.
- */
-abstract class Region(
- name: String,
- validation: Boolean,
- hasAttributes: HasAttributes = HasAttributesImpl(validation)
-) :
- Element(name, validation, hasAttributes),
- HasStroke by HasStrokeImpl(hasAttributes),
- HasFill by HasFillImpl(hasAttributes),
- HasClipPath by HasClipPathImpl(hasAttributes)
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-/**
- * An SVG style element.
- */
-class STYLE(validation: Boolean) : Element("style", validation)
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.RenderMode
-import com.github.nwillc.ksvg.attributes.*
-
-/**
- * The SVG element itself.
- */
-class SVG(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) :
- Container("svg", validation, hasAttributes),
- HasDimensions by HasDimensionsImpl(hasAttributes) {
- /**
- * Top level functions.
- */
- companion object {
- /**
- * Create an SVG element.
- */
- inline fun svg(validation: Boolean = false, block: SVG.() -> Unit): SVG = SVG(validation).apply(block)
- }
-
- /**
- * The viewBox attribute.
- */
- var viewBox: String? by AttributeProperty("viewBox", AttributeType.NumberList)
-
- /**
- * Create a group element in this svg.
- */
- fun defs(block: DEFS.() -> Unit): DEFS = add(DEFS(validation), block)
-
- /**
- * Create a style element.
- */
- fun style(block: STYLE.() -> Unit): STYLE = add(STYLE(validation), block)
-
- override fun getAttributes(renderMode: RenderMode): Map<String, String> = if (renderMode == RenderMode.FILE) {
- mutableMapOf(
- "xmlns" to "http://www.w3.org/2000/svg",
- "xmlns:xlink" to "http://www.w3.org/1999/xlink",
- ).also {
- it.putAll(attributes)
- }
- } else {
- super.getAttributes(renderMode)
- }
-
- override fun render(appendable: Appendable, renderMode: RenderMode) {
- if (renderMode == RenderMode.FILE) {
- appendable.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n")
- }
- super.render(appendable, renderMode)
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-/**
- * Indicates something is an SVG DSL marker.
- */
-@DslMarker
-annotation class SvgTagMarker
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.attributes.*
-
-/**
- * An SVG text element.
- */
-class TEXT(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) :
- Element("text", validation, hasAttributes),
- HasOrigin by HasOriginImpl(hasAttributes),
- HasFill by HasFillImpl(hasAttributes),
- HasStroke by HasStrokeImpl(hasAttributes),
- HasClipPath by HasClipPathImpl(hasAttributes) {
-
- /**
- * The font size attributes.
- */
- var fontSize: String? by AttributeProperty(type = AttributeType.Length)
-
- /**
- * The font family.
- */
- var fontFamily: String? by AttributeProperty()
-
- /**
- * The textLength attribute.
- */
- var textLength: String? by AttributeProperty(renamed = "textLength", type = AttributeType.LengthOrPercentage)
-
- /**
- * The text-anchor attribute.
- */
- var textAnchor: String? by AttributeProperty(type = AttributeType.TextAnchor)
-}
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-/**
- * An SVG title element.
- */
-class TITLE(validation: Boolean = false) : Element("title", validation)
+++ /dev/null
-/*
- * Copyright (c) 2020, nwillc@gmail.com
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package com.github.nwillc.ksvg.elements
-
-import com.github.nwillc.ksvg.RenderMode
-import com.github.nwillc.ksvg.attributes.*
-
-/**
- * An SVG use element.
- */
-class USE(validation: Boolean = false, hasAttributes: HasAttributes = HasAttributesImpl(validation)) :
- Element("use", validation, hasAttributes),
- HasOrigin by HasOriginImpl(hasAttributes),
- HasDimensions by HasDimensionsImpl(hasAttributes) {
-
- /**
- * The reference URL.
- */
- var href: String? by AttributeProperty()
-
- override fun getAttributes(renderMode: RenderMode): Map<String, String> =
- if (renderMode == RenderMode.INLINE) HashMap(attributes).apply {
- remove("href")?.let { href ->
- put("xlink:href", href)
- }
- } else {
- attributes
- }
-}