typst / svg2pdf

Converts SVG files to PDF.
Apache License 2.0
273 stars 32 forks source link

Wavedrom diagram rendering issues (font, dotted lines) #46

Closed magistere closed 7 months ago

magistere commented 10 months ago

Hello, I'm trying to use svg2pdf to convert SVG files of Wavedrom diagrams generated by https://github.com/wallento/wavedrompy, but the rendering of text and dotted lines is different from SVG rendering in the browser and seems wrong. Input SVG: out PDF from svg2pdf:

svg2pdf-output
LaurenzV commented 10 months ago

That's what I get:

image

The font looks right to me, you probably just don't have it installed correctly or for some reason svg2pdf just can't find it. See also #44, font handling is definitely something that should be improved.

As for the dotted lines, something indeed seems to be going wrong here, I will try to investigate it in the next few days.

LaurenzV commented 10 months ago

MRP:

<?xml version="1.0" encoding="utf-8" ?>
<svg height="200"
     width="200" xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
    <g>
        <g transform="translate(80.5,0.5)">
            <path d="m 0,0 0,150" id="gmark_0_0" style="stroke:#888;stroke-width:30;stroke-dasharray:1,3"/>
        </g>
    </g>
</svg>

Output:

image

The bug only seems to appear in Chrome and Adobe Acrobat.

LaurenzV commented 10 months ago

So it boils down to this example:

<svg id="svg1" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
    <path d="M 100,25 L 100,175" fill="blue" stroke-opacity="0" stroke="green" />
</svg>

For some reason, Chrome and Acrobat will apply a fill to a line even though it's just a line...

magistere commented 10 months ago

Thanks, Laurenz! The font issue is resolved, Helvetica is set as font-family in that SVG, and it seems that browsers just handle it as sans-serif on Windows for better compatibility. Yes, dotted-lines issue depends on the PDF viewer. In Firefox the rendering is perfect, but in more popular Chrome and Acrobat it is not.

LaurenzV commented 10 months ago

Yeah, I'll think about how we can circumvent this.

LaurenzV commented 8 months ago

Happy to say that I managed to fix it, but it will be some time before I can open a PR because we need a new release of resvg (which has just been updated, so might probably be a while before that happens).

magistere commented 8 months ago

Great! Thank you!