Slick Forums
http://slick.ninjacave.com/forum/

BUG: Unicode Font getWidth() changes if text offset
http://slick.ninjacave.com/forum/viewtopic.php?f=1&t=5658
Page 1 of 1

Author:  hugheth [ Tue Oct 16, 2012 6:36 pm ]
Post subject:  BUG: Unicode Font getWidth() changes if text offset

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));
font.addAsciiGlyphs();
font.loadGlyphs();
} 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", Color.black, 1, 3);

System.out.println(font.getWidth("m"));

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,
Hugh

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/