Can't change defaultSansSerifTypeFacename once set

15 posts / 0 new
Last post
gekkie100
Offline
Last seen: 1 week 3 days ago
Joined: 12 Apr 2005 - 14:35
Can't change defaultSansSerifTypeFacename once set

I can't seem to change the default SanSerifTypeFaceName once set.
I want to change the font in our app when the user has chosen a different language, we set it to use "Arial Unicode MS" if the language is Japanese.
But we need to call setDefaultSansSerifTypefaceName before any component (font object) is created otherwise you can't change it, it will stick to 'Lucida Grande' (mac).
And because we show a splash-screen while loading settings we are already too late.

To reproduce:
In the Juce Demo (latest tip)

     ContentComp (MainDemoWindow& mainWindow_)
        : mainWindow (mainWindow_),
          currentDemoId (0)
    {
		//if you set the defaultsans here it works fine 
		//LookAndFeel::getDefaultLookAndFeel().setDefaultSansSerifTypefaceName("Courier New");
        setOpaque (true);
        invokeDirectly (showRendering, true);
	}

    ~ContentComp()
    {
       #if JUCE_OPENGL
        openGLContext.detach();
       #endif
    }

    void paint (Graphics& g)
    {
        g.fillAll (Colours::white);
    }

    //==============================================================================
    void showDemo (Component* demoComp)
    {
		//but if you set the defaultsans here it sticks to whatever it was set to as the default in LookAndFeel class
		//this is platform independent,on the mac that would be 'Lucida Grande'
		LookAndFeel::getDefaultLookAndFeel().setDefaultSansSerifTypefaceName("Courier New");

        currentDemo = demoComp;
        addAndMakeVisible (currentDemo);

		currentDemo->setBounds ("0, 0, parent.width, parent.height");
    }

Tip for anyone needing a workaround for the missing font fallback mechanism.
In our language files we specify a font to use.
This is how our language translation file looks like.
We call TRANS("FontToRenderThisLanguageIn") to find out if we need to use another font.

language: Japanese
version: Avenue 4 GUI
"FontToRenderThisLanguageIn" = "Arial Unicode MS"

"Hello" = "こんにちは"
"Composition" = "コンポジション"
"Composition Properties" = "コンポジションプロパティ"
"Composition Settings" = "コンポジション設定"
"Composition Effects" = "コンポジションエフェクト"
"Composition Audio" = "コンポジションオーディオ"
"Composition Video" = "コンポジションビデオ"
.....

jules
Online
Last seen: 5 min 5 sec ago
Joined: 29 Apr 2013 - 18:37
Re: Can't change defaultSansSerifTypeFacename once set

Looks like it had already cached the typeface.. I've checked in something that will hopefully fix it - try it again now.

gekkie100
Offline
Last seen: 1 week 3 days ago
Joined: 12 Apr 2005 - 14:35
Re: Can't change defaultSansSerifTypeFacename once set

Thanx for looking at it Jules.
It partly works, some components works well others don't. Maybe because they have different styles?
Screenshot below:

jules
Online
Last seen: 5 min 5 sec ago
Joined: 29 Apr 2013 - 18:37
Re: Can't change defaultSansSerifTypeFacename once set

Could be because those components are storing a Font object internally, and continuing to use that after you change the default typeface..?

gekkie100
Offline
Last seen: 1 week 3 days ago
Joined: 12 Apr 2005 - 14:35
Re: Can't change defaultSansSerifTypeFacename once set

But i call this method before the components in question are created.
I moved the line from ShowDemo to perform (const InvocationInfo& info) int the Juce Demo. So it's called before the demo component is created.
Same happens in my own app. i set the font before the mainwindow is created only some components are showing the correct font.

gekkie100
Offline
Last seen: 1 week 3 days ago
Joined: 12 Apr 2005 - 14:35
Re: Can't change defaultSansSerifTypeFacename once set

Jules, have you got a clue on what else might be causing this issue. Anything else i could try to help you fix this issue?

jules
Online
Last seen: 5 min 5 sec ago
Joined: 29 Apr 2013 - 18:37
Re: Can't change defaultSansSerifTypeFacename once set

Interesting. I think it might be the style that's messing it up. Try again now..

gekkie100
Offline
Last seen: 1 week 3 days ago
Joined: 12 Apr 2005 - 14:35
Re: Can't change defaultSansSerifTypeFacename once set

The Juce Demo seems to work fine, now merging your change to our own juce branch, manual labour so it takes a while.

gekkie100
Offline
Last seen: 1 week 3 days ago
Joined: 12 Apr 2005 - 14:35
Re: Can't change defaultSansSerifTypeFacename once set

Ahh no, the Juce Demo still shows some text in the wrong font.
- The Drag And Drop demo show the fonts incorrrect
- The enable/disable components toggle button on the Widgets page is still incorrect
- Nodes in TreeViews demo are incorrect
- File Playback tab on Audio demo, list is not ok

Any ideas?

gekkie100
Offline
Last seen: 1 week 3 days ago
Joined: 12 Apr 2005 - 14:35
Re: Can't change defaultSansSerifTypeFacename once set

Update: Our app succesfully shows the correct fonts, i don't know why the Juce Demo does not.
I'm happy of course but willing to help you test the Juce Demo more if needed.

jules
Online
Last seen: 5 min 5 sec ago
Joined: 29 Apr 2013 - 18:37
Re: Can't change defaultSansSerifTypeFacename once set

Thanks. I wouldn't worry too much about the demo, I'll take a look if I'm ever really bored..

Pages