Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fonts in MS Windows

 
Henrik �stman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the remarks under the Return section of the ClassLoader getResource method (method detail section).
 
Henrik �stman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic