typst/svg2pdf

PDF content generated from SVG <pattern> jumps when zoom in/out in Safari

Legonaftik opened this issue · 3 comments

input.svg -> output.pdf

The expected behaviour is that the red line should be horizontally aligned with one of the blue lines (with the <pattern>). The output PDF looks as expected in Chrome and Preview apps but in Safari <pattern> jumps a bit up/down when changing the zoom level.

Is it something that can be fixed by modifying the SVG2PDF conversion flow? Since I could only reproduce this issue with <pattern> then maybe there is an alternative way of representing it before trying to create PDF? 🤔

mozilla/pdf.js#11473
It looks like tile-based rendering of PDF Patterns is tricky and other projects, including Mozilla, also facing (or at least faced) the same issue.

https://github.com/typst/svg2pdf/blob/main/src/render.rs#L427
Would it be a good alternative to avoid PDF Pattern syntax and replace SVG <pattern> with multiple instances of content that should be repeated/tiled directly (e.g. line/rect/path/...) assuming that at this stage of the pipeline all the dimensions are already absolute (thanks to usvg) so it's possible to calculate how many items/cells need to be repeated?

Is it something that can be fixed by modifying the SVG2PDF conversion flow? Since I could only reproduce this issue with then maybe there is an alternative way of representing it before trying to create PDF? 🤔

You probably could in theory try to emulate the pattern behavior, but I would imagine this to be a nightmare to implement, especially because patterns can also have transforms themselves and this would be very hard to recreate. Given that PDFs support patterns natively, we should also use them for that. It also would be very bad for performance. The best thing to do here would be to report this issue to Apple directly and hope that they fix it, since this is an issue on their side.

I'm closing this since there isn't much we can do about that from our side.