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
|