some style change at svg loading
This commit is contained in:
parent
e919534780
commit
a362451a03
|
@ -18,39 +18,43 @@ object Svg {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writeSvg(writer: Writer, backgroundColor: Int, paths: Map<MyPath, PaintOptions>, width: Int, height: Int) {
|
private fun writeSvg(writer: Writer, backgroundColor: Int, paths: Map<MyPath, PaintOptions>, width: Int, height: Int) {
|
||||||
writer.write("<svg width=\"")
|
writer.apply {
|
||||||
writer.write(width.toString())
|
write("<svg width=\"")
|
||||||
writer.write("\" height=\"")
|
write(width.toString())
|
||||||
writer.write(height.toString())
|
write("\" height=\"")
|
||||||
writer.write("\" xmlns=\"http://www.w3.org/2000/svg\">")
|
write(height.toString())
|
||||||
|
write("\" xmlns=\"http://www.w3.org/2000/svg\">")
|
||||||
|
|
||||||
// background rect
|
// background rect
|
||||||
writer.write("<rect width=\"")
|
write("<rect width=\"")
|
||||||
writer.write(width.toString())
|
write(width.toString())
|
||||||
writer.write("\" height=\"")
|
write("\" height=\"")
|
||||||
writer.write(height.toString())
|
write(height.toString())
|
||||||
writer.write("\" fill=\"#")
|
write("\" fill=\"#")
|
||||||
writer.write(Integer.toHexString(backgroundColor).substring(2))
|
write(Integer.toHexString(backgroundColor).substring(2))
|
||||||
writer.write("\"/>")
|
write("\"/>")
|
||||||
|
|
||||||
for ((key, value) in paths) {
|
for ((key, value) in paths) {
|
||||||
writePath(writer, key, value)
|
writePath(this, key, value)
|
||||||
|
}
|
||||||
|
write("</svg>")
|
||||||
}
|
}
|
||||||
writer.write("</svg>")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writePath(writer: Writer, path: MyPath, options: PaintOptions) {
|
private fun writePath(writer: Writer, path: MyPath, options: PaintOptions) {
|
||||||
writer.write("<path d=\"")
|
writer.apply {
|
||||||
for (action in path.getActions()) {
|
write("<path d=\"")
|
||||||
action.perform(writer)
|
for (action in path.getActions()) {
|
||||||
writer.write(" ")
|
action.perform(this)
|
||||||
}
|
write(" ")
|
||||||
|
}
|
||||||
|
|
||||||
writer.write("\" fill=\"none\" stroke=\"#")
|
write("\" fill=\"none\" stroke=\"#")
|
||||||
writer.write(Integer.toHexString(options.color).substring(2))
|
write(Integer.toHexString(options.color).substring(2))
|
||||||
writer.write("\" stroke-width=\"")
|
write("\" stroke-width=\"")
|
||||||
writer.write(options.strokeWidth.toString())
|
write(options.strokeWidth.toString())
|
||||||
writer.write("\" stroke-linecap=\"round\"/>")
|
write("\" stroke-linecap=\"round\"/>")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadSvg(file: File, canvas: MyCanvas) {
|
fun loadSvg(file: File, canvas: MyCanvas) {
|
||||||
|
|
|
@ -15,12 +15,11 @@ class Line : Action {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val xy = data.substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
val xy = data.substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
||||||
x = java.lang.Float.parseFloat(xy[0].trim { it <= ' ' })
|
x = xy[0].trim().toFloat()
|
||||||
y = java.lang.Float.parseFloat(xy[1].trim { it <= ' ' })
|
y = xy[1].trim().toFloat()
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
throw InvalidParameterException("Error parsing the given Line data.")
|
throw InvalidParameterException("Error parsing the given Line data.")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(x: Float, y: Float) {
|
constructor(x: Float, y: Float) {
|
||||||
|
@ -33,9 +32,11 @@ class Line : Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun perform(writer: Writer) {
|
override fun perform(writer: Writer) {
|
||||||
writer.write("L")
|
writer.apply {
|
||||||
writer.write(x.toString())
|
write("L")
|
||||||
writer.write(",")
|
write(x.toString())
|
||||||
writer.write(y.toString())
|
write(",")
|
||||||
|
write(y.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,12 +15,11 @@ class Move : Action {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val xy = data.substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
val xy = data.substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
||||||
x = java.lang.Float.parseFloat(xy[0].trim { it <= ' ' })
|
x = xy[0].trim().toFloat()
|
||||||
y = java.lang.Float.parseFloat(xy[1].trim { it <= ' ' })
|
y = xy[1].trim().toFloat()
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
throw InvalidParameterException("Error parsing the given Move data.")
|
throw InvalidParameterException("Error parsing the given Move data.")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(x: Float, y: Float) {
|
constructor(x: Float, y: Float) {
|
||||||
|
@ -33,9 +32,11 @@ class Move : Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun perform(writer: Writer) {
|
override fun perform(writer: Writer) {
|
||||||
writer.write("M")
|
writer.apply {
|
||||||
writer.write(x.toString())
|
write("M")
|
||||||
writer.write(",")
|
write(x.toString())
|
||||||
writer.write(y.toString())
|
write(",")
|
||||||
|
write(y.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,16 +18,15 @@ class Quad : Action {
|
||||||
try {
|
try {
|
||||||
val parts = data.split("\\s+".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
val parts = data.split("\\s+".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
||||||
val xy1 = parts[0].substring(1).split(",".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 <= ' ' })
|
x1 = xy1[0].trim().toFloat()
|
||||||
y1 = java.lang.Float.parseFloat(xy1[1].trim { it <= ' ' })
|
y1 = xy1[1].trim().toFloat()
|
||||||
x2 = java.lang.Float.parseFloat(xy2[0].trim { it <= ' ' })
|
x2 = xy2[0].trim().toFloat()
|
||||||
y2 = java.lang.Float.parseFloat(xy2[1].trim { it <= ' ' })
|
y2 = xy2[1].trim().toFloat()
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
throw InvalidParameterException("Error parsing the given Quad data.")
|
throw InvalidParameterException("Error parsing the given Quad data.")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(x1: Float, y1: Float, x2: Float, y2: Float) {
|
constructor(x1: Float, y1: Float, x2: Float, y2: Float) {
|
||||||
|
@ -42,13 +41,15 @@ class Quad : Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun perform(writer: Writer) {
|
override fun perform(writer: Writer) {
|
||||||
writer.write("Q")
|
writer.apply {
|
||||||
writer.write(x1.toString())
|
write("Q")
|
||||||
writer.write(",")
|
write(x1.toString())
|
||||||
writer.write(y1.toString())
|
write(",")
|
||||||
writer.write(" ")
|
write(y1.toString())
|
||||||
writer.write(x2.toString())
|
write(" ")
|
||||||
writer.write(",")
|
write(x2.toString())
|
||||||
writer.write(y2.toString())
|
write(",")
|
||||||
|
write(y2.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue