Custom ttf and vflib


#1

I want to use Roboto Bold font in the app. I’ve generated binary h/cpp from Roboto-Bold.ttf with binarybuilder and tried to use it:

[code]
AnyComponentLookAndFeel::AnyComponentLookAndFeel(void)
{
vf::FreeTypeFaces::addFaceFromMemory(7.f, 50.f, false, binarydata::robotobold_ttf, binarydata::robotobold_ttfSize);
}

const Typeface::Ptr AnyComponentLookAndFeel::getTypefaceForFont (Font const& font)
{
Typeface::Ptr tf;
String faceName (font.getTypefaceName());
// Make requests for the default sans serif font use our
// FreeType hinted font instead.
if (faceName == Font::getDefaultSansSerifFontName())
{
// Create a new Font identical to the old one, then
// switch the name to our hinted font.
Font f (font);
// You’ll need to know the exact name embedded in the font. There
// are a variety of free programs for retrieving this information.
f.setTypefaceName (“Helvetica Neue LT Com 65 Medium”);
// Now get the hinted typeface.
tf = vf::FreeTypeFaces::createTypefaceForFont (f);
}
// If we got here without creating a new typeface
// then just use the default LookAndFeel behavior.
if (!tf)
{
tf = LookAndFeel::getTypefaceForFont (font);
}
return tf;
}

void AnyComponentLookAndFeel::drawLabel (Graphics& g, Label& label)
{
Font f(“Roboto Bold”, 40, 1);
Typeface::Ptr tf = getTypefaceForFont(f);

g.fillAll (label.findColour (Label::backgroundColourId));

if (! label.isBeingEdited())
{
	const float alpha = label.isEnabled() ? 1.0f : 0.5f;
	const Font font (getLabelFont (label));

	Font robotoFont(tf->getName(), 40, 1);
	g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
	g.setFont (robotoFont);
            ....

}[/code]
But the default font is rendered


#2
  1. You forgot to change the name from “Helvetica Neue LT Com 65 Medium” to the name of your font. If you look at ‘tf’ from the debugger I’m sure it will be a nullptr.
  2. in drawLabel you don’t need to call getTypefaceForFont, JUCE will call that for you.
  3. Your version of getTypefaceForFont should look like this:
    const Typeface::Ptr AnyComponentLookAndFeel::getTypefaceForFont (Font const& font)
    {
       Typeface::Ptr tf;
       String faceName (font.getTypefaceName());
       if (faceName == "Roboto Bold")
       //...

#3

Damn. That return type should be Typeface::Ptr, not const Typeface::Ptr… Must fix that so that the move operator can be used.


#4

If I remove getTypefaceForFont, it’s never called. It’s called only if I call LookAndFeel::setDefaultLookAndFeel(&myLookAndFeel)