cppfw / svgren

:camera: SVG rendering library in C++
MIT License
206 stars 41 forks source link

tiger.svg not rendering correctly #16

Closed JaimeIvanCervantes closed 7 years ago

JaimeIvanCervantes commented 7 years ago

Hello, I was able to render camera.svg and other 3 simple svgs correctly using the example on tests/render/main.cpp but tiger.svg is failing to render properly:

Here's my result when rendering the file camera.svg: camera

And here's my result when rendering the file tiger.svg: tiger

I use the exact same code for both, the only thing that I changed was the name of the file. I wonder if this is just happening to me, or if you also are seeing this issue too?

saeitsystems commented 7 years ago

In my application svgren renders the tiger.svg without problems: grafik

(under windows with VisualStudio 2015)

igagis commented 7 years ago

I also don't see problems with tiger.svg, at least I tried recently under Windows and under Linux. @JaimeIvanCervantes on which OS are you trying?

saeitsystems commented 7 years ago

I got a different tiger.svg from wikipedia which causes an assertion in svgren: grafik

See attached tiger.svg image tiger.zip

igagis commented 7 years ago

Hm, interesting, let me try...

igagis commented 7 years ago

Ok, it uses Cubuc_Smooth_Rel elements in some path which is not implemented in svgren. I need to implement it.

saeitsystems commented 7 years ago

It is not urgent to me but since it is a standard file on wikipmedia it would be better not to have an assertion ... https://commons.wikimedia.org/wiki/File:Ghostscript_Tiger.svg

igagis commented 7 years ago

svgren is not a complete support of the SVG standard yet, as the standard is quite big, so I implement features on demand. So thank you for finding missing stuff and providing sample SVGs for those, I add all such SVGs to the test data set. Assertions are only active in Debug configuration, in Release there are no assertions done, but I checked that tiger.svg in Relese mode, it looks quite distorted :)

saeitsystems commented 7 years ago

In release mode I got this result: grafik

igagis commented 7 years ago

Yep, it's quite distorted because of those missing path steps. I'm trying to fix it now.

saeitsystems commented 7 years ago

Interesting is that the new tiger.svg from mediawiki looks identical but the file is about 30% smaller than your test tiger.svg

igagis commented 7 years ago

@saeitsystems obviously, it is because in my tiger.svg version smooth curve steps are converted to non-smooth ones, which are basically identical, only that smooth ones are shorter in writing. You can see more about smooth/non-smooth cubic curve path steps here https://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands

saeitsystems commented 7 years ago

@igagis that looks quite complicated .... I think your library is already doing a very good job! Are there any favorite SVG editors you would recomend? I use AffinityDesigner on Windows or Mac. I tried Inkscape - I didn't like it because it is slow, the GUI is complicated and not standard windows and there is no UHD support.

igagis commented 7 years ago

Well, I'm not drawing much SVGs on my own, but when I need to check something or edit some SVG I use Inkscape. Because I mainly use Linux envirnoment, it is easy to install it there and it is quite sufficient for small SVG tweaks. I did not search for better editors, so, no idea what else is available.

JaimeIvanCervantes commented 7 years ago

I am using macOS Sierra with clang-802.0.42 and cairo 1.14.10 (using Homebrew), and I'm saving the results to png with the changes on my PR: https://github.com/igagis/svgren/pull/17

camera.svg and other svgs were rendered correctly, it's only tiger.svg that doesn't work. Hmm maybe it's something on my side, I'll keep investigating.

igagis commented 7 years ago

Ok, I think I have also seen some strange results on MacOS, but not that big as your tiger.svg. I will try to reproduce on MacOS.

igagis commented 7 years ago

I reproduced the problem with tiger.svg on MacOS, same as @JaimeIvanCervantes observes, investigating...

igagis commented 7 years ago

For some reason, on MacOS the std lib works differently than on other systems. The problem which causes the tiger.svg bug is that on MacOS the following assertion fails:

std::istringstream s("0c");
float d;
s >> d;
assert(!s.fail())

any idea how to workaround this?

JaimeIvanCervantes commented 7 years ago

I am reproducing the failed assertion:

#include <iostream>
#include <sstream>
#include <assert.h>

using namespace std;

int main() {
        std::istringstream s("0c");
        float d;
        s >> d;

        cout<<"d="<<d<<endl;

        if (s.fail()) {
                cout<<"Error"<<endl;
        }

        assert(!s.fail());

        return 0;
}

And here's the output:

d=0
Error
Assertion failed: (!s.fail()), function main, file istreamstringError.cpp, line 18.
Abort trap: 6

Thinking about best way to get around it.

JaimeIvanCervantes commented 7 years ago

I think the c next to the 0 is causing the failure. When I use std::istringstream s("0") I don't get any errors.

igagis commented 7 years ago

Sure, but the problem is that exactly this "0c" is a valid part of SVG document which is to be parsed as number 0 and 'c' should be ignored. I'm now implementing some workaround for this.

igagis commented 7 years ago

@JaimeIvanCervantes Ok, the problem was actually in svgdom. I made a workaround. The svgdom version 0.2.36 is coming soon, here is the travis build: https://travis-ci.org/igagis/svgdom/builds when it is done, you can upgrade svgdom via Homebrew.

JaimeIvanCervantes commented 7 years ago

Excellent thanks for the quick fix! I actually have my own cmake file with svgdom and svgren dependencies, so I just pulled your changes and it works like a charm, tiger.svg is rendering correctly now ;)

igagis commented 7 years ago

There is still other issue with Wikipedia tiger.svg, so reopening this bug for now, though the fix will come soon.

igagis commented 7 years ago

@saeitsystems Ok, new packages released to nuget: svgdom version 0.2.40 svgren version 0.4.20 please try and close the bug.

saeitsystems commented 7 years ago

The Tiger from wikimedia renders fine now grafik

It seems, I can't close the bug because I didn't open ist

igagis commented 7 years ago

Good, and Jaime also reported that he had no problems on MacOS now. So, closing the bug. Thank you!