Use embeded Font

I am trying to use am embeded font.

I searched in the forum and found this topic by Jules


What I have done:

- Added the TTF file with Introjucer, so its accessed by the BinaryData
- Override the "getTypefaceForFont()" in my custom LookAndFeel like so:

Typeface::Ptr getTypefaceForFont(const Font& font) override
    return Typeface::createSystemTypefaceFor(BinaryData::myFont_ttf, BinaryData::myFont_ttfSize);

so it returns this font eitherway.

I can't see any change in my GUI though.
I know I did something wrong, but don't know what.

Any advice?

Can't think of anything obvious, except maybe you're drawing with a Font object that you already created before you set the new L+F?

What I've done is to set my LookAndFeel in the begining of the MainComponent constructor.
Other than that, I just overriden the getTypefaceForFont(), as mentioned above, and the drawButtonBackground().

If I set the font on every componenten separately, it works fine (the font changes).

Is there another way to se embeded fonts?

It should work perfectly well like that, we use the same technique in various apps.

I'm actually just about to fix a related bug where embedded fonts don't draw correctly if you use an AttributedString but forget to set its font. But as long as you use them properly, it should all work OK.

I am doing this on Windows (if it makes any difference), I'll check this on my Mac too, and see if I have something else wrong.

I'll post if i figure it out.


Hi all,

I have the same problem too.
I have embed a new font named "BroadcastTitling" at the beggining of the constructor of my MainComponent.cpp  but it has no effect at all.
In order to check if the problem comes from fonts, I installed it in my system (windows 10) and it works fine.

Here is a piece of code from MainComponent.cpp :
where Laf_V3 : private variable of type LookAndFeel_V3, in MainComponent.h

MainComponent::MainComponent ()
 //[Constructor_pre] You can add your own custom stuff here..
   Typeface::Ptr FontPtr = Typeface::createSystemTypefaceFor(BinaryData::BroadcastTitling_ttf,   BinaryData::BroadcastTitling_ttfSize);
    String Sf = FontPtr->getName();

  addAndMakeVisible (Lbl_DoTest = new Label ("Lbl_DoTest",
                                               TRANS("Do Test")));
    Lbl_DoTest->setFont (Font (15.00f, Font::plain));
    Lbl_DoTest->setJustificationType (Justification::centredLeft);
    Lbl_DoTest->setEditable (false, false, false);
    Lbl_DoTest->setColour (TextEditor::textColourId, Colours::black);
    Lbl_DoTest->setColour (TextEditor::backgroundColourId, Colour (0x00000000));

 ....more code



Any suggestion please? 




Edit.: Here are the BinaryData and .ttf file itself, if anyone wants to reproduce the problem..

That won't work - you can't just ask for a custom typeface by name, as it won't be found by the OS, which won't know about its existence. You'd need to do like the OP and create a Font object directly from the Typeface object.

I change my code like this :

MainComponent.cpp (constructor) :

where General_Laf : my custom LookAndFeel_V3 in order to override only the getTypefaceForFont(0 function.

    Laf_V3 = new General_Laf();

.. more code for addAndMakeVisible the gui components

Custom LookAndFeel :

    Typeface::Ptr getTypefaceForFont(const Font& font) override
        return Typeface::createSystemTypefaceFor(BinaryData::BroadcastTitling_ttf,



This function is called subsequently, but has no effect.

But, if i change this function as follows :

    Typeface::Ptr getTypefaceForFont(const Font& font) override
        Font CurrentFont("Comic Sans MS", 15.0f, Font::plain);
        return Font::getDefaultTypefaceForFont(CurrentFont);

everything goes ok and all fonts are turned to the specified font family.
I can't realize what's really going wrong.

I appreciate any help


Have you tried with the latest version from today?

Someone else reported an identical problem, which turned out to be due to a completely unrelated mistake involving their use of an AttributedString. I've tightened that class up now so if that sounds like your situation, try again with the newest code..

I just downloaded the latest version, and it works perfectly now.

Thanks a lot Jules.



OK, thanks.

FYI the problem I fixed was nothing to do with embedded fonts, that was just a symptom of a bug you get if you create an AttributedString but don't bother specifying its font.

Even though it seems to work for you now, you probably still should fix your code so that you specify a font for your AttributedString, otherwise they're just using some arbitrary default size, which probably isn't what you want.

Hi Jules,

I tested my app, with various fonts that they not installed in the system (windows 10).
It seems that everything works fine.
I would assume (fully knowing to whom I say this) that somewhere deeply in Juce, the two issues (embedded fonts and Attributedstring) ends up in a same common procedure. 
I attempted twice to follow the sequence of the two procedures through debugger, but I lost the control and I stopped the try. Sorry...
In any case I will observe the behaviour of my app and I will inform you for any change.
I think the OP will take the same care.  

Thanks again