Hello,
Sorry for the long post, but I’m having a hard time trying to figure out some issues I have with LookAndFeel. It seems like I’m not the only one, so I guess we need some kind of updated info on how to properly use and set the look and feel for plugins.
I also upgraded to JUCE 7 and I’m on the development branch.
We started porting some of our plugins to Linux and noticed that they are leaking the GlyphInfo class, which I suppose is related to the custom fonts implementation I’m using. macOS and Windows are not leaking, just Linux.
This is what we are doing right now, in PluginProcessor.h I have the following code before the actual AudioProcessor class (which I believe was suggested by Jules a few years ago):
struct MainLookAndFeel
{
MainLookAndFeel() { LookAndFeel::setDefaultLookAndFeel (&lnf); }
~MainLookAndFeel() { LookAndFeel::setDefaultLookAndFeel (nullptr); }
MyLookAndFeel lnf;
};
Then as a member of AudioProcessor, I have:
SharedResourcePointer<MainLookAndFeel> mainLookAndFeel;
And this was enough for all my needs, using also custom fonts this way:
static const juce::Typeface::Ptr getOpenSansRegular()
{
static auto typeface = juce::Typeface::createSystemTypefaceFor (BinaryData::OpenSansRegular_ttf,
BinaryData::OpenSansRegular_ttfSize);
return typeface;
}
static const juce::Typeface::Ptr getOpenSansBold()
{
static auto typeface = juce::Typeface::createSystemTypefaceFor (BinaryData::OpenSansBold_ttf,
BinaryData::OpenSansBold_ttfSize);
return typeface;
}
juce::Typeface::Ptr getTypefaceForFont (const juce::Font& font) override
{
if (font.getStyleFlags() == juce::Font::bold)
{
return getOpenSansBold();
}
return getOpenSansRegular();
}
So, again, macOS and Windows are perfectly fine with this, but Linux is leaking GlyphInfo. If I remove the custom fonts, I see no leaks on Linux.
I also tried to replace the SharedResourcePointer with a std::unique_ptr but I get the same issues.
So I created a new plugin with nothing but a custom LookAndFeel to test a few implementations and discovered another issue related to this thread.
If I’m using setDefaultLookAndFeel my popups call getParentComponentForMenuOptions on my LookAndFeel class and they open as I want. Instead, if I’m just using setLookAndFeel on the popup object, getParentComponentForMenuOptions in my LookAndFeel is NOT called, and popups open with default behavior.
So, to recap:
- what’s the proper way of implementing and using custom LookAndFeel with custom fonts in plugins?
- how can I avoid the leaking of
GlyphInfoon Linux if I want to use custom fonts? - is it safe to use
setDefaultLookAndFeelfor plugins? if not, there’s something wrong going on asgetParentComponentForMenuOptionsin my LookAndFeel is not called when usingsetLookAndFeelon popups.
