com.intellij.ui.svg.loadSvg replacement

What is the correct alternative for “com.intellij.ui.svg.loadSvg()”?

Code:

val url = URI.create(iconUrl).toURL()
val svgContent = url.readText()
val bufferedImage: BufferedImage = loadSvg(
    data = svgContent.byteInputStream().readBytes(),
    scale = scale.toFloat(),
)
val loadedIcon = ImageIcon(bufferedImage)

Requirement:
Using an SVG URL, I need to get a scaled version of it to render it in the UI.

SVGLoader is also internal.
Suggested alternatives like ImageLoader, IconLoader do not scale as expected for SVGs.

Source code for reference: material-symbols/Material Symbols/src/main/kotlin/com/makeappssimple/material/symbols/cache/IconsCache.kt at main · Abhimanyu14/material-symbols · GitHub

We use JSVG under the hood, maybe you can use it directly?

Hi @yuriy.artamonov ,
Are you referring to this one?
‘com.intellij.ui.svg.JSvgDocument.Companion’ is declared in unstable ‘com.intellij.ui.svg.JSvgDocument’ marked with @ApiStatus.Internal.

No, to original JSVG library

JetBrains is using a forked version of JSVG. Unfortunately, some useful APIs are private in this version (I don’t know why).
Consider using the original JSVG: GitHub - weisJ/jsvg: Java SVG renderer. Its APIs are more open.
If you want to stick to the JetBrains’ fork, you can scale your imagesby using ImageUtil.scaleImage. This is what I’m doing in a plugin. I found no workaround to load an image from bytes, so I load images from files directly (file://) or from resources.

Able to get the required scaling with the original JSVG library.
Thank You!

Didn’t try, but IconLoader.findIcon(url) should be the right way.

@m.sciachero ,
Unfortunately, that doesn’t work as expected for me.