# Multiple fonts in custom look and feel

**URL:** <https://forum.juce.com/t/multiple-fonts-in-custom-look-and-feel/26818>\
**Category:** General JUCE discussion\
**Created:** [March 15, 2018, 2:49pm UTC](https://forum.juce.com/t/multiple-fonts-in-custom-look-and-feel/26818 "2018-03-15T14:49:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samdav1es](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@samdav1es](https://forum.juce.com/u/samdav1es)\
**Post date:** [March 15, 2018, 2:49pm UTC](https://forum.juce.com/t/multiple-fonts-in-custom-look-and-feel/26818/1 "2018-03-15T14:49:33Z")

</div>

Hi, I have an app that is tabbed and each tab component has it’s own unique custom look and feel. Each of these tab components also needs its own embedded font that I create through createSystemTypefaceFor( ) and override getTypefaceForFont( ).

However, I am struggling to get the different look and feels to use their own font as in juce LookAndFeel::getTypefaceForFontFromLookAndFeel(const Font& font ) the font returned will only use the app’s getDefaultLookAndFeel( ) rather than the look and feel of the tab component.

I have tried setting the tab components to change the default look and feel by adding LookAndFeel::setDefaultLookAndFeel (&\_tab1LookAndFeel); in the constructor but this doesn’t seem to work.

How do other people use different multiple embedded fonts in their applications?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [March 15, 2018, 3:16pm UTC](https://forum.juce.com/t/multiple-fonts-in-custom-look-and-feel/26818/2 "2018-03-15T15:16:15Z")

</div>

Simply use [Component::setLookAndFeel()](https://juce.com/doc/classComponent#a6f2c10cd9840844a5be16e5deeef6f50). This will set the look and feel only for this component and their children.

The procedure for a component is to look if a lookAndFeel is set, if not traverse the hierarchy, until a parent is found, that has a LookAndFeel defined, and use this one.  
If none is found, it will use the one you set with LookAndFeel::setDefaultLookAndFeel…

Caveat: you need to own that LookAndFeel, preferably in a ScopedPointer. So take care in which order they are deleted. Probably a setLookAndFeel (nullptr) in the destructor could be needed.

HTH

---

<div class="post-metadata">

**Author:** ![samdav1es](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@samdav1es](https://forum.juce.com/u/samdav1es)\
**Post date:** [March 15, 2018, 3:26pm UTC](https://forum.juce.com/t/multiple-fonts-in-custom-look-and-feel/26818/3 "2018-03-15T15:26:41Z")

</div>

Thanks for the reply daniel. Maybe I should have been more specific but the problem I am having is with fonts. Only the font set in the default look and feel is used, while I want to have my own font for each custom look and feel

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [March 15, 2018, 3:37pm UTC](https://forum.juce.com/t/multiple-fonts-in-custom-look-and-feel/26818/4 "2018-03-15T15:37:00Z")

</div>

I see. Indeed, looking into the LookAndFeel, there are several callbacks, e.g. getPopupMenuFont() . Did you try to override those in your custom LNF returning a specific font for that purpose?

I think it would be a good addition to allow setting a Font in a LNF instance to be used in all those callbacks, leaving them to adjust the size, which is the only thing they do at the moment…

---

<div class="post-metadata">

**Author:** ![samdav1es](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@samdav1es](https://forum.juce.com/u/samdav1es)\
**Post date:** [March 16, 2018, 12:26pm UTC](https://forum.juce.com/t/multiple-fonts-in-custom-look-and-feel/26818/5 "2018-03-16T12:26:38Z")

</div>

Ok so I have found a solution by overriding the getFont() functions in LookAndFeel to return a Font with a custom font name. Then in my default LookAndFeel getTypefaceForFont() override I have an if statement that tests the name of which font to use. A bit hacky but it seems to work:

class Tab1LookAndFeel : public LookAndFeel\_V4  
{  
public:  
Font getLabelFont(Label &label) override;  
Font getTextButtonFont (TextButton&, int buttonHeight) override;  
}

Font Tab1LookAndFeel::getLabelFont(Label &label)  
{  
return Font (“Tab1Font”, label.getFont().getHeight(), Font::plain);  
}

Font Tab1LookAndFeel::getTextButtonFont (TextButton&, int buttonHeight)  
{  
return Font (“Tab1Font”, jmin (15.0f, buttonHeight \* 0.5f), Font::plain);  
}

class DefaultLookAndFeel : public LookAndFeel\_V4  
{  
public:  
virtual Typeface::Ptr getTypefaceForFont (const Font&) override;  
private:  
Typeface::Ptr tab1Tf;  
Typeface::Ptr defaulTf;  
}

DefaultLookAndFeel::DefaultLookAndFeel()  
{  
tab1Tf = Typeface::createSystemTypefaceFor(BinaryData::tabfont\_ttf,  
BinaryData::tabfont\_ttfSize);  
defaultTf = Typeface::createSystemTypefaceFor(BinaryData::defaultfont\_ttf,  
BinaryData:: defaultfont\_ttfSize);  
}

Typeface::Ptr DefaultLookAndFeel::getTypefaceForFont (const Font& font)  
{  
if (font.getTypefaceName() == “Tab1Font”)  
{  
return tab1Tf;  
}  
else  
{  
return defaultTf;  
}  
}

Does anybody know why the font used is always the default LookAndFeel’s font and not the current one?
