File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Fonts in MS Windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Fonts in MS Windows" Watch "Fonts in MS Windows" New topic
Author

Fonts in MS Windows

Henrik �stman
Greenhorn

Joined: Apr 09, 2005
Posts: 11
Hi!

I having trouble displaying custom TTF-fonts in Windows.
Here is the code i'm using to load a font that is bundled with my application:

Font tmpFont = Font.createFont(Font.TRUETYPE_FONT, new
BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream(GAME_FONT)));

mFont = new Font(tmpFont.getName(), tmpFont.getStyle(), FONTSIZE);

Instead of showing my TrueType-font Windows use some kind of standard font.
The same application is working great in Linux and MacOS X!
If i install the font in Window, then the font get shown, but surly should you be able to load a font from file without installing it? Right?

What am i doing wrong? Please?
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
See the remarks under the Return section of the ClassLoader getResource method (method detail section).
Henrik �stman
Greenhorn

Joined: Apr 09, 2005
Posts: 11
Sorry, but i still don't get it.

public final static String GAME_FONT = "se/hgo/trycoon/jplane2/resources/cooper.ttf";
private final static int FONTSIZE = 50;

System.out.println("name = " + tmpFont.getName() + "\n" +
"style = " + tmpFont.getStyle() + "\n" +
"tmpFont = " + tmpFont.toString());

Gives me:
name = Cooper
style = 0
tmpFont = java.awt.Font[family=Cooper,name=Cooper,style=plain,size=1]

If the font not had been found, mGameFont = new Font(tmpFont.getName(), tmpFont.getStyle(), FONTSIZE);, would throw an exception.

But it all looks OK, except that Windows shows another font. (Mac & Linux is still working great).

More suggestions?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Fonts in MS Windows