I noticed that when a custom font is installed in windows os, the call to Graphics::drawText is not using the font set with setFont but overrides it with the installed custom font from windows.
Steps to reproduce:
1/ Search on google the font “Google Font: EB Garamond”
2/ Download and Install them
3/ Graphics::drawText does not work properly anymore
Workaround (sort of) :
The workaround for this is to replace the g.drawText() by a custom method creating a textLayout, I place it is my main lookAndFeel:
static void drawText(juce::Graphics& g,
const juce::String& text,
juce::Rectangle<float> bounds,
juce::Justification just,
juce::Colour c,
float multiplicatorWindows = 1.2f
{
juce::Font font = g.getCurrentFont();
#if BOOST_OS_WINDOWS
bounds.translate(0, (-1.2f));
font.setHeight(g.getCurrentFont().getHeight() * (multiplicatorWindows));
#endif
juce::AttributedString str(text);
str.setJustification(just);
str.setFont(font);
str.setColour(c);
str.setWordWrap(juce::AttributedString::none);
juce::TextLayout textLayout;
textLayout.createLayout(str, bounds.getWidth(), bounds.getHeight());
textLayout.draw(g, bounds);
}
it would be great if g.drawText were behaving the way it should because it is not reliable when building cross-platform apps that require to look exactly the same.
Using “textLayout” brings its own issues mostly regarding placements and it not really a wanted long-term workaround, I had to place size multiplicators and some translates on windows to obtain satisfying results.
Hope this helps to find a fix.
EDIT: This does not work 100% of the time but greatly reduces the number of machine with a font issue