Custom font issue

Hi there,

I have a problem with a custom font :

  • I exported a system font using FontManager executable found in the forum
  • I have used binarybuilder to get it in cpp/h files
  • I have overloaded getTypefaceForFont() in L&F for setting my custom typeface for fonts
  • I shows labels using my L&F -> NO TEXT

Do you have an idea about the cause of this problem ?

Well,

I resolved my issue, it was only because a bad export of TTF.
Now it works, but I don’t know how to set default font !
I overloaded getTypefaceForFont() function, but labels don’t use my custom font.
So, can you tell me how it works ?
Where can I define a global font ?

Thanks

Please help ?

Maybe you’re creating your lookandfeel too late, so that some fonts have already loaded and cached the default typeface before you set your own custom one?

I have inserted my L+F in Jucer so that I can select it as we can do with new and old school L+F.
If it does not work like this, how do I have to create it ? Or when ?

Well, you’d need to apply it before creating the Font objects that you want it to change. Once a Font has been created, its typeface is fixed, and won’t be affected by anything you do in the l+f afterwards.

So I have to initialize it before TypefaceCache, if I understand well.
How can I initialize it before for sure ?
Or how can I reset TypefaceCache ?

No.

Like I said, any Font objects created before you apply your l+f will not be affected by it.

You were complaining that a label wasn’t using your typeface, so I’m assuming you created this label BEFORE you applied your l+f, and it probably has an internal Font object that was created beforehand.

So :

  • If I create a label before setting my own l+f, it cannot be changed by new l+f
  • If I create a label after setting my own l+f, it will have the typeface defined by my l+f in getTypefaceForFont()

That does not work !
Both label have same fonts !

Well, I didn’t say this was definitely the reason your label wasn’t working, it was just a possible cause!

You’re setting your l+f as the global default l+f, right? It won’t work on individual components.

Hi,

Yes, my l+f is set using LookAndFeel::setDefaultLookAndFeel() function.
In fact, I have two issues now that I cannot understand…

  1. Labels are not created using my custom font by default, even after having set my l+f as default
  2. If I set my custom font on those labels using Jucer combobox, it works. But if I set bold and/or italic styles, labels are not updated using those.

I really do not understand how it works…

Can you explain really clearly ?

When a Font is asked to produce its Typeface object, it uses LookAndFeel::getTypefaceForFont to get one.

The result gets cached inside the Font object, so it will only call getTypefaceForFont once.

That’s it. I don’t know what else you expect me to explain!

[quote=“jules”]
When a Font is asked to produce its Typeface object, it uses LookAndFeel::getTypefaceForFont to get one.

The result gets cached inside the Font object, so it will only call getTypefaceForFont once.

That’s it. I don’t know what else you expect me to explain![/quote]

So I tried something :

  • Put a break into getTypefaceForFont() in my own l+f
  • Create a label

At the creation label does not look in l+f, and get a default font (sansSerif).
It does like this because of creating font member using SharedFontInternal which initialize typeface like this :

So, what I am supposed to do ?

Ok !
I found something !

If I initialize my l+f before any window, TypefaceCache uses its typeface ! …

So apparently, after having initialized any GUI component using a selected l+f, you cannot change labels without restarting application because TypefaceCache is not reset by new l+f.

Is that normal ?

I was assuming you already were creating your l+f before creating any components!

If you really need to change it later, you could clear the cache by calling Typeface::setTypefaceCacheSize, but even then you can’t guarantee that all fonts will magically update, so just setting it up early is the best plan.

Ok !
So if I understand well, you cannot have two custom l+f with custom typeface for each…
That’s so cruel :?

So now that I understood how to set it by default, can you explain me why I cannot set labels in bold or italic ?
That does not work at all, whereas I exported the 260 glyphs using FontBuilder (application posted in another thread).
Do you know why ?

How could it know which typeface it should use as a bold version of your custom font?

Typeface are not independent of that parameter ?
FontBuilder does not extract the whole thing ?
How can we do with getTypefaceForFont() for example ?

Sorry, I don’t understand your question.