I am seeing an issue with a memory-based font I’m using in that it renders correctly on Mac but not Windows for identical code. I’ve made a simple app to show the issue, the only lines I’ve added on top of the basic GUI app template are in paint():
void MainContentComponent::paint (Graphics& g)
{
g.fillAll (Colour (0xff001F36));
auto myFont = Font (Typeface::createSystemTypefaceFor (BinaryData::News_Gothic_Extra_Condensed_Bold_otf,
BinaryData::News_Gothic_Extra_Condensed_Bold_otfSize));
myFont.setHeight (25);
g.setFont (myFont);
g.setColour (Colours::white);
g.drawSingleLineText ("News Gothic Extra Condensed Bold", 20, 30);
}
This gives the following results:
Mac – font displaying correctly
Windows – font not displaying correctly
This is using a .otf file for the font, if I convert to a .ttf the issue goes away and both platforms display the font correctly.
This rings a bell - IIRC there was just some mysterious problem that stopped Windows from loading OTFs correctly when they’re done as in-memory fonts. Not sure whether a fix is even possible for it, I think just sticking to TTFs might be the answer
something similar also happens with TTF, afaik. I’ve never been able to match how the fonts are rendered (using the same cross platform font file) between Mac and PC.
I found a fix for my use case. I don’t know if this is useful, anyway here it goes:
In my case the problem was happening for some fonts that have particular styles (e.g. Bold, Italic).
This is what I was doing, in pseudo code:
auto myFont(Typeface::createSystemTypefaceFor(ItalicFontName, ItalicFontSize));
font.setStyleFlags(Font::italic);
Calling setStyleFlags destroyed the contained typeface.
And this seems to be the culprit.
Taking a look into the setStyleFlags implementation I see
font->typeface = nullptr;
I don’t know why this is happening on Windows only.
Maybe @ed95 could take a look at this?
You can try with the DSEG14Classic-Italic.ttf font contained in the package available at https://www.keshikan.net/fonts-e.html