meerk40t / svgelements

SVG Parsing for Elements, Paths, and other SVG Objects.
MIT License
133 stars 29 forks source link

is it possible to get the width and height of Text elements? #90

Closed soundquiet closed 3 years ago

soundquiet commented 3 years ago

Hi, is it possible to get the width and height of Text elements?

tatarize commented 3 years ago

No. Not without a way of determining how large they are. Which means being able to access the font and glyph data. That requires an engine of some kind to figure out the size. At most you can figure out how large they are, but without a font library to check you can't really gauge their size. It takes some stuff outside the scope of the project.

tatarize commented 3 years ago

Which isn't to say it's impossible, it just requires other software to work. MeerK40t which uses svgelements to items does solve this by using wxPython's code for measuring font size, etc. But, it requires something like that.

If you wanted something quick and dirty you could send the text svg to inkscape through the CLI get the text run through a text to path routine, and then load that in svgelements. Paths can be solved for their bounds rather easily with bbox()

text-height-width

soundquiet commented 3 years ago

I see. Thank you!