Mac: TextLayout.createLayout silently failing when text height > maxHeight

Hi all, after spending a few hours investigating why a certain text wouldn’t appear, we realised the problem was that we were (erroneously) setting the font height to be greater than maxHeight - something like this:

    juce::AttributedString stringToDisplay;
    stringToDisplay.setText ("Hello World");
    stringToDisplay.setFont (31);

    juce::TextLayout l;
    l.createLayout (stringToDisplay, float (999999.f), float (30)); // <- maxHeight is 30 but font height is 31!

    l.draw (g, getLocalBounds().toFloat());

So instead of getting clipped text, an assertion or some other indication that something was wrong, all we got here was a “blank” `result. This happened only on Mac, while it seemed fine on Windows.

May I suggest adding an assert or some form of check in createLayout for cases such as this one so that similar problems are easier to spot in future?

One additional bit of information: if we comment the call to createNativeLayout then it works (i.e. we still see some text on the screen):

void TextLayout::createLayout (const AttributedString& text, float maxWidth, float maxHeight)
{
    lines.clear();
    width = maxWidth;
    height = maxHeight;
    justification = text.getJustification();

    //if (! createNativeLayout (text))
        createStandardLayout (text);

    recalculateSize();
}
2 Likes