I'm looking for a simple step-by-step solution to embedding fonts in JUCE.
I'm having a bit of trouble embedding fonts in my app (totally forgot to put time into this before an app release, and now my app isn't displaying my font on user systems - understandably so).
I've searched and followed all the posts available on the subject, but am still having issues. I'd like to be to add the embedded font to labels already present in my app that we're created and layed out via a ProJucer GUI component.
What I've done so far:
1) Added the font to my ProJucer session so that it gets added to BinaryData
2) Created a class I called "EmbeddedFont:"
#include "../JuceLibraryCode/JuceHeader.h"
class EmbeddedFonts
{
private:
Font calistoMT;
public:
EmbeddedFonts();
Font& getCalistoMT();
};
and
EmbeddedFonts::EmbeddedFonts()
{
// in the line below is where I'm getting the assertion error: jassert (typefaceName.isNotEmpty());
calistoMT = Font(Typeface::createSystemTypefaceFor(BinaryData::Calisto_MT,
BinaryData::Calisto_MTSize));
}
Font& EmbeddedFonts::getCalistoMT()
{
return calistoMT;
}
3) Made an instance of this in the header of my GUI component class 4) Tried passing this font to the label font:
genericLabelName->setFont(embeddedFont.getCalistoMT());
Not really sure what to do from here. Also, after I get the embedded font to work, is there anything specific I should be doing to the font field in the projucer GUI component? Should I just set it to the same font? I only ask because I will technically be setting the font twice in the constructor (once from the GUI Component option drop-down menu and once from hand coding the embedded font).
I've tried this for a few days and still am having trouble. Thanks for any help. This is the last thing I need to do before releasing my next app update, so any assistance is greatly appreciated.
Since it looks like you're doing things correctly on the JUCE side of things, I believe the font file you're trying to load in doesn't have a name associated with it. I would try the following:
Check the name of the Typeface
returned from your createSystemTypefaceFor
call before you pass it to the Font
constructor. I believe it should have a getName()
or similar call to get its name. If that name is empty (and I expect it to be, given your assert), there's your problem.
You may want to try downloading a TTF file viewer that can give you some information on that file that you're trying to load in. It could also indicate if the font you're reading in has a name in it or not. If it does appear to have a name in its Metadata, that might indicate a bug in the JUCE library.
You might try loading in a different font or different fonts that you know have the correct name in the metadata (because you've checked with some sort of viewer or tool), and see if the typeface created for them has the name set, and, if so, try creating a Font
from one of those typefaces and see if it succeeds.
If the typeface loaded in actually does have a name set, then this theory kind of goes out the window, but I would still try the third step and see if you always get this error with every font or if it's limited to just the one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With