On what basis is a typeface style chosen?

I’m loading NotoSansCJK.ttc, which contains 7 weights ranging from Extra Light to Black, using juce::Typeface::createSystemTypefaceFor(const void *fontFileData, size_t fontFileDataSize).

I’d expect the Typeface to work together with JUCE’s Font system, but am running into the following questions/issues:

  • When I call getStyle() on the Typeface “Thin” is returned. On what basis is this chosen as the default?
  • When I create a juce::Font with this Typeface and set the style to FontStyleFlags::bold, I don’t see my text drawn as bold. What do the flags actually influence? I can see the style changed to “Bold”.

I always override getTypefaceForFont in the look and feel class. You can do whatever magic you like then by inspecting a Font() object and returning a typeface.

1 Like

Hey, didn’t know you could do that. Thanks, that should be a good workaround!

Just today, I was working on the same thing. In constructor of your LookAndFeel class (e.g. inheriting LookAndFeelV4) you can also call

setDefaultSansSerifTypefaceName("YourTypefaceName");

In my case, changes were not applied everywhere, so I made few overrides like:

Font getLabelFont(Label& label) override

Sorry to wake up this old thread, but how exactly do you use this? How do you get the override of getTypefaceForFont() to be called? I added it, but it never hits, do I have to call it myself? Thanks.

I see: getTypefaceForFont() is never called unless you have called:

LookAndFeel::setDefaultLookAndFeel()

But if you do this, correct me if I am wrong, it would be impossible to have different fonts in multiple instances of your plugin? This setting is shared between instances, correct?

Let’s say the user has a choice of visual schemes for the plugin, and said schemes may include a different font, and you could have multiple instances of the plugins and set one to the green theme, one to the red theme in order to differentiate which is which…

Register all the fonts in the default look and feel. Use their normal names as well, we got in trouble once using different names/style names from the underlying font.

Then there are many schemes you could use to choose the font the user has selected for that particular instance. I’d pass a shared object around from my PluginEditor to everywhere and have a method Font getUserFont() { ... } in it and do g.setFont(config.getUserFont()) a lot.