GlyphArrangement::addFittedText - newline problem


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:
then the result that is drawn is:

Obviously I’m expecting the output:

I’ve tried to use different ways to get a correct 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?


Bizarre! Can you give me a code snippet to try, e.g. that I could paste into the juce demo?


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.


Is it possible that the CustomTypeface::getGlyphPositions doesn’t handle special characters correctly?
When I pass the String:
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:
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.


Hmm. How about this:

[code]void CustomTypeface::getGlyphPositions (const String& text, Array & resultGlyphs, Array& xOffsets)
xOffsets.add (0);
float x = 0;

for (String::CharPointerType t (text.getCharPointer()); ! t.isEmpty();)
    float width = 0.0f;
    int glyphChar = 0;

    const juce_wchar c = t.getAndAdvance();

    if (const GlyphInfo* const glyph = findGlyph (c, true))
        width = glyph->getHorizontalSpacing (*t);
        glyphChar = (int) glyph->character;
        const Typeface::Ptr fallbackTypeface (Typeface::getFallbackTypeface());

        if (fallbackTypeface != nullptr && fallbackTypeface != this)
            Array <int> subGlyphs;
            Array <float> subOffsets;
            fallbackTypeface->getGlyphPositions (String::charToString (c), subGlyphs, subOffsets);

            if (subGlyphs.size() > 0)
                glyphChar = subGlyphs.getFirst();
                width = subOffsets[1];

    x += width;
    resultGlyphs.add (glyphChar);
    xOffsets.add (x);



Works as expected.
Thanks a lot.