* @return a TextHit object encapsulating the character index for
* successful hits and whether the hit is on the character
* leading edge.
*/
public TextHit hitTestChar(float x, float y) {
TextHit textHit = null;
// if this layout is transformed, need to apply the inverse
// transform to the point
if (transform != null) {
try {
Point2D p = new Point2D.Float(x, y);
transform.inverseTransform(p, p);
x = (float) p.getX();
y = (float) p.getY();
} catch (java.awt.geom.NoninvertibleTransformException nite) {;}
}
int currentChar = 0;
for (int i = 0; i < gv.getNumGlyphs(); i++) {
Shape gbounds = gv.getGlyphLogicalBounds(i);
if (gbounds != null) {
Rectangle2D gbounds2d = gbounds.getBounds2D();
// System.out.println("Hit Test: [" + x + ", " + y + "] - " +
// gbounds2d);
if (gbounds.contains(x, y)) {
boolean isRightHalf =
(x > (gbounds2d.getX()+(gbounds2d.getWidth()/2d)));
boolean isLeadingEdge = !isRightHalf;
int charIndex = charMap[currentChar];
textHit = new TextHit(charIndex, isLeadingEdge);
return textHit;
}
}
currentChar += getCharacterCount(i, i);
}