This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Fonts in MS Windows  RSS feed

 
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?
 
Ranch Hand
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?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!