Embedding TTF fonts on Windows have no Style information?

I’m trying to embed some TTF fonts, two of them specifically.

The Font Family is “ArlonSK” - One is a “Regular” style, and one is a “Medium” Style.

But after I call createSystemTypefaceFor(), they have no style information.

            auto typeface = juce::Typeface::createSystemTypefaceFor(BinaryData::ArlonSKRegular_ttf, BinaryData::ArlonSKRegular_ttfSize);
            DBG("name " + typeface->getName());
            DBG("style" + typeface->getStyle());

The DBG shows:

name ArlonSK Regular
style

Here is what the TTF names section looks like in FontForge:

I’d like to have these two fonts able to be used like one font with a “Regular” typeface and a “Medium” typeface, but I am unable to figure out how to make this happen.

Seeing that a font familiy involves having a style of the font in a separate file, you’ll have to manually load and use all of these font instances.

This means that you have to manually determine, usually in your LookAndFeel derivative, which font you want to apply. (I recommend this approach because manually setting the Typeface::Ptr for each Component that you want to use a font style over another, you’ll typically end up with a lot of repeated code and a spaghetti on your hands.)

If you want to accelerate this process a little bit, you can copy/paste this into your project to help; it’s from my modules. In that file you’ll find the classes FontWeight and FontFamily: squarepine_core/Fonts.h at main · SquarePine/squarepine_core · GitHub .

What I then do in my projects with that is create a class that loads up all of the FontFamily instances under a single class (so as to use it as a SharedResourcePointer):

class SharedFonts final
{
public:
    /** Load the typeface instances here. For an example, I've set this up with Roboto (which is added as BinaryData). */
    SharedFonts()
    {
        roboto.regular.normal = Typeface::createSystemTypefaceFor (RobotoRegular_ttf,             RobotoRegular_ttfSize);
        roboto.assignAllToNormal (roboto.regular.normal);
    }

    FontFamily roboto { "Roboto" };

private:
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SharedFonts)
};

From there, use a SharedResourcePointer instance to access the fonts within your overridden getTypefaceForFont in your LookAndFeel (eg: SharedResourcePointer<SharedFonts> sharedFonts;). Yes, it’s a lot of scaffolding!

Thanks for this information, However, one problem: as far as I can determine:

getTypefaceForFont will not be called unless you have used LookAndFeel:setDefaultLookAndFeel, and I cannot do this because my plugin allows a choice of different “skins”, and you can have multiple instances loaded with different skins to tell them apart. Using LookAndFeel:setDefaultLookAndFeel makes it impossible because the default LookAndFeel is shared between all instances of the plugin.

Interesting caveat! Unless I’m misunderstanding, I think I see what you mean with this bit of JUCE code: JUCE/juce_LookAndFeel.cpp at develop · juce-framework/JUCE · GitHub .

Not that this helps your situation – this sounds like something that should be fixed from the JUCE side: with the flexibility of being able to swap look and feels on the fly, it seems unreasonable to allow font overriding to work exactly as expected via getTypefaceForFont. Otherwise, you’re completely stuck manually updating all of your Components…

Yes, that bit of code is exactly the issue. The Font class stores an external pointer to this function. I tried messing around with it for awhile but was unable to switch it to something that would call getTypefaceForFont in the current LookAndFeel.

I have the manual updating of components with the embedded font variations working, but I had very much hoped there would be a simpler solution…