adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
530 stars 125 forks source link

SVG rasterizer, png not as expected #425

Open andre2007 opened 4 months ago

andre2007 commented 4 months ago

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 commented 4 months ago

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

adamdruppe commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

....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 commented 4 months ago

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