Hi guys, I would like to throw in my two cents on the topic. This is based off my current experience and hoepefully will be useful for improving font rendering in JUCE. Follows a tldr at the end.
My current standalone app project uses different look and feel implementations. I am using the Open Sans font by Google which has different ascent/descent values for both Win and HHead and as expected the font has different heights between Windows and Mac. Now, problems start when loading from memory fonts with edited ascend/descends:
Edited font at launch. L&f has been set just once within the main method:
However, as soon as I change the active look and feel, the same text renders as such:
Looks like all glyphs have shifted by two positions and kerning seems all over the place.
When opening the same edited font with Font Book it seems to render fine
All I did to the edited font was updating the Ascent and Descent values as pointed out by @anthony-nicholls a few posts ago. I personally used this hack in the past and never had garbled text as a result.
Now you might think that I messed something up while tweaking the font with FontForge so let’s try with a version of the same font (open sans) available on the fontsquirrel website. This version of the font has matching ascent and descent values out of the box so no font forge editing is needed.
How it looks when launching the standalone app for the first time:
After updating the active look and feel:
Glyphs are mostly fine this time, apart from the capital “i” letter becoming the symbol for the Laotian local currency. Also I am not 100% sure this post lookandfeel update text is still in open sans by looking at some of the glyphs (especially the letter “A”). Additionally the new text seems to be taller.
Calling Typeface::clearTypefaceCache() after changing the active look and feel didn’t help.
This issue occurs on both Windows and Mac. Using JUCE 7.0.5.
Look and feel is set first with:
juce::LookAndFeel::setDefaultLookAndFeel ();
And then updated with:
setLookAndFeel ();
getTypefaceForFont() is implemented like so for all look and feel implementations:
Typeface::Ptr CustomLookAndFeel::getTypefaceForFont (const Font& font)
{
auto const bold = Typeface::createSystemTypefaceFor (BinaryData::OpenSansBold_ttf, BinaryData::OpenSansBold_ttfSize);
auto const semiBold = Typeface::createSystemTypefaceFor (BinaryData::OpenSansSemiBold_ttf, BinaryData::OpenSansSemiBold_ttfSize);
auto const regular = Typeface::createSystemTypefaceFor (BinaryData::OpenSansRegular_ttf, BinaryData::OpenSansRegular_ttfSize);
if (font.isBold()) {
return bold;
}
if (font.getTypefaceStyle() == "SemiBold") {
return semiBold;
}
return regular;
}
Note getTypefaceForFont()
gets called only at start even after resetting the typeface cache.
Removing const
from the typefaces doesn’t help.
Tldr; In some cases editing the ascend and descend values of a font would cause garbled text, also, it seems there are some issues with font rendering somewhere within juce after updating the look and feel. This issue seems to be platform independent.