Can't change defaultSansSerifTypeFacename once set

Discussion and support for general JUCE issues

Can't change defaultSansSerifTypeFacename once set

Postby gekkie100 » Tue Jun 26, 2012 9:51 am

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)
Code: Select all
     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.

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

"Hello" = "こんにちは"
"Composition" = "コンポジション"
"Composition Properties" = "コンポジションプロパティ"
"Composition Settings" = "コンポジション設定"
"Composition Effects" = "コンポジションエフェクト"
"Composition Audio" = "コンポジションオーディオ"
"Composition Video" = "コンポジションビデオ"
.....
gekkie100
JUCE UberWeenie
 
Posts: 249
Joined: Tue Apr 12, 2005 2:35 pm

Re: Can't change defaultSansSerifTypeFacename once set

Postby jules » Tue Jun 26, 2012 10:40 am

Looks like it had already cached the typeface.. I've checked in something that will hopefully fix it - try it again now.
User avatar
jules
Fearless Leader
 
Posts: 17193
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: Can't change defaultSansSerifTypeFacename once set

Postby gekkie100 » Tue Jun 26, 2012 11:02 am

Thanx for looking at it Jules.
It partly works, some components works well others don't. Maybe because they have different styles?
Screenshot below:
Attachments
Screen shot 2012-06-26 at 12.01.50 PM.png
Screen shot 2012-06-26 at 12.01.50 PM.png (83.29 KiB) Viewed 420 times
gekkie100
JUCE UberWeenie
 
Posts: 249
Joined: Tue Apr 12, 2005 2:35 pm

Re: Can't change defaultSansSerifTypeFacename once set

Postby jules » Tue Jun 26, 2012 11:06 am

Could be because those components are storing a Font object internally, and continuing to use that after you change the default typeface..?
User avatar
jules
Fearless Leader
 
Posts: 17193
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: Can't change defaultSansSerifTypeFacename once set

Postby gekkie100 » Tue Jun 26, 2012 11:11 am

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
JUCE UberWeenie
 
Posts: 249
Joined: Tue Apr 12, 2005 2:35 pm

Re: Can't change defaultSansSerifTypeFacename once set

Postby gekkie100 » Tue Jun 26, 2012 12:48 pm

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?
gekkie100
JUCE UberWeenie
 
Posts: 249
Joined: Tue Apr 12, 2005 2:35 pm

Re: Can't change defaultSansSerifTypeFacename once set

Postby jules » Tue Jun 26, 2012 1:20 pm

Interesting. I think it might be the style that's messing it up. Try again now..
User avatar
jules
Fearless Leader
 
Posts: 17193
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: Can't change defaultSansSerifTypeFacename once set

Postby gekkie100 » Tue Jun 26, 2012 2:13 pm

The Juce Demo seems to work fine, now merging your change to our own juce branch, manual labour so it takes a while.
gekkie100
JUCE UberWeenie
 
Posts: 249
Joined: Tue Apr 12, 2005 2:35 pm

Re: Can't change defaultSansSerifTypeFacename once set

Postby gekkie100 » Tue Jun 26, 2012 2:30 pm

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
JUCE UberWeenie
 
Posts: 249
Joined: Tue Apr 12, 2005 2:35 pm

Re: Can't change defaultSansSerifTypeFacename once set

Postby gekkie100 » Tue Jun 26, 2012 3:12 pm

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.
gekkie100
JUCE UberWeenie
 
Posts: 249
Joined: Tue Apr 12, 2005 2:35 pm

Re: Can't change defaultSansSerifTypeFacename once set

Postby jules » Tue Jun 26, 2012 3:20 pm

Thanks. I wouldn't worry too much about the demo, I'll take a look if I'm ever really bored..
User avatar
jules
Fearless Leader
 
Posts: 17193
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: Can't change defaultSansSerifTypeFacename once set

Postby gekkie100 » Fri Jun 29, 2012 11:24 am

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"

Code: Select all
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;
    }
.....
gekkie100
JUCE UberWeenie
 
Posts: 249
Joined: Tue Apr 12, 2005 2:35 pm

Re: Can't change defaultSansSerifTypeFacename once set

Postby gekkie100 » Mon Jul 02, 2012 10:26 am

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.
gekkie100
JUCE UberWeenie
 
Posts: 249
Joined: Tue Apr 12, 2005 2:35 pm

Re: Can't change defaultSansSerifTypeFacename once set

Postby jules » Mon Jul 02, 2012 3:00 pm

Hi.. Yes, sorry, that's exactly what I should have done originally - thanks for spotting it!
User avatar
jules
Fearless Leader
 
Posts: 17193
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: Can't change defaultSansSerifTypeFacename once set

Postby gekkie100 » Mon Jul 02, 2012 7:33 pm

Ok thanx!
gekkie100
JUCE UberWeenie
 
Posts: 249
Joined: Tue Apr 12, 2005 2:35 pm


Return to General JUCE discussion

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 2 guests

cron