In application i have to use custom font. First i create class that extends VerticalFieldManager class. In this class i want to use custom font. I have TTF file (name is AGENCYB.TTF). I kept this file in res/img folder. To load this file i use following code:
if (FontManager.getInstance().load("AGENCYB.TTF", "MyFont",
FontManager.APPLICATION_FONT) == FontManager.SUCCESS)
{
System.out.println("**************************IF SUCCESS*******");
try
{
FontFamily typeface = FontFamily.forName("MyFont");
myFont = typeface.getFont(Font.BOLD, 50);
label2.setFont(myFont);
}
catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
}
But it is not changing font of label field. I implemented code by using this link:
http://docs.blackberry.com/en/developers/deliverables/18095/BlackBerry_Java_SDK-Development_Guide–1239696-0730090812-001-6.0-US.pdf
Any idea would be great help.
Thanks
**********EDIT**************
if (FontManager.getInstance().load("AGENCYB.TTF", "AGENCYB", FontManager.APPLICATION_FONT) == FontManager.SUCCESS)
First of all, this is the BlackBerry tutorial I’ve used for loading custom fonts
Second of all, I don’t see a return code of 8 in any of the values that the API docs says
FontManager.load()returns.SUCCESSis a value of 0, so you’re not successfully callingload().http://www.blackberry.com/developers/docs/7.0.0api/net/rim/device/api/ui/FontManager.html
When I ran in the debugger on OS 5.0 and 7.1, I saw that
-8was equal toFontManager.DUPLICATE_NAME, but didn’t see any code equal to8.Also, did you generate this font file yourself (AGENCYB.TTF)? Because your code is asking for a font named MyFont in the AGENCYB.TTF file. I wouldn’t expect a font to actually be named MyFont unless it was somebody writing a Hello World program (and homemade .ttf file).
If this is a custom font, provided by a 3rd-party font library, or bought from someone else, I would expect the font names to be something other than MyFont, which is what they have in the BlackBerry sample that you probably copied your code from.
So, double-check that, and let us know if it’s still not working.
Update: since it looks like you also fail when you use the string
"AGENCYB"in your code, I think the problem is that you’re using the wrong font name. Even though the file isAGENCYB.TTF, I bet the font name inside that file is notAGENCYB. Is this the same file that you find in Windows underC:\Windows\fonts? If so, you can use Windows (7, at least) to look at the font file.Just double-click the .ttf file in Windows Explorer, and it should give you a preview, that shows the proper font name. That name is the name you use in the two java calls, where the sample code has
"MyFont". In this case, you see that the font name is probably"Agency FB". Try that.Update 2: I also tried loading the Agency FB font from the
AGENCYR.TTFfile that can be found inC:\windows\Fonts\AGENCYR.TTFon a Windows 7 machine. This exact code worked for me on a 5.0 8900 simulator: