JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.72k stars 1.14k forks source link

SVG <use/> is not rendered #4102

Open hakanai opened 7 months ago

hakanai commented 7 months ago

Describe the bug If you try to render an SVG which uses the <use/> element, the rendering is skipped.

Affected platforms Select one of the platforms below:

Versions

To Reproduce

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.singleWindowApplication

fun main() = singleWindowApplication {
    MaterialTheme {
        Surface {
            Image(
                painter = painterResource("/3C.svg"),
                contentDescription = "3 of Clubs",
                modifier = Modifier.requiredSize(250.dp, 350.dp)
            )
        }
    }
}

The SVG: 3C

Expected behavior The image should be rendered as in Chrome, IDEA, and other viewers.

Screenshots image

Atlands commented 7 months ago

For now resources library supports only xml vector drawables and other raster formats (png, jpg. webp)

eymar commented 7 months ago

As @Atlands mentioned, indeed, .svg is not supported as is. You can try to convert your svg into xml. Please follow the comment above.

eymar commented 7 months ago

My colleagues told me that actually, .svg is supported for desktop only (without the resources library), not in common. So it's a bug in Compose for Desktop or Skiko.

eymar commented 7 months ago

Reproduced with 1.6.0-dev1357 too.

hakanai commented 7 months ago

Yeah, I've never been sure why Android went and made its own XML format instead of supporting SVG more fully. I remember hitting issues with it way back in the past and thought it might have improved by now.

If I were going to do a rewrite, I think I'd go all the way to rendering the cards in native Kotlin. But that's for later, when I have the time for that kind of exercise. I'll probably make a tool that spits out PDF for printing the actual cards while I'm at it.

okushnikov commented 1 month ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.