Is it possible to more accurately measure SVG text height?

后端 未结 1 1648
迷失自我
迷失自我 2021-01-12 09:11

I\'m trying to measure the exact height used to render a given string with a given font with an SVG text tag.

I\'ve tried using getBBox and getExtentOfChar, but the

相关标签:
1条回答
  • 2021-01-12 09:19

    No. All the SVG DOM methods (getBBox(), getExtentOfChar()) are defined to return the full glyph cell height. That extra space above the cap height is allowance for taller glyphs - such as accented capitals. I think this is true for HTML DOM methods as well.

    There are, however, JS libraries around which may be of use. For example:

    https://github.com/Pomax/fontmetrics.js

    I have not used this library myself, so I can't tell you how reliable or accurate it is.

    0 讨论(0)
提交回复
热议问题