It’s super simple with the Projucer. Just:
- Add the TTF (or OTF etc) files to the Projucer project. By default it will add them in the
BinaryData
. - Use
Typeface::createSystemTypefaceFor()
to create the typeface and construct a font.
I’ve never had a problem doing this with a Meyer’s singleton, especially now they’re threadsafe to initialise in C++11. Let’s say you had a font WackyFont.otf
and it has been added to the Projucer project. You can have a method to create this font:
static const Font& getWackyFont()
{
static Font wacky (Font (Typeface::createSystemTypefaceFor (BinaryData::WackyFont_otf,
BinaryData::WackyFont_otfSize)));
return wacky;
}
I usually add a method like this to my custom look-and-feel class. They you can get different sizes by doing things like getWackyFont().withHeight (255.0f)
etc…
I’m sure there are other patterns that you can use as Typeface::createSystemTypefaceFor()
returns a shared Typeface::Ptr
.
BTW Watch out for font licenses as many include an exclusion for embedding like this and require a separate (often more costly) license…Slightly different context but there was the My Little Pony case recently…