FreeType probably gives us this information about each glyph, but it (obviously) has not been exposed to allow the use of getCharBoundaries, the TextField class has some missing pieces that would be great to have implemented.
Hi All.
About this issue, I have the solution. I used textfield.getLineMetrics. But this is only a temporary solution and it just right in some cases.
I will wait for the next version.
I use getLineMetrics to calculate y and height. And textWidth can give me x and width. So I have x, y, width, height to create bound of char. But this solution is slow and it is not totally right.
Anyone found a solution to get REAL char boundaries since?
Because calling Textfield.getLineMetrics(0).ascent or Textfield.getLineMetrics(0).height on a textfield with the text “e” will return exactly the same value as when called on the same textfield but with the text “t”. Wich means that the height returned is actually not dependent on the character but only on the font size and type (wich is the reason why all bound boxes have the same top and bottom in long2805l2 screenshot whereas we would like to have something like in his first post where “A” and “c” characters bound boxes have different height).
And textfield.getCharBoundaries().height seems to suffer from the same artefact has it actually return the font size and thus do not depend on the character at the index called in the function…
Hmm, I’m not sure if we can get any additional details from Freetype, although you could render the text (say, as black) to a BitmapData (using draw) and then (maybe) use getColorBoundsRect to see where the pixels drew?
I recently retried to get char real boundaries.
I thought I could have it with something like:
font.getGlyphMetrics(font.getGlyph("e")).height
to get the height of the “e” char for example (then need to be converted to a real height by taking into account font size)
But sadly this return 0…
So I might be not passing the correct argument to getGlyph() or I don’t understand what height is for glyphmetrics…
Drawing the char to a Bitmapdata and extracting colored pixels boundaries seems the only solution for now. Sadly (it consume a lot of CPU usage for just getting a char height).
Well it’s called GlyphMetrics so it is supposed to be the Glyph specific metrics.
the font general height is supposed to be returned by font.height
Anyway, there is probably a bug as, as said font.getGlyphMetrics(font.getGlyph("e")).height
return a height of 0 (so even if this is the line height, it shouldn’t be 0…)