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 rasterizer, png not as expected #425

Open
andre2007 opened this issue Mar 5, 2024 · 6 comments
Open

SVG rasterizer, png not as expected #425

andre2007 opened this issue Mar 5, 2024 · 6 comments

Comments

@andre2007
Copy link
Contributor

I really do not have much knowledge about SVG. I write a D binding for Verovio (https://github.com/rism-digital/verovio) which is able to create Midi & SVG file for a given MusicXML file.

I attached the sample SVG file.
sample_svg.zip

In the webbrowser it is rendered like this:

image

When I use svg.d the PNG looks like this:
image

I used this coding and the svg.d from master:

  NSVG* image = nsvgParseFromFile("sample.svg", "px", 96);
    int w = 2000;
    int h = 4000;

    NSVGrasterizer rast = nsvgCreateRasterizer();
    auto img = new TrueColorImage(w, h);
    rasterize(rast, image, 0, 0, 1, img.imageData.bytes.ptr, w, h, w*4);
    image.kill();
    writePng("test.png", img);

Is there an error on my side or is maybe s.th. missing in svg.d?

@adamdruppe
Copy link
Owner

I think here it might just be that the background color is different.... ill try it soon.

@adamdruppe
Copy link
Owner

eh changing the bg color didn't matter, it might also be the symbol id references it uses, that looks incomplete here, and the <symbol> i don't see any implementation for that at all... yeah and if i delete that, the firefox result looks similar.

So that's the problem, <symbol> isn't implemented here.

@adamdruppe
Copy link
Owner

The <use> thing also isn't implemented.

By a quick glance a the spec, symbol is basically a mini-embedded svg you can refer to time and time again with use to paste it in multiple times. But implementing this in the mess of ported C code prolly not easy.

@adamdruppe
Copy link
Owner

It also doesn't support <text> or <tspan> which are also used here.

It has extremely minimal css support so that might also prove to be a limitation but i don't think that'd be very important in this case (biggest effect would be using normal font instead of italic and bold).

Each of these is doable to fix but a pain given that this is essentially C code.

@adamdruppe
Copy link
Owner

....you know one potentially easy answer here is to preprocess it. it'd be tricky to get the viewBox working right with that though. eh prolly not gonna work that easily.

@andre2007
Copy link
Contributor Author

Thanks a lot Adam that you have analyzed it. I will check wheter I can pre process if as suggested by you. Thanks.

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