Skip to content

Commit

Permalink
Reduce duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuwu committed Dec 7, 2024
1 parent 4c3ecaa commit 55f59ff
Showing 1 changed file with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,38 +155,30 @@ class SVG {

event = next()
}

fun extractStrokeFromCommand(originalCommand: String, commandElements: List<String>) {
if (commandElements.size > 3) {
strokeColor = commandElements[3].toULong()
}
if (commandElements.size > 4) {
strokeSize = commandElements[4].toFloat()
}
commands.addLast(SVGCommand.MoveTo.fromString(originalCommand).apply {
paintColor = strokeColor
brushSize = strokeSize
})
}
pathData.split(COMMA).forEach {
val command = it.trim()
if (command.isEmpty()) return@forEach
val commandElements = command.split(" ")

when (command.first()) {
SVGCommand.MoveTo.CODE -> {
if (commandElements.size > 3) {
strokeColor = commandElements[3].toULong()
}
if (commandElements.size > 4) {
strokeSize = commandElements[4].toFloat()
}
commands.addLast(SVGCommand.MoveTo.fromString(command).apply {
paintColor = strokeColor
brushSize = strokeSize
})
extractStrokeFromCommand(originalCommand = command, commandElements = commandElements)
}

SVGCommand.AbsLineTo.CODE -> {
if (commandElements.size > 3) {
strokeColor = commandElements[3].toULong()
}
if (commandElements.size > 4) {
strokeSize = commandElements[4].toFloat()
}
commands.addLast(SVGCommand.MoveTo.fromString(command).apply {
paintColor = strokeColor
brushSize = strokeSize
})
extractStrokeFromCommand(originalCommand = command, commandElements = commandElements)
}

SVGCommand.AbsQuadTo.CODE -> {
if (commandElements.size > 5) {
strokeColor = commandElements[5].toULong()
Expand Down

0 comments on commit 55f59ff

Please sign in to comment.