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.
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.
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.
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"