I’m using Graphics::drawFittedText to draw the text of a label that contains newline characters.
The text is submitted correctly to GlyphArrangement::addFittedText but in the output that is drawn there are some characters missing after each newline character.
When the the following text is submitted to GlyphArrangement::addFittedText:
chicken\nchicken\nchicken\nchicken\nchicken
then the result that is drawn is:
chicken
hicken
icken
cken
ken
Obviously I’m expecting the output:
chicken
chicken
chicken
chicken
chicken
I’ve tried to use different ways to get a correct newline:
\n
\r\n
newline
But the result is always the same. For each newline in the string one additional character at the beginning of the next line is truncated.
Any idea what could be wrong?
I found out that it only happens when I’m using custom serialized fonts. So it deosn’t seem to be related to the GlyphArrangement.
I’ll post my results when I’ve found the exact reason for the problem.
Thanks.
Is it possible that the CustomTypeface::getGlyphPositions doesn’t handle special characters correctly?
When I pass the String:
chicken\nchicken\nchicken
to the CustomTypeface::getGlyphPositions it tries to find a fallbackTypeface for the \n and nothing is added to the resultGlyphs and xOffsets.
So there are the following characters added to the resultGlyphs:
chickenchickenchicken
which is a total of 21 characters which do not include any whitespace anymore.
However when these 21 characters are passed to the GlyphArrangement::addCurtailedLineOfText then the loop iterates over the original characters String::CharPointerType t (text.getCharPointer()); which are still 23 with two whitespaces included.
As the loop iterates over the original text with size 23 but only up to textLen which now is 21 with whitespaces removed, the String::CharPointerType t (text.getCharPointer()); test returns wrong whitespaces and the loop stops too early.
I think the GlyphArrangement::addCurtailedLineOfText is working correctly but the CustomTypeface::getGlyphPositions needs to handle special characters (whitespaces) to resolve this issue.