Struggles Implementing Default Custom Font

I figured this out a while ago! Here’s my solution.

  1. I defined a custom LookAndFeel class with a member called customTypeface_ which I initialized using createSystemTypefaceFor
juce::Typeface::Ptr customTypeface_ {juce::Typeface::createSystemTypefaceFor (BinaryData::RobotoMonoLight_ttf, BinaryData::RobotoMonoLight_ttfSize)};
  1. In my LookAndFeel’s constructor, I set the default san serif font to my custom typeface and set the default LookAndFeel to the custom LookAndFeel instance. I also made sure to set the default LookAndFeel to nullptr in the destructor.
CustomLAF::CustomLAF ()
{
    setDefaultSansSerifTypeface (customTypeface_);

    juce::LookAndFeel::setDefaultLookAndFeel(this);

}

CustomLAF::~CustomLAF ()
{
    juce::LookAndFeel::setDefaultLookAndFeel(nullptr);
}



  1. I then created an instance of my custom LookAndFeel as a member in my PluginEditor. No need to do anything except define it as a member variable!

I did get a weird issue when my look and feel class would randomly not propagate to PopUpMenus. I resolved this by manually setting the LookAndFeel of my PopUpMenu to the default LookAndFeel.

// in the constructor where the popup is a child
popupMenu_.setLookAndFeel(&juce::LookAndFeel::getDefaultLookAndFeel());

// in the destructor
popupMenu_.setLookAndFeel(nullptr);

This was all clearly described in the JUCE Font Embedding Guide that I skimmed rather than read (I was missing the setDefaultLookAndFeel step). TIL: when in doubt, slow down. Thanks for the help everybody!

1 Like