Closed Mrfence97 closed 3 years ago
Tests were expected to fail, I haven't pushed updated reference PDFs in case you wanted to review yourself. All are due to a better text trimming/space consolidation implementation:
text-anchor="middle", two tspans
is perfectly aligned with the blue line, but in browser renderings (and svg2pdf after this PR), the d is offset:
Addresses issue #123.
Implementation is how you'd expect: using a recursive function to process each
<tspan>
in turn, the base case being when a child is simply a plain#text
element. The context of the parent element is passed down to each child.Note browsers seem to treat text chunks in a linear manner. That is to say that setting the
x
/y
attribute of a nested<tspan>
will impact any subsequent<tspan>
s, regardless of whether they're a child, sibling or at a higher level. This effectively means that the collection ofTextChunk
s can be stored as a 1D array, rather than a tree. See the third and fourth tests in the new spec SVG.Things are complicated by the correct trimming of text when
xml:space = "default"
. In particular, spaces need to be consolidated across elements in eachTextChunk
and betweenTextChunk
s. Browsers also treatxml:space
differently:xml:space
can be freely changed and all child elements inheritxml:space
once set topreserve
cannot be set back todefault
in any child elementThis PR uses the Chrome convention.