setDefaultSansSerifTypefaceName not working on all widgets


I just tested setDefaultSansSerifTypefaceName, in order to globally change the font of my application.

I thought it would affect all components and make them use the new font. But that does not seem to be the case. It works on some components. But there are exceptions, which still use their own font. Exmple of components, which it does not work on:

- the Tooltip Window

- AlertWindows


Juce 3.2 on a stand-alone application under Windows 7.


Maybe you created those components before setting the default font, and they already had their own Font objects internally that they carry on using?


No should be in the right order. I am setting up the LookAndFell first(at the start of my application), then I instantiate the Tooltip. Same for the AlertWindows, which I create on the fly, whenever needed (using AlertWindow::showMessageBoxAsync ).

PS: Maybe I can try to reproduce it in on a small demo project. If I find time.


Yes, trying to reproduce it would be a good way to either fix it, or show us where the problems is.


I did some debugging: The LookAndFeel of both the TabBarButton and the Tooltip use a TextLayout::draw and AttributedString in order to draw its text. Whereas other components, such as labels use Graphics::drawFittedText. It seems, AttributedString (or maybe TextLayout) is using different font setting methods than Graphics. And therfore it seems, it does not react to LookAndFeel::setDefaultSansSerifTypefaceName. That in turn results in TabBarButton and Tooltip getting the wrong font. 

Here is some code I used to test that. First I instantiate my main Component and set the LookAndFeel:

class FontTestApplication  : public JUCEApplication
    void initialise (const String& commandLine) override
        mainWindow = new MainWindow (getApplicationName());

... more code here ...


In the MainWindow's paint routine I create two different text strings. One using Graphics::drawFittedText and another one using TextLayout::draw. Both functions get to use the same font:

void MainContentComponent::paint (Graphics& g)
    g.fillAll (Colour (0xff001F36));

    Font font(15); //same font for both string-drawing methods

    g.drawFittedText("This is a test string.", juce::Rectangle<int>(10, 100, 200, 25), Justification::centred, 1);

    AttributedString s;
    s.append("This is a test string.");

    TextLayout textLayout;
    textLayout.createLayout(s, 200);
    textLayout.draw(g, juce::Rectangle<float>(10, 140, 200, 25));

But: only the "drawFittedText" string is correctly drawn in "Wingdings". The other string is drawn in normal text. I think, this must be a bug? I mean: two methods, which use the same font should also display the same font, I would assume. Both should display the Wingdings symbols. Or is there something wrong with my code?

I have attached a screenshot of the result. And I have attached the source files used in my test application.

My Environment: JUCE 4 on Win 7 under VS2015.





Bumping this in hope that someone can take a look :-)



If you set the typeface to "Times" then it works. But Webdings doesn't.

As far as I can tell, CoreText is actually replacing Webdings with a default font for some strange reason. The correct font definitely goes in, but when it has finished the layout, the one it returns is different! Since CoreText is a bit of a black box, I'm not sure what I could do about that, and really can't think why it'd replace that font, but not others..


Thanks for looking into this. Unfortunately it is also happening to more normal fonts, such as Courier New (and I think even Arial, even though it is harder to be sure, because Times and Arial do not look that different).

At the moment my workaround is to set the font manually. I.e. in the problematic components I explicitly set the font by name (and don't rely on setDefaultSansSerifTypefaceName).

That works fine for me.