Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dev.tonholo.s2c.domain.svg.toBrush
import dev.tonholo.s2c.error.ErrorCode
import dev.tonholo.s2c.error.ExitProgramException
import dev.tonholo.s2c.extensions.EMPTY
import dev.tonholo.s2c.extensions.indented
import dev.tonholo.s2c.extensions.prependIndent
import dev.tonholo.s2c.geom.AffineTransformation
import dev.tonholo.s2c.geom.applyTransformations
import dev.tonholo.s2c.logger.debug
Expand Down Expand Up @@ -128,7 +128,7 @@ sealed interface ImageVectorNode : MethodSizeAccountable {

val pathParamsString = if (pathParams.isNotEmpty()) {
"""(
|${pathParams.joinToString("\n") { (param, value) -> "$param = $value,".indented(4) }}
|${pathParams.joinToString("\n") { (param, value) -> "$param = $value,".prependIndent(4) }}
|)"""
} else {
""
Expand Down Expand Up @@ -260,8 +260,8 @@ sealed interface ImageVectorNode : MethodSizeAccountable {
}
val value = """
|PathData {
| ${clipPathData.indented(indentSize = 4)}
|${"}".indented(indentSize)}"""
| ${clipPathData.prependIndent(indentSize = 4)}
|${"}".prependIndent(indentSize)}"""
.trimMargin()
add(CLIP_PATH_PARAM_NAME to value)
}
Expand Down Expand Up @@ -289,10 +289,10 @@ sealed interface ImageVectorNode : MethodSizeAccountable {
val groupParamsString = if (groupParams.isNotEmpty()) {
val params = groupParams.joinToString("\n") { (param, value) ->
if (param == CLIP_PATH_PARAM_NAME && minified.not() && params.clipPath != null) {
"${"// ${params.clipPath.normalizedPath}".indented(4)}\n"
"${"// ${params.clipPath.normalizedPath}".prependIndent(4)}\n"
} else {
""
} + "$param = $value,".indented(indentSize)
} + "$param = $value,".prependIndent(indentSize)
}
"""(
|$params
Expand Down Expand Up @@ -470,10 +470,10 @@ private fun createNode(
throw e
}

private inline fun resetDotCount(current: Char): Int =
private fun resetDotCount(current: Char): Int =
if (current == '.') 1 else 0

private inline fun calculateDotCount(char: Char, dotCount: Int, lastChar: Char): Int =
private fun calculateDotCount(char: Char, dotCount: Int, lastChar: Char): Int =
if (char == '.') {
dotCount + 1
} else if ((lastChar.isDigit() && char.isWhitespace()) || lastChar.isWhitespace()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ enum class PathCommand(
}
}

inline fun String.removeSuffix(pathCommand: PathCommand): String =
fun String.removeSuffix(pathCommand: PathCommand): String =
removeSuffix(pathCommand.value.toString())

inline fun Char.toPathCommand(): PathCommand? {
fun Char.toPathCommand(): PathCommand? {
return when (this) {
PathCommand.ArcTo.value -> PathCommand.ArcTo
PathCommand.CurveTo.value -> PathCommand.CurveTo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@

package dev.tonholo.s2c.domain

import dev.tonholo.s2c.domain.PathNodes.ArcTo
import dev.tonholo.s2c.domain.PathNodes.CurveTo
import dev.tonholo.s2c.domain.PathNodes.HorizontalLineTo
import dev.tonholo.s2c.domain.PathNodes.LineTo
import dev.tonholo.s2c.domain.PathNodes.MoveTo
import dev.tonholo.s2c.domain.PathNodes.QuadTo
import dev.tonholo.s2c.domain.PathNodes.ReflectiveCurveTo
import dev.tonholo.s2c.domain.PathNodes.ReflectiveQuadTo
import dev.tonholo.s2c.domain.PathNodes.VerticalLineTo
import dev.tonholo.s2c.extensions.indented
import dev.tonholo.s2c.extensions.prependIndent
import dev.tonholo.s2c.extensions.removeTrailingZero
import dev.tonholo.s2c.extensions.toInt
import dev.tonholo.s2c.parser.method.MethodSizeAccountable
Expand Down Expand Up @@ -119,7 +110,7 @@ sealed class PathNodes(
val separator = if (minified || forceInline) "" else "\n"
val scape = if (minified || forceInline) " " else "|"
return joinToString(separator) {
"$scape${it.indented(indentSize)},"
"$scape${it.prependIndent(indentSize)},"
}.let {
if (minified || forceInline) it.substring(1, it.length - 1) else "\n$it\n"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class AvgRootNode(
}
}

inline fun AvgRootNode.asNodes(
fun AvgRootNode.asNodes(
minified: Boolean,
): List<ImageVectorNode> = children.mapNotNull { node ->
(node as? AvgNode)?.asNode(minified)
}

inline fun AvgNode.asNode(
fun AvgNode.asNode(
minified: Boolean,
): ImageVectorNode? = when (this) {
is AvgGroupNode -> asNode(minified)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.tonholo.s2c.domain.compose

import dev.tonholo.s2c.extensions.indented
import dev.tonholo.s2c.extensions.prependIndent
import dev.tonholo.s2c.parser.method.MethodSizeAccountable
import kotlin.jvm.JvmInline

Expand Down Expand Up @@ -111,18 +111,18 @@ sealed interface ComposeBrush : ComposeType<String>, MethodSizeAccountable {
appendColors(stops, colors, INDENT_SIZE)
start.toCompose().let {
if (it != ComposeOffset.ZERO) {
appendLine("start = $it,".indented(INDENT_SIZE))
appendLine("start = $it,".prependIndent(INDENT_SIZE))
}
}
end.toCompose().let {
if (it != ComposeOffset.INFINITE) {
appendLine("end = $it,".indented(INDENT_SIZE))
appendLine("end = $it,".prependIndent(INDENT_SIZE))
}
}
if (tileMode != null && tileMode != GradientTileMode.Clamp) {
appendLine("tileMode = ${tileMode.toCompose()},".indented(INDENT_SIZE))
appendLine("tileMode = ${tileMode.toCompose()},".prependIndent(INDENT_SIZE))
}
append(")".indented(INDENT_SIZE / 2))
append(")".prependIndent(INDENT_SIZE / 2))
}
}

Expand Down Expand Up @@ -153,15 +153,15 @@ sealed interface ComposeBrush : ComposeType<String>, MethodSizeAccountable {
appendLine(".radialGradient(")
appendColors(stops, colors, INDENT_SIZE)
if (center != null && center != ComposeOffset.Infinite) {
appendLine("center = ${center.toCompose()},".indented(INDENT_SIZE))
appendLine("center = ${center.toCompose()},".prependIndent(INDENT_SIZE))
}
if (radius != null) {
appendLine("radius = ${radius}f,".indented(INDENT_SIZE))
appendLine("radius = ${radius}f,".prependIndent(INDENT_SIZE))
}
if (tileMode != null && tileMode != GradientTileMode.Clamp) {
appendLine("tileMode = ${tileMode.toCompose()},".indented(INDENT_SIZE))
appendLine("tileMode = ${tileMode.toCompose()},".prependIndent(INDENT_SIZE))
}
append(")".indented(INDENT_SIZE / 2))
append(")".prependIndent(INDENT_SIZE / 2))
}
}

Expand Down Expand Up @@ -189,9 +189,9 @@ sealed interface ComposeBrush : ComposeType<String>, MethodSizeAccountable {
appendLine(".sweepGradient(")
appendColors(stops, colors, INDENT_SIZE)
if (center != null) {
appendLine("center = ${center.toCompose()},".indented(INDENT_SIZE))
appendLine("center = ${center.toCompose()},".prependIndent(INDENT_SIZE))
}
append(")".indented(INDENT_SIZE / 2))
append(")".prependIndent(INDENT_SIZE / 2))
}
}
}
Expand All @@ -203,15 +203,15 @@ private fun StringBuilder.appendColors(
indent: Int,
) {
if (stops.isNullOrEmpty()) {
appendLine("colors = listOf(".indented(indent))
appendLine("colors = listOf(".prependIndent(indent))
colors
.asSequence()
// filter not valid Compose colors
.mapNotNull { it.toCompose() }
// add indentation
.map { "$it,".indented(indent * 2) }
.map { "$it,".prependIndent(indent * 2) }
.forEach(::appendLine)
appendLine("),".indented(indent))
appendLine("),".prependIndent(indent))
} else {
stops
.zip(colors)
Expand All @@ -222,7 +222,7 @@ private fun StringBuilder.appendColors(
}
.map { (stop, color) ->
// map to vararg arguments
"${stop}f to $color,".indented(indent)
"${stop}f to $color,".prependIndent(indent)
}
.forEach(::appendLine)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ abstract class SvgElementNode<out T>(
when (it) {
is SvgChildNode<*> -> it.copy(parent = this)
is SvgElementNode<*> -> it.copy(parent = this)
else -> it
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,12 @@ abstract class XmlChildNode(
private set

val rootParent: XmlParentNode by lazy {
var current: XmlChildNode
var current: XmlChildNode = this
var currentParent = parent
do {
while (currentParent !is XmlRootNode) {
current = currentParent as XmlChildNode
currentParent = when (currentParent) {
is XmlRootNode -> break
else -> current.parent
}
} while (currentParent !is XmlRootNode)

currentParent = current.parent
}
// XmlRootNode is the Document itself and not an actual node.
// Because of that, we return the direct child that we use to
// access its parent to reach the XmlRootNode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open class ExitProgramException(
}
}

inline fun ExitProgramException(
fun ExitProgramException(
errorCode: ErrorCode,
message: String,
throwable: Throwable? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ fun String.camelCase(): String = replaceDividers()
fun String.pascalCase(): String = replaceDividers()
.replaceFirstChar { it.uppercaseChar() }

@Deprecated(
message = "Use prependIndent instead",
replaceWith = ReplaceWith(expression = "this.prependIndent(indentSize)"),
)
fun String.indented(indentSize: Int) = " ".repeat(indentSize) + this

/**
* Prepends an indent to the string.
*/
Expand Down Expand Up @@ -102,4 +96,4 @@ fun String.toPercentage(): Float {
/**
* Removes trailing zeros from a string representing a number.
*/
inline fun String.removeTrailingZero(): String = replace("\\.0\\b".toRegex(), "")
fun String.removeTrailingZero(): String = replace("\\.0\\b".toRegex(), "")
Loading