diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/Svg.kt b/app/src/main/kotlin/com/simplemobiletools/draw/Svg.kt index 2919465..fd37494 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/Svg.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/Svg.kt @@ -18,39 +18,43 @@ object Svg { } private fun writeSvg(writer: Writer, backgroundColor: Int, paths: Map, width: Int, height: Int) { - writer.write("") + writer.apply { + write("") - // background rect - writer.write("") + // background rect + write("") - for ((key, value) in paths) { - writePath(writer, key, value) + for ((key, value) in paths) { + writePath(this, key, value) + } + write("") } - writer.write("") } private fun writePath(writer: Writer, path: MyPath, options: PaintOptions) { - writer.write("") + write("\" fill=\"none\" stroke=\"#") + write(Integer.toHexString(options.color).substring(2)) + write("\" stroke-width=\"") + write(options.strokeWidth.toString()) + write("\" stroke-linecap=\"round\"/>") + } } fun loadSvg(file: File, canvas: MyCanvas) { diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/actions/Line.kt b/app/src/main/kotlin/com/simplemobiletools/draw/actions/Line.kt index 7497946..1fc48c1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/actions/Line.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/actions/Line.kt @@ -15,12 +15,11 @@ class Line : Action { try { val xy = data.substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray() - x = java.lang.Float.parseFloat(xy[0].trim { it <= ' ' }) - y = java.lang.Float.parseFloat(xy[1].trim { it <= ' ' }) + x = xy[0].trim().toFloat() + y = xy[1].trim().toFloat() } catch (ignored: Exception) { throw InvalidParameterException("Error parsing the given Line data.") } - } constructor(x: Float, y: Float) { @@ -33,9 +32,11 @@ class Line : Action { } override fun perform(writer: Writer) { - writer.write("L") - writer.write(x.toString()) - writer.write(",") - writer.write(y.toString()) + writer.apply { + write("L") + write(x.toString()) + write(",") + write(y.toString()) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/actions/Move.kt b/app/src/main/kotlin/com/simplemobiletools/draw/actions/Move.kt index 0654095..87681ad 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/actions/Move.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/actions/Move.kt @@ -15,12 +15,11 @@ class Move : Action { try { val xy = data.substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray() - x = java.lang.Float.parseFloat(xy[0].trim { it <= ' ' }) - y = java.lang.Float.parseFloat(xy[1].trim { it <= ' ' }) + x = xy[0].trim().toFloat() + y = xy[1].trim().toFloat() } catch (ignored: Exception) { throw InvalidParameterException("Error parsing the given Move data.") } - } constructor(x: Float, y: Float) { @@ -33,9 +32,11 @@ class Move : Action { } override fun perform(writer: Writer) { - writer.write("M") - writer.write(x.toString()) - writer.write(",") - writer.write(y.toString()) + writer.apply { + write("M") + write(x.toString()) + write(",") + write(y.toString()) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/actions/Quad.kt b/app/src/main/kotlin/com/simplemobiletools/draw/actions/Quad.kt index 7260904..5ccf447 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/actions/Quad.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/actions/Quad.kt @@ -18,16 +18,15 @@ class Quad : Action { try { val parts = data.split("\\s+".toRegex()).dropLastWhile(String::isEmpty).toTypedArray() val xy1 = parts[0].substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray() - val xy2 = parts[1].split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray() // No need to skip the 'Q' here + val xy2 = parts[1].split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray() - x1 = java.lang.Float.parseFloat(xy1[0].trim { it <= ' ' }) - y1 = java.lang.Float.parseFloat(xy1[1].trim { it <= ' ' }) - x2 = java.lang.Float.parseFloat(xy2[0].trim { it <= ' ' }) - y2 = java.lang.Float.parseFloat(xy2[1].trim { it <= ' ' }) + x1 = xy1[0].trim().toFloat() + y1 = xy1[1].trim().toFloat() + x2 = xy2[0].trim().toFloat() + y2 = xy2[1].trim().toFloat() } catch (ignored: Exception) { throw InvalidParameterException("Error parsing the given Quad data.") } - } constructor(x1: Float, y1: Float, x2: Float, y2: Float) { @@ -42,13 +41,15 @@ class Quad : Action { } override fun perform(writer: Writer) { - writer.write("Q") - writer.write(x1.toString()) - writer.write(",") - writer.write(y1.toString()) - writer.write(" ") - writer.write(x2.toString()) - writer.write(",") - writer.write(y2.toString()) + writer.apply { + write("Q") + write(x1.toString()) + write(",") + write(y1.toString()) + write(" ") + write(x2.toString()) + write(",") + write(y2.toString()) + } } }