-
Notifications
You must be signed in to change notification settings - Fork 15
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
Use usvg to convert SVG to TinyVG. #5
Conversation
This looks promising! Before i merge this i wanna make sure that i can run the benchmarks with the new version as well. First thing i noticed: It doesn't do invalid argument checking. passing Have you enabled PR editing? I'd like to try fixing it myself to get some hands on Rust |
Yes, editing is enabled. This is not a final version since I plan to add binary writing first. So not need to merge it anytime soon. Benchmarking of what? SVG to TinyVG conversion? usvg supports like 20x more than the previous version, so it would be apples and oranges. |
Okay, cool. I fixed two bugs in the text generation so i can actually convert to text format. I would keep it that way until we know that everything works as using the text format is definitly easier for debugging and we know that there aren't encoder errors, but only converter errors
The benchmark also yields the PDF comparison renderings which i'm generating right now. I will upload my test set for this here, including the SVG input and the PDF output, so you can run the same tests locally. FreeSVG is truly a source of fucked up SVG files 😆 Get the files here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already identified places where some bugs happen
If you're looking for really bad SVG, you're welcome: https://github.com/RazrFalcon/resvg-test-suite/tree/master/svg |
I will take a look into binary encoding tomorrow. |
Thanks for creating that, works quite well already! :) I have a couple users already using that converter and some of them asked if it would be possible to add |
Can you provide a file that fails? |
Sure, sorry should have provided that in the first comment. Commit:
Produces a completely purple (=> transparent) tga file: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><defs><radialGradient id="a" cx="71.845" cy="47.719" r="25.128" gradientTransform="matrix(-.00903 -2.7717 2.0794 -.00409 -67.416 1235.7)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#f2e916"/><stop offset=".312" stop-color="#f11e25"/><stop offset=".729" stop-color="#f2e916"/><stop offset="1" stop-color="#f11e25"/></radialGradient><radialGradient id="b" cx="32.209" cy="49.871" r="16.697" gradientTransform="matrix(2.1889 -.3504 .62278 4.0978 -71.12 844.64)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#faff00"/><stop offset="1" stop-color="#ff713f"/></radialGradient></defs><path fill="url(#a)" d="M4.266 1016.5C14.937 1013.796 17.004 1014.653 15.458 1021.59 17.855 1013.492 13.768 1001.975 6.876 991.75 15.748 992.064 23.083 1001.222 22.648 1017.943 21.83 1005.929 29.175 996.344 35 989.995 34.664 994.485 34.825 1000.25 33.758 1007.307 32.518 1015.514 33.149 1017.597 33.149 1017.597 31.583 1008.956 35.228 1004.69 46.037 992.687 41.406 999.777 45.16 1013.712 43.768 1024.078 42.438 1008.118 53.52 1012.987 52.06 1005.31 53.988 1013.405 48.532 1024.33 49.808 1030.614 53.518 1025.564 53.36 1021.269 53.096 1015.744 55.046 1018.736 54.894 1018.545 55.64 1020.48 59.72 1036.467 55.13 1047.895 35.77 1049.283 25.072 1050.572-4.904 1044.224 9.304 1028.311 11.298 1026.077 15.955 1018.187 4.265 1016.501z" transform="translate(0 -988.36)"/><path fill="url(#b)" d="M17.038 1016.7C12.165 1029.149-19.714 1033.538 32.169 1050.301 50.288 1047.631 64.911 1047.471 61.943 1019.407 59.413 1036.471 55.711 1031.362 51.216 1036.801 55.766 1033.154 51.356 1019.516 58.262 1010.959 51.779 1012.219 46.3 1030.145 39.077 1033.493 56.044 1016.708 42.755 1010.653 48.345 997.539 47.107 1007.543 35.96 1006.53 35.425 1022.784 35.173 1017.072 35.472 1023.199 35.58 1017.284 35.73 1009.09 33.356 1000.77 38.36 991.676 33.66 991.485 20.075 1026.247 24.61 1034.4 19.195 1025.075 28.31 1007.135 16.306 988.49 20.823 1009.465 18.817 1010.328 17.039 1016.7z" transform="matrix(.81593 -.10258 .10857 .86357 -107.09 -843.32)"/></svg> Even though it generates output:
Here is a zip file with svg, tvgt, tvg and tga files: fire-1295306.zip |
|
Hello, I've been working with Lyze and I'm hoping to make a video about TinyVG in a couple months. In using the converter in my workflow, I noticed that SVG's that I've made implement a sort of crop to cut off parts of the image. Can the converter cut these parts off or should that be left to the libraries implementing TinyVG? Please see below: Resulting TVG Thanks for your consideration. |
@raeleus Can you provide both images as PNG to clearly see the difference? |
Seem like a |
@raeleus what renderer do you use?
|
I'm using Lyze's implementation for libGDX, but it looks like he figured out a solution. Thanks for the help! |
Can you provide a textual/lisp output of the .Net version? usvg is definitely correct here, meaning I'm writing curves wrong.
This is the correct output, according to SVG. It has a concept of zero-length paths. I assume TinyVG doesn't. Will skip them then. |
Sure! settings.tvgt
Yeah, an empty path doesn't make sense in the design of TinyVG. I think it's enough to strip off any single
I know, the .NET conversion tool already handles this case |
I've converted the produced tvgt to SVG by hand and it looks perfectly fine. So the data is correct. Maybe I misunderstood the spec somewhere? <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24">
<path d="
M 12 15.5
C 10.067003375592224 15.5 8.5 13.932996624407778 8.5 12
C 8.5 10.067003375592224 10.067003375592222 8.5 12 8.5
C 13.932996624407778 8.5 15.5 10.067003375592222 15.5 12
C 15.5 13.93299662440777 13.932996624407778 15.5 12 15.5
M 19.43 12.97
C 19.47 12.65 19.5 12.33 19.5 12
C 19.5 11.67 19.47 11.34 19.43 11
L 21.54 9.37
C 21.73 9.22 21.78 8.95 21.66 8.73
L 19.66 5.27
C 19.54 5.05 19.27 4.96 19.05 5.05
L 16.56 6.05
C 16.04 5.66 15.5 5.32 14.87 5.07
L 14.5 2.42
C 14.46 2.18 14.25 2 14 2
L 10 2
C 9.75 2 9.54 2.18 9.5 2.42
L 9.13 5.07
C 8.5 5.32 7.96 5.66 7.44 6.05
L 4.95 5.05
C 4.73 4.96 4.46 5.05 4.34 5.27
L 2.34 8.73
C 2.21 8.95 2.27 9.22 2.46 9.37
L 4.57 11
C 4.53 11.34 4.5 11.67 4.5 12
C 4.5 12.33 4.53 12.65 4.57 12.97
L 2.46 14.63
C 2.27 14.78 2.21 15.05 2.34 15.27
L 4.34 18.73
C 4.46 18.95 4.73 19.03 4.95 18.95
L 7.44 17.94
C 7.96 18.34 8.5 18.68 9.13 18.93
L 9.5 21.58
C 9.54 21.82 9.75 22 10 22
L 14 22
C 14.25 22 14.46 21.82 14.5 21.58
L 14.87 18.93
C 15.5 18.67 16.04 18.34 16.56 17.94
L 19.05 18.95
C 19.27 19.03 19.54 18.95 19.66 18.73
L 21.66 15.27
C 21.78 15.05 21.73 14.78 21.54 14.63
L 19.43 12.97
Z"/>
</svg> The only difference I see is that you file has resolution of 1/1024, while mine is 1/1. I would suggest double-checking the tvgt-to-tvg converter or the renderer. |
The arc definition has one boolean that is inversly defined to SVG. Here are: Original SVG<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24">
<path d="M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z" />
</svg> conversion output of .NET converter
back conversion of .NET converter<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path style="fill:#000000;stroke:none;" d="M12,15.5A3.5,3.5,0,0,1,8.5,12A3.5,3.5,0,0,1,12,8.5A3.5,3.5,0,0,1,15.5,12A3.5,3.5,0,0,1,12,15.5M19.4296875,12.9697265625C19.4697265625,12.650390625,19.5,12.330078125,19.5,12C19.5,11.669921875,19.4697265625,11.33984375,19.4296875,11L21.5400390625,9.3701171875C21.73046875,9.2197265625,21.7802734375,8.9501953125,21.66015625,8.73046875L19.66015625,5.26953125C19.5400390625,5.0498046875,19.26953125,4.9599609375,19.0498046875,5.0498046875L16.5595703125,6.0498046875C16.0400390625,5.66015625,15.5,5.3203125,14.8701171875,5.0703125L14.5,2.419921875A0.505859375,0.505859375,0,0,0,14,2H10C9.75,2,9.5400390625,2.1796875,9.5,2.419921875L9.1298828125,5.0703125C8.5,5.3203125,7.9599609375,5.66015625,7.4404296875,6.0498046875L4.9501953125,5.0498046875C4.73046875,4.9599609375,4.4599609375,5.0498046875,4.33984375,5.26953125L2.33984375,8.73046875C2.2099609375,8.9501953125,2.26953125,9.2197265625,2.4599609375,9.3701171875L4.5703125,11C4.5302734375,11.33984375,4.5,11.669921875,4.5,12C4.5,12.330078125,4.5302734375,12.650390625,4.5703125,12.9697265625L2.4599609375,14.6298828125C2.26953125,14.7802734375,2.2099609375,15.0498046875,2.33984375,15.26953125L4.33984375,18.73046875C4.4599609375,18.9501953125,4.73046875,19.0302734375,4.9501953125,18.9501953125L7.4404296875,17.9404296875C7.9599609375,18.33984375,8.5,18.6796875,9.1298828125,18.9296875L9.5,21.580078125C9.5400390625,21.8203125,9.75,22,10,22H14C14.25,22,14.4599609375,21.8203125,14.5,21.580078125L14.8701171875,18.9296875C15.5,18.669921875,16.0400390625,18.33984375,16.5595703125,17.9404296875L19.0498046875,18.9501953125C19.26953125,19.0302734375,19.5400390625,18.9501953125,19.66015625,18.73046875L21.66015625,15.26953125C21.7802734375,15.0498046875,21.73046875,14.7802734375,21.5400390625,14.6298828125L19.4296875,12.9697265625Z"/>
</svg> conversion output of Rust converter
back conversion of Rust converter<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path style="fill:#000000;stroke:none;" d="M12,16C10,16,9,14,9,12C9,10,10,9,12,9C14,9,16,10,16,12C16,14,14,16,12,16M19,13C19,13,20,12,20,12C20,12,19,11,19,11L22,9C22,9,22,9,22,9L20,5C20,5,19,5,19,5L17,6C16,6,16,5,15,5L15,2C14,2,14,2,14,2L10,2C10,2,10,2,10,2L9,5C9,5,8,6,7,6L5,5C5,5,4,5,4,5L2,9C2,9,2,9,2,9L5,11C5,11,5,12,5,12C5,12,5,13,5,13L2,15C2,15,2,15,2,15L4,19C4,19,5,19,5,19L7,18C8,18,9,19,9,19L10,22C10,22,10,22,10,22L14,22C14,22,14,22,15,22L15,19C16,19,16,18,17,18L19,19C19,19,20,19,20,19L22,15C22,15,22,15,22,15L19,13Z"/>
</svg> |
I'm not sure I understood the problem. There are no arcs after the Rust converter. They will be converted into curves. |
Then it looks like this conversion from arc to bezier might be wrong? The C# converter just uses the absolute coordinates and passes them to TinyVG, so bezier rendering is definitly correct on my end |
ArcTo to CurveTo is guarantee to be correct. It is well tested. And |
I think we both have ignored that fact. Sorry for accusing your project of invalid data 🙇 This is the problem here. Changing this to |
Good. Can you point me to the code that does precision optimization so I can port it to Rust? |
It's this part here: sdk/src/tools/svg2tvgt/svg2tvgt.cs Lines 462 to 526 in f82d465
combined with this: sdk/src/tools/svg2tvgt/svg2tvgt.cs Lines 1457 to 1474 in f82d465
|
Thanks, I will take a look. |
A bare minimum implementation. Produces only text version of TinyVG.
Adds basically full SVG support. resvg is one of the best SVG parsers out there. More specifically it adds text, markers, all the shapes, full SVG path support, CSS, referenced gradients,
use
/symbol
resolving, nested svg and many many more.Unlike C# version, the final binary is just 2MB or even less if we disable text and strip it.
Unsupported:
Closes #3