Kerning problems when drawing text character by character

Posted by shekel on Stack Overflow See other posts from Stack Overflow or by shekel
Published on 2011-01-03T06:45:48Z Indexed on 2011/01/03 6:54 UTC
Read the original article Hit count: 235

Filed under:
|
|
|

I'm trying to draw strings character by character to add lighting effects to shapes composed of text.

while (i != line.length()) {
c = line.substring(i, i + 1);

cWidth = g.getFontMetrics().stringWidth(c);

g.drawString(c, xx += cWidth, yy);
i++;
}

The problem is, the width of a character isn't the actual distance it's drawn from another character when those two characters are printed as a string. Is there any way to get the correct distance in graphics2d?

© Stack Overflow or respective owner

Related posts about java

Related posts about string