memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.06k stars 767 forks source link

Vertical centering of text based on the ascender only #574

Closed ghost closed 8 months ago

ghost commented 4 years ago

I needed an option to center text vertically based on the cap height only. When choosing NVG_ALIGN_MIDDLE, the ascender and the descender are taken into account, so a string containing upper-case characters only, e.g., TEXT, is not centered vertically, but shifted upwards.

Therefore I added a new option NVG_ALIGN_MIDDLE_ASCENT, which is based in the height of the ascender only.

I think that cap height would be an even better option, but the fontstash library does not provide access to this measure.

rgb2hsv commented 1 year ago

I found a valuable use for this same feature. Thanks for PRing it!