drawFittedText() not constrained to bounds?

I’m painting a multiline string with g.drawFittedText(message, b, Justification::topLeft, 1); and getting the following result :


The red background is being filled with g.fillRect(b).

I would have expected that I would only see 1 line given the 4th parameter to drawFittedText (I set that like that as a test), and also that the text would be constrained to the bounds.

Using JUCE 5.4.1 on master. I also tried without setting a custom font in case something screwy was happening there.

Is this a bug or have I made a dumb mistake/faulty assumption?

To confirm it’s not me doing something dumb, I started a new AudioApplication from the Projucer and simply added this to the paint method :

    auto b = Rectangle<int>(50, 50, 200, 100);
    String message = "This is a message.\nIt can be extremely long if required.\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
    g.drawFittedText(message, b, Justification::topLeft, 1);

which gives me this result :

Of course I still may have done something dumb, but I hope not :wink:

Those functions don’t actually clip anything, the rectangle just tells it where you want the text. If you want it to be clipped to that rect, just call g.reduceClipRegion before you draw.

1 Like

Super, thanks. Faulty assumption it was then. :slight_smile:
Although the documentation does state this :

If the text just won’t fit into the space, it’ll cram as much as possible in there, and put some ellipsis at the end to show that it’s been truncated.

which is why I thought something was broken.

edit : it seems having \n in the text changes the behaviour.

Hmm, that is a bit misleading. I think maybe it can only do the ellipsis if you give it a single line to lay out.

Yes, appears so. As noted in the edit to previous reply.