yWorks / svg2pdf.js

A javascript-only SVG to PDF conversion utility that runs in the browser. Brought to you by yWorks - the diagramming experts
MIT License
666 stars 104 forks source link

Why add space between tspans? #63

Closed zhangchen0514 closed 5 years ago

zhangchen0514 commented 5 years ago

Why add space between tspans? It looks different from origin svg.

svg: svg pdf: pdf

test file: test.zip

src: https://github.com/yWorks/svg2pdf.js/blob/dd06aad011a784823ff1465691b2bb261ebeec3c/src/svg2pdf.js#L1428-L1432

yGuy commented 5 years ago

Hmm... your test-case looks convincing. @HackbrettXXX I fail to see that your comment applies, here. Any ideas? It really does seems as if removing that if would fix the issue and in all browsers I tried the above SVG there was no space inserted. Could it be that you had xml-whitespace between the tspans? Do you remember the test-cases that you had when you wrote that comment?

HackbrettXXX commented 5 years ago

The test case I was referring to is text-placement/spec.svg. I think the problem is, that in this test case, the tSpans end with a space character, that will get trimmed in line 1551:

transformedText = transformText(node, removeNewlinesAndTrim(tSpan.textContent));

That probably led me to the conclusion, that a space needs to be inserted between tSpans.

yGuy commented 5 years ago

Oh - so that's actually two bugs!

HackbrettXXX commented 5 years ago

This issue is now fixed. However, if you test your file, you will find that the space between the two tSpans is still slightly too large. The reason is missing kerning between tSpans (usually, the distance between "f" and "e" is smaller than between for example "ss"). Fixing this seems quite difficult, though. I'm gonna open a new issue for this.

HackbrettXXX commented 5 years ago

https://github.com/yWorks/svg2pdf.js/issues/68