DevSrSouza / svg-to-compose

Converts SVG and Android Vector Drawable in Compose Multiplatform source code
MIT License
418 stars 36 forks source link

Consider using a PathParser #26

Open bartek-wesolowski opened 6 months ago

bartek-wesolowski commented 6 months ago

Instead of constructing images like this:

path(fill = SolidColor(Color(0xFFfcf7d2)), stroke = null, strokeLineWidth = 0.0f,
        strokeLineCap = Butt, strokeLineJoin = Miter, strokeLineMiter = 4.0f,
        pathFillType = NonZero) {
    moveTo(1037.06f, 87.81f)
    horizontalLineToRelative(92.36f)
    lineTo(1129.42f, 22.7f)
    lineTo(1026.06f, 22.7f)
    verticalLineToRelative(54.12f)
    curveToRelative(0.0f, 6.07f, 4.93f, 11.0f, 11.0f, 11.0f)
}

Consider using a PathParser

addPath(
    PathParser().parsePathString(
        "M256 0 c4.6 0 9.2 1 13.4 2.9 l188.3 79.9 c22 9.3 38.4 31 38.3 57.2 -0.5 99.2 -41.3 280.7 -213.6 363.2 -16.7 8 -36.1 8 -52.8 0 C57.3 420.7 16.5 239.2 16 140 c-0.1 -26.2 16.3 -47.9 38.3 -57.2 L242.7 2.9 C246.8 1 251.4 0 256 0z m0 66.8 v378 C394 378 431.1 230.1 432 141.4 L256 66.8z"
    ).toNodes()
)

This would make the result code much shorter and possibly help (partially) solve https://github.com/DevSrSouza/svg-to-compose/issues/16 with MethodTooLargeException.

Goooler commented 2 months ago

You can try out https://github.com/ComposeGears/Valkyrie.