Hi all,
I would like to know if you have a method to return a cut position inside a (long) string given a width in pixel and a font.
I thought about making a simple iterative like :
for (i = 0; i < hugeText; i++)
{
if (font.getStringWidth(hugeText.subtring(0, i)) > availableWidth) return i-1;
}
But I guess it’s clearly inefficient (if the string is huge, it’s O(N) intensive operations).
I don’t understand exactly how the font kerning and letter width work, but would it be possible to extract a letter width in a lookup table, or are they dependent on the previous and the next one ?
Else, I’ve thought about a dichotomic solution, but if the lookup solution works I think it’s easier to implement.
Else, should I add a method in Font for this, so I can copy and adapt getStringWidthFloat() method ?