* @param y start Y position to draw
*/
public void drawString(Graphics2D g, String str, float x, float y) {
char[] input = str.toCharArray();
Character ch;
Glyph glyph;
DLInfo info;
GlyphMetrics glMetrics;
Color col = g.getColor();
Font font = g.getFont();
int length = str.length();
FontPeerImpl peer = ((FontPeerImpl)font.getPeer());
AffineTransform fontAT = (AffineTransform)font.getTransform().clone();
Point.Float pos = new Point.Float();
Paint paint = g.getPaint();
boolean isAntialias = g.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING) == RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
try {
fontAT.inverseTransform(new Point.Double(x + fontAT.getTranslateX(), y + fontAT.getTranslateY()), pos);
} catch (NoninvertibleTransformException e) {
// TODO determinant equals 0 => point or line
g.fill(font.createGlyphVector(g.getFontRenderContext(), str).getOutline(x, y));
return;
}
fontAT.translate(pos.x,pos.y);
g.transform(fontAT);
HashCode hash = new HashCode();
hash.append(peer);
hash.append(getFactor(g.getTransform()));
hash.append(paint);
hash.append(isAntialias);
Integer intHash = new Integer(hash.hashCode());
GlyphHashtable glyphHash =
intHash2glyphHash.containsKey(intHash) ?
(GlyphHashtable) intHash2glyphHash.get(intHash) : null;
if ( glyphHash == null) {
glyphHash = new GlyphHashtable();
intHash2glyphHash. put(intHash, glyphHash);
}
activateVars();
for (int i = 0; i - length < 0; i ++) {
ch = new Character(input[i]);
if (ESCAPE.contains(ch)) continue;
glyph = peer.getGlyph(input[i]);
if (ch == ' ') {
glMetrics = glyph.getGlyphPointMetrics();
gl.glTranslated(
glMetrics.getAdvanceX(),
glMetrics.getAdvanceY(),
0
);
continue;
}
info = glyphHash.containsKey(ch) ? (DLInfo)glyphHash.get(ch) : null;
if (info == null || !info.isValid()) {
createColorGlyphDL(g, glyph, glyphHash, font, ch, col, isAntialias);
} else {
gl.glCallList(info.getDL());
}
glMetrics = glyph.getGlyphPointMetrics();
gl.glTranslated(
glMetrics.getAdvanceX(),
glMetrics.getAdvanceY(),
0
);