Hello all,
I’m attempting to integrate a custom font into my plugin. Currently, I’m overriding the getTypefaceForFont method, creating a member variable in PluginEditor class called font and passing it to the desired components. I then set the font in the paint method using the juce::Graphics setFont method.
`
juce::Typeface::Ptr getTypefaceForFont(const juce::Font& f) override
{
juce::ignoreUnused(f);
static juce::Typeface::Ptr myFont = juce::Typeface::createSystemTypefaceFor(BinaryData::MegrimRegular_ttf, BinaryData::MegrimRegular_ttfSize);
return myFont;
};
void paint (juce::Graphics& g) override
{
g.setFont(font);
g.fillAll(juce::Colours::black);
g.setColour (juce::Colours::white);
g.drawRect (bounds, 1.0); // draw an outline around the component
g.setFont (fontHeight);
g.drawText (text, bounds, juce::Justification::centred, true); // draw some placeholder text
}
`
This works but feels wrong. My initial approach was to override the default LookAndFeel with my getTypefaceForFont function, then ensure that the juce::Graphics class uses this function whenever it paints.
I tried doing this using the following constructor with the overridden getTypefaceForFont method
CustomLookAndFeel () { setDefaultSansSerifTypeface(getTypefaceForFont(juce::Font ())); };
but I still end up with the default font rather than my custom font.
- When is the getTypefaceForFont() used?
- When and where is the Font set for the Graphics object passed into a component’s paint method?
The answer to these questions + any other insight would be greatly appreciated. Thank you for your time.