alafr / SVG-to-PDFKit

Insert SVG into a PDF document created with PDFKit
MIT License
397 stars 111 forks source link

Handle 0s in stroke-dasharray #162

Closed bendemboski closed 2 years ago

bendemboski commented 2 years ago

In PDFKit >=0.10.0, calling dash() with any 0s in the dash array/length will throw an error. For more info see

https://github.com/foliojs/pdfkit/issues/1060 https://github.com/foliojs/pdfkit/issues/949 https://github.com/foliojs/pdfkit/pull/969

A number of SVG editors, I believe including inkscape, will happily generate stroke-dasharray attributes with 0s in them, and then running them through SVG-to-PDFKit will cause the conversion to fail completely. So, this commit does a bunch of math to rewrite dash arrays containing 0s to eliminate the zeros, but still achieve the same result.

This commit also updates the version of PDFKit the examples use to the latest (0.13.0) and adds a test that exercises a bunch of stroke-dasharray scenarios with 0s in them.