some style change at svg loading

This commit is contained in:
tibbi 2017-04-09 10:28:16 +02:00
parent e919534780
commit a362451a03
4 changed files with 61 additions and 54 deletions

View File

@ -18,39 +18,43 @@ object Svg {
}
private fun writeSvg(writer: Writer, backgroundColor: Int, paths: Map<MyPath, PaintOptions>, width: Int, height: Int) {
writer.write("<svg width=\"")
writer.write(width.toString())
writer.write("\" height=\"")
writer.write(height.toString())
writer.write("\" xmlns=\"http://www.w3.org/2000/svg\">")
writer.apply {
write("<svg width=\"")
write(width.toString())
write("\" height=\"")
write(height.toString())
write("\" xmlns=\"http://www.w3.org/2000/svg\">")
// background rect
writer.write("<rect width=\"")
writer.write(width.toString())
writer.write("\" height=\"")
writer.write(height.toString())
writer.write("\" fill=\"#")
writer.write(Integer.toHexString(backgroundColor).substring(2))
writer.write("\"/>")
// background rect
write("<rect width=\"")
write(width.toString())
write("\" height=\"")
write(height.toString())
write("\" fill=\"#")
write(Integer.toHexString(backgroundColor).substring(2))
write("\"/>")
for ((key, value) in paths) {
writePath(writer, key, value)
for ((key, value) in paths) {
writePath(this, key, value)
}
write("</svg>")
}
writer.write("</svg>")
}
private fun writePath(writer: Writer, path: MyPath, options: PaintOptions) {
writer.write("<path d=\"")
for (action in path.getActions()) {
action.perform(writer)
writer.write(" ")
}
writer.apply {
write("<path d=\"")
for (action in path.getActions()) {
action.perform(this)
write(" ")
}
writer.write("\" fill=\"none\" stroke=\"#")
writer.write(Integer.toHexString(options.color).substring(2))
writer.write("\" stroke-width=\"")
writer.write(options.strokeWidth.toString())
writer.write("\" stroke-linecap=\"round\"/>")
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) {

View File

@ -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())
}
}
}

View File

@ -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())
}
}
}

View File

@ -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())
}
}
}