Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG data parsing results in IllegalArgumentException #518

Open
pusolito opened this issue Mar 18, 2022 · 3 comments
Open

SVG data parsing results in IllegalArgumentException #518

pusolito opened this issue Mar 18, 2022 · 3 comments

Comments

@pusolito
Copy link

pusolito commented Mar 18, 2022

The following is valid SVG data and works in this fiddle.

"M12.5 11H11.71L11.43 10.73A6.471 6.471 0 0013 6.5 6.5 6.5 0 106.5 13C8.11 13 9.59 12.41 10.73 11.43L11 11.71V12.5L16 17.49 17.49 16 12.5 11ZM6.5 11C4.01 11 2 8.99 2 6.5S4.01 2 6.5 2 11 4.01 11 6.5 8.99 11 6.5 11Z"

However, it fails to parse in 0.7.16.

file: .../commonMain/org/jetbrains/skia/Path.kt

fun makeFromSVGString(svg: String): Path  {
    Stats.onNativeCall()
    val result = interopScope {
        _nMakeFromSVGString(toInterop(svg))
    }

    if (result == NullPointer) {
       throw IllegalArgumentException("Failed to parse SVG Path string: $svg") // <=========== Gets here b/c result is NullPointer
    } else {
        return Path(result)
    }
 }
@pusolito
Copy link
Author

Any updates on this issue? It is a blocker for apps that rely on SVG.

@Nekoyue
Copy link
Contributor

Nekoyue commented May 10, 2022

Found a possible cause/fix for this issue. It seems like a formatting issue with non-standard representations of arcs. The code will work after adding spaces like the image below. Some SVG optimization tools (e.g. https://www.svgviewer.dev/ ) may be able to do this automatically.
image

@pusolito
Copy link
Author

Thanks for following up. These changes resolved my issue. It's interesting that some engines are more lenient in their parsing. But it makes more sense to have clean inputs when possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants