shrhdk / text-to-svg

Convert text to SVG path without native dependence.
Other
964 stars 131 forks source link

Calculating exact height of the text #52

Closed HenrikFricke closed 4 years ago

HenrikFricke commented 4 years ago

Right now, the getMetrics method returns the proportions of the path, but it calculates the height of the text including the special characters even if those characters are not used.

Screenshot 2019-08-20 at 11 20 52

Screenshot 2019-08-20 at 11 21 16

Sometimes this could cause problems when centring the text vertically, so we would like to extend the getMetrics method to also give back the exact height of the given text.

As a result the response of the method could look like this for the given example:

{
    "x":0,
    "y":0,
    "baseline":28.632,
    "width":71.952,
    "height":35.568,
    "ascender":28.632,
    "descender":-6.936,
    "exactHeight": 24
}

What do you think about it? Shall we prepare a pull request?

shrhdk commented 4 years ago

@HenrikFricke Good idea!

Shall we prepare a pull request?

Yes, please.

HenrikFricke commented 4 years ago

@shrhdk Hey, thanks for your response. We tried to prepare a pull request but then we figured out that our use case is very special and at some point, we realized we would need to change a lot in the library to adjust it to our fits. I'll close this issue now, but again thanks for your answer!