You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With freetype-go, is there a way to compute the text extents (width and height)
of a string given a particular font and size *before* rendering the text?
I've looked around in the source code, and it *appears* that the right
information is there, but I can't quite seem to figure out how to do it.
As of right now, if I want an image that "snugly" fits some string, I do the
following:
Over estimate the extents by multiplying the pixel size of one em unit by the
length of the string. I get the width/height this way (assuming one line of
text).
I allocate an image with a rectangle of two points: (0, 0) and (width, height).
After rendering the text to the image using DrawText, I use the point returned
from DrawText to take a sub-image of the initial image. (I convert this point
to a (x, y) position by simply dividing the X and Y of the point by 256. It
seems to work OK, but I have no idea if this is correct.)
--------------
And one last question: would the extents include the entire bounding box of the
string? The (x,y) position returned by DrawText doesn't seem to cover the parts
of the text the dip below the text's base line. Like the tail in the 'y'. My
solution has just been to pad the 'y' with a few pixels, but I know this is not
optimal since it will break if the font size changes too much.
(My apologies if my terminology is off. I don't have much experience in font
rendering.)
I would happily submit a patch if I was nudged in the right direction :-)
Thanks!
Original issue reported on code.google.com by [email protected] on 2 Jun 2012 at 10:44
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
[email protected]
on 2 Jun 2012 at 10:44The text was updated successfully, but these errors were encountered: