Here’s a fun one! In JUCE 8 I am experiencing what looks like a bug to do with font ligatures (e.g., a combined ‘ff’ into a single shape in some fonts). I’ve narrowed it down to this example using Proxima Nova:
#include <JuceHeader.h>
class MainComponent : public Component
{
public:
MainComponent()
{
auto fonts = Font::findAllTypefaceNames();
if (! fonts.contains ("Proxima Nova"))
throw std::runtime_error (
"\nPlease install the 'Proxima Nova Regular.otf' font to reproduce this example. See: \n"
"https://github.com/roshinthomas/Proximanova-fonts/blob/master/Proxima%20Nova%20Regular.otf");
Font font ("Proxima Nova", 18.0f, Font::plain);
string.append ("Hello, World!\n", font.withHeight (36.0f).withStyle (Font::bold), Colours::black);
string.append ("Different, World!\n", font, Colours::red);
string.append ("Why is 'W' in 'Why' red?\n", [font] () mutable{ font.setTypefaceName ("Arial"); return font; }(), Colours::blue);
string.append ("Is it the 'ff' ligature throwing off the counting?\n", font, Colours::red);
setSize (320, 240);
}
~MainComponent() override = default;
void paint (Graphics& g) override
{
g.fillAll (Colours::lightgrey);
string.draw (g, getLocalBounds().reduced (20).toFloat());
}
private:
AttributedString string;
};
(I’m deliberately using the deprecated Font constructor so I can show this doesn’t happen in JUCE 7, using the FontOptions constructors yields the same results in JUCE 8.)
As the text suggest, the ‘W’ in the first ‘Why’ on line 3 is carried on in red from the previous line (and ‘I’ on the last line continues in blue):
Yes, these changes should also fix the problem described in this thread. Although you might want to wait for a C++20 fix that’s arriving soon. I’ll update this thread when it’s out.