You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by jo...@apache.org on 2020/05/07 16:46:21 UTC

[isis] 04/08: ISIS-2342 scale image 2/n

This is an automated email from the ASF dual-hosted git repository.

joergrade pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit a4d256056e88239dde0ba4ce3b69c7705d7d3aca
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Fri May 1 16:53:26 2020 +0200

    ISIS-2342 scale image 2/n
---
 .../client/kroviz/utils/ScalableVectorGraphic.kt   | 51 ++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/ScalableVectorGraphic.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/ScalableVectorGraphic.kt
new file mode 100644
index 0000000..777ff76
--- /dev/null
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/ScalableVectorGraphic.kt
@@ -0,0 +1,51 @@
+package org.apache.isis.client.kroviz.utils
+
+import org.w3c.dom.Document
+import org.w3c.dom.parsing.XMLSerializer
+import org.w3c.dom.svg.SVGSVGElement
+
+class ScalableVectorGraphic(val document: Document) {
+
+    private fun root(): SVGSVGElement {
+        return document.rootElement!!
+    }
+
+    fun setHeight(height: Int) {
+        root().setAttribute("height", height.toString() + "px")
+    }
+
+    fun getHeight(): Int {
+        val raw = root().getAttribute("height") as String
+        val value = raw.replace("px", "")
+        return value.toInt()
+    }
+
+    fun setWidth(width: Int) {
+        root().setAttribute("width", width.toString() + "px")
+    }
+
+    fun getWidth(): Int {
+        val raw = root().getAttribute("width") as String
+        val value = raw.replace("px", "")
+        return value.toInt()
+    }
+
+    fun scaleUp(factor: Double = 0.1) {
+        var f = factor
+        if (factor < 1) f = 1 + factor
+        val oldHeight = getHeight()
+        val oldWidth = getWidth()
+        setHeight((oldHeight * f).toInt())
+        setWidth((oldWidth * f).toInt())
+    }
+
+    fun scaleDown(factor: Double = 0.1) {
+        scaleUp(factor * -1)
+    }
+
+    fun serialized(): String {
+        val srlzr = XMLSerializer()
+        return srlzr.serializeToString(document)
+    }
+
+}