Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 41
Registered: ‎11-11-2010
My Device: Not Specified
Accepted Solution

Font only shows correctly on first run after installation

I have a really weird problem whereby my custom font only shows up correctly on the first run of my app after installing in the simulator or on a device. Subsequent runs of the app, show the fields with the default system font.

 

The function I am using is as follows:

 

public static Font GetCustomFont(boolean bold, int size)
{
	Font myFont = null;

	if (FontManager.getInstance().load("customfont.ttf", "custom", FontManager.APPLICATION_FONT) ==FontManager.SUCCESS)
	{
		try
		{
			FontFamily typeface = FontFamily.forName("custom");
			if (bold) myFont = typeface.getFont(Font.BOLD, size);
			else myFont = typeface.getFont(Font.ITALIC, size);
		}
		catch (Exception e)
		{ e.printStackTrace(); }
	}
	return myFont;
}

 and the font is used as follows:

 

LabelField myLabel = new LabelField("TESTING CUSTOM FONT");
myLabel.setFont(GetCustomFont(false, 24));
add(myLabel);

 

The font shows up ok the first time I run the app. Even if I call System.exit(0), then restart the app, it comes back up with the system font. My font is a 46kB TTF file, added to the res folder of my project and I am developing for BB 7.0.0.

 

Can anyone please help?

Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Font only shows correctly on first run after installation

You need to check the return code from

 

FontManager.getInstance().load(...)

 

You only accept SUCCESS, I think you will find in subsequent runs that the return code is something like 'Already loaded' and so you can use it in this circumstance too. 

Contributor
Posts: 41
Registered: ‎11-11-2010
My Device: Not Specified

Re: Font only shows correctly on first run after installation

Fixed! This is the exact problem. I now accept FontManager.DUPLICATE_NAME and FontManager.DUPLICATE_DATA in addition to FontManager.SUCCESS, although I suspect I should not be accepting duplicate data since it would not be found using a different name.

Thanks Peter!