Open cornwe19 opened 2 years ago
Units are rarely used in svg. whats your usecase?
I'm importing and manipulating preexisting SVGs that happen to use units for their font-sizes.
A small step in the right direction might be to at least warn or document somewhere that measurements with units aren't supported or something. It took me a while to figure out why my text fields just weren't measuring at all.
Or we could just skip the unit alltogether. Feel free to implement a PR. You should find the corresponding code somewhere in https://github.com/svgdotjs/svgdom/blob/master/src/utils/textUtils.js
I think ignoring the unit would work for the case of px
, but other units mean different things than the scalar values represent. I'll see if I can get a coherent PR together on this. Thanks for pointing me in the right direction in the codebase.
This library has no notion of real-world measurements. How much is a cm in px if you don't have a screen? There is no way to know. The only other unit that would make sense is percentage but in the end, this is a custom library that supports as much as it can. What works works and when somebody needs more, they can create a PR :)
It seems that when
<text>
or<tspan>
elements have a font-size which includes a unit, this library renders their.bbox()
as an empty rect (all 0's). The following example illustrates my point.Which outputs the following when run in node: