https://kotlinlang.org logo
Title
o

orangy

07/19/2021, 5:23 PM
SVGPainter
seems to ignore
Density
for stroke width, and uses it for
intrinsicSize
only. It makes rendering inconsistent – graphics appear too thin. Is it a known issue?
1
i

Igor Demin

07/19/2021, 8:43 PM
It isn't a known issue. Can you provide the SVG with the issue?
o

orangy

07/19/2021, 9:10 PM
It’s a trivial path with strokewidth (check mark for checkbox control). AFK right now… Paths painted by compose at 2.dp is equivalent to svg painted with storkewidth 4
<svg width="18" height="14" viewBox="0 0 18 14" fill="none" xmlns="<http://www.w3.org/2000/svg>">
    <path d="M1 6.46197L6.29819 12L17 1" stroke="white" stroke-width="4"/>
</svg>
:tnx: 1
i

Igor Demin

07/19/2021, 10:12 PM
Everything draws correctly on my side
import androidx.compose.desktop.Window
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.loadSvgResource
import androidx.compose.ui.unit.Density

fun main() = Window {
    Row {
        CompositionLocalProvider(LocalDensity provides Density(1f)) {
            Test()
        }
        CompositionLocalProvider(LocalDensity provides Density(2f)) {
            Test()
        }
        CompositionLocalProvider(LocalDensity provides Density(4f)) {
            Test()
        }
    }
}

@Composable
private fun Test() {
    val density = LocalDensity.current
    val svg = remember(density) {
        loadSvgResource(
            """
                <svg width="18" height="14" viewBox="0 0 18 14" fill="none" xmlns="<http://www.w3.org/2000/svg>">
                    <path d="M1 6.46197L6.29819 12L17 1" stroke="black" stroke-width="4"/>
                </svg>
            """.trimIndent().byteInputStream(),
            density
        )
    }

    Image(
        svg,
        contentDescription = null
    )
}
Compose 0.5.0-build226
o

orangy

07/20/2021, 10:01 AM
Yeah, my bad, sorry 🙏