linebender / resvg

An SVG rendering library.
Apache License 2.0
2.83k stars 228 forks source link

Disappearing elements when transform scale < (1/4096) #648

Closed muglug closed 1 year ago

muglug commented 1 year ago

This is a great project that vastly simplifies building an SVG renderer — thanks for building it.

I ran into a problem that's easy to work around, but ticketing all the same.

This is a simplified version of https://upload.wikimedia.org/wikipedia/commons/0/01/Flag_of_Niue.svg

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="600" height="600" viewBox="-60 -60 120 120">
    <rect x="-50" y="-50" width="100" height="100" fill="#000000"/>
    <rect x="-50000" y="-50000" width="100000" height="100000" fill="red" transform="scale(0.00024)"/>
</svg>

Expected: A black square with a red square inside it Actual: A black square

If you change scale(0.00024) to scale(0.00025) the box appears. The cutover is 1/4096.

Looks like this comes from Transform::is_valid: https://github.com/RazrFalcon/tiny-skia/commit/c56f2c6cff769021ec5071288e156d6ed41e4f52.

IMO when it comes to scale transforms the zero check shoud check values much smaller than 1/4096.

RazrFalcon commented 1 year ago

Interesting. 1/4096 is the default Skia cutoff. And accidentally resvg uses the same one now. Will fix.

muglug commented 1 year ago

Thanks!