mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-06-05 21:59:17 +02:00
couple svg.kt style changes
This commit is contained in:
@ -44,8 +44,8 @@ object Svg {
|
|||||||
private fun writePath(writer: Writer, path: MyPath, options: PaintOptions) {
|
private fun writePath(writer: Writer, path: MyPath, options: PaintOptions) {
|
||||||
writer.apply {
|
writer.apply {
|
||||||
write("<path d=\"")
|
write("<path d=\"")
|
||||||
for (action in path.getActions()) {
|
path.getActions().forEach {
|
||||||
action.perform(this)
|
it.perform(this)
|
||||||
write(" ")
|
write(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,10 +63,10 @@ object Svg {
|
|||||||
canvas.clearCanvas()
|
canvas.clearCanvas()
|
||||||
canvas.setBackgroundColor(svg.background!!.color)
|
canvas.setBackgroundColor(svg.background!!.color)
|
||||||
|
|
||||||
for (sp in svg.paths) {
|
svg.paths.forEach {
|
||||||
val path = MyPath()
|
val path = MyPath()
|
||||||
path.readObject(sp.data)
|
path.readObject(it.data)
|
||||||
val options = PaintOptions(sp.color, sp.strokeWidth)
|
val options = PaintOptions(it.color, it.strokeWidth)
|
||||||
|
|
||||||
canvas.addPath(path, options)
|
canvas.addPath(path, options)
|
||||||
}
|
}
|
||||||
@ -85,14 +85,14 @@ object Svg {
|
|||||||
val pathElement = root.getChild(ns, "path")
|
val pathElement = root.getChild(ns, "path")
|
||||||
|
|
||||||
root.setStartElementListener { attributes ->
|
root.setStartElementListener { attributes ->
|
||||||
val width = Integer.parseInt(attributes.getValue("width"))
|
val width = attributes.getValue("width").toInt()
|
||||||
val height = Integer.parseInt(attributes.getValue("height"))
|
val height = attributes.getValue("height").toInt()
|
||||||
svg.setSize(width, height)
|
svg.setSize(width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
rectElement.setStartElementListener { attributes ->
|
rectElement.setStartElementListener { attributes ->
|
||||||
val width = Integer.parseInt(attributes.getValue("width"))
|
val width = attributes.getValue("width").toInt()
|
||||||
val height = Integer.parseInt(attributes.getValue("height"))
|
val height = attributes.getValue("height").toInt()
|
||||||
val color = Color.parseColor(attributes.getValue("fill"))
|
val color = Color.parseColor(attributes.getValue("fill"))
|
||||||
if (svg.background != null)
|
if (svg.background != null)
|
||||||
throw UnsupportedOperationException("Unsupported SVG, should only have one <rect>.")
|
throw UnsupportedOperationException("Unsupported SVG, should only have one <rect>.")
|
||||||
@ -103,7 +103,7 @@ object Svg {
|
|||||||
pathElement.setStartElementListener { attributes ->
|
pathElement.setStartElementListener { attributes ->
|
||||||
val d = attributes.getValue("d")
|
val d = attributes.getValue("d")
|
||||||
val color = Color.parseColor(attributes.getValue("stroke"))
|
val color = Color.parseColor(attributes.getValue("stroke"))
|
||||||
val width = java.lang.Float.parseFloat(attributes.getValue("stroke-width"))
|
val width = attributes.getValue("stroke-width").toFloat()
|
||||||
svg.paths.add(SPath(d, color, width))
|
svg.paths.add(SPath(d, color, width))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user