Can't change defaultSansSerifTypeFacename once set


#1

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" = "コンポジションビデオ"
.....

#2

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


#3

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


#4

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


#5

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.


#6

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?


#7

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


#8

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


#9

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?


#10

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.


#11

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


#12

I thought i had it working but i was wrong. Some components are still not showing the right font.
So i digged around the code and figured that when you clear the TypeFaceCache you’ll need to set defaultFace = nullptr;
If i do this it seems to work fine, also your Juce Demo seems to pick up the changes.
is this a safe fix, or doesn’t it make sense to you"

class TypefaceCache  : public DeletedAtShutdown
{
public:
    TypefaceCache()
        : counter (0)
    {
        setSize (10);
    }

    ~TypefaceCache()
    {
        clearSingletonInstance();
    }

    juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache);

    void setSize (const int numToCache)
    {
        faces.clear();
        faces.insertMultiple (-1, CachedFace(), numToCache);
    }

    void clear()
    {
        setSize (faces.size());
		defaultFace = nullptr;
    }
.....

#13

Jules, could you have a look at my last post.
I would like to know if setting the defaultFace to null when clearing the cache is safe.


#14

Hi… Yes, sorry, that’s exactly what I should have done originally - thanks for spotting it!


#15

Ok thanx!