Consider the following AttributedString “stringToDraw”:
stringToDraw.setWordWrap(juce::AttributedString::WordWrap::byChar);
stringToDraw.setJustification(juce::Justification::centredLeft);
stringToDraw.append(“555t burgletonMsMMfarm2brrrrrrrF”, juce::Font(“IBM-PlexSans”, 20.8f, juce::Font::FontStyleFlags::plain));
This string can, if truly broken by char, fit within a 194x44 bounding box. I have illustrated it in the attached screenshot (left = actual result of using byChar wrap, right = manually breaking at the correct character).
As you can see, it seems like the string is breaking byWord, and then byChar. I understand that byWord breaking is the preferred means of breaking, but is this not a bug, if the “preferred” method would result in going out of bounds, while the specified method would not?
Not sure the best way to provide example, but this is the steps to repro:
Mac OSX 15.6
Projucer Juce 8.0.11 → Create GUI project
In MainComponent.cpp, add the replace the contents of the paint function with the following code:
juce::AttributedString stringToDraw;
juce::AttributedString stringToDrawCorrectly;
stringToDraw.setWordWrap(juce::AttributedString::WordWrap::byChar);
stringToDraw.setJustification(juce::Justification::centredLeft);
stringToDraw.append("555t burgletonMsMMfarm2brrrrrrrF", juce::Font("IBM-PlexSans", 20.8f, juce::Font::FontStyleFlags::plain));
stringToDrawCorrectly.setWordWrap(juce::AttributedString::WordWrap::byChar);
stringToDrawCorrectly.setJustification(juce::Justification::centredLeft);
stringToDrawCorrectly.append("555t burgletonMsM\nMfarm2brrrrrrrF", juce::Font("IBM-PlexSans", 20.8f, juce::Font::FontStyleFlags::plain));
g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));
g.setColour(juce::Colours::red);
g.drawRect(16,16,194,44);
g.setColour (juce::Colours::white);
stringToDraw.draw(g, {16,16,194,44});
g.setColour(juce::Colours::red);
g.drawRect(194+16+16,16,194,44);
g.setColour (juce::Colours::white);
stringToDrawCorrectly.draw(g, {194+16+16,16,194,44});

