TTF font changes a lot on windows, what can I do?

Hello forum,

In my plugin I’m using a custom font and I’m loading it using binarydata, however, I noticed that the font doesn’t work on windows (only in Mac), what strategy do you recommend me to solve this?

RenderingComparation

I’m loading it this way:

static auto typeface = juce::Typeface::createSystemTypefaceFor(BinaryData::customFont,
                                                                       BinaryData::customFontSize);

g.setFont(juce::Font(typeface).withHeight(16));

Any help will be appreciated, thanks in advance!

It looks like it’s falling back to its default font. Which font are you trying to load?

1 Like

You can try loading as an OTF instead, conversion can be done using online converters such as this.

1 Like

I like simple solutions, but I’m not sure if it is safe to define static variables and load the typeface directly into it without any locking.

JUCE has a font cache itself. I would create your own look and feel class and overwrite the part where JUCE gets the font as follows:

class TalLookAndFeel : public LookAndFeel_V3
{
public:

Typeface::Ptr getTypefaceForFont(Font const& font) override
  {
    Typeface::Ptr tf;

    juce::String faceName (font.getTypefaceName());

    if (faceName == "MyFontName")
    {
        return Typeface::createSystemTypefaceFor(BinaryData::ARIALN_TTF, BinaryData::ARIALN_TTFSize);
    }
    ....
1 Like

OTF has worked, thanks!

1 Like