Slick Forums

Discuss the Slick 2D Library
It is currently Fri Sep 25, 2020 12:27 am

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue Oct 16, 2012 6:36 pm 

Joined: Thu Jul 28, 2011 9:42 pm
Posts: 6
Hello there,

I seem to be seeing a very odd behaviour when it comes to using the measuring facilities provided by UnicodeFont. The current font I am loading in is standard Arial at 14px:

UnicodeFont font = new UnicodeFont(new Font("Arial", 0, 14));
try {
font.getEffects().add(new ColorEffect(java.awt.Color.white));
} catch (Exception e) {
System.err.println("Unable to load UI font");
return null;

When I measure the width of the letter "m" I get 11:

int i = font.getWidth("m");

However, if I then draw a string, using the offset start and end optional arguments, the width permanently changes to 26:

font.drawString(0, 0, "Hello",, 1, 3);


Any ideas why I'm seeing this behaviour? I couldn't find it documented anywhere so I'm assuming it's a bug. A workaround is to create two fonts, one for measurements and one for rendering, but as it already takes a fair while to render the fonts I'd quite like to avoid this if possible!

Many thanks,

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 0 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group