Fonts not working when loaded from BinaryData

#1

I’ve added an OTF file to the projucer which has been automatically added to the BinaryData namespace.

I’m now trying to use that font like so:

Font font(Typeface::createSystemTypefaceFor(BinaryData::MontserratRegular_otf,
                                            BinaryData::MontserratRegular_otfSize));

g.setFont(font.withHeight(25.f));
g.setColour(Colours::white);
g.drawText("12345", getLocalBounds(), Justification::centred, true);

However the font is displayed wrong, as shown below:
image

The font should look like this (using paint.NET):
image

I’ve also installed the font to my OS and it does work if I instead use

Font font("Montserrat", 25.f, Font::plain);

But I can’t rely on my users having the font installed!

Have I done something wrong or is there something odd going on?

0 Likes

#2

This also happens with the other font I use - Open Sans (also in OTF format).

I decided to try instead the TTF formats of both fonts and it turns out the TTF versions do indeed work.

This fixes my issue - I can just swap to TTF - but maybe there’s still an issue with OTF fonts?

I tried with a few other random OTF fonts and they all seemed to work fine - I also re-downloaded the latest versions of the OTF formats for Montserrat and Open Sans but still neither of them work!

0 Likes