* @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 = aci.getBeginIndex();
for (int i = 0; i < gv.getNumGlyphs(); i++) {
Shape gbounds = gv.getGlyphLogicalBounds(i);
if (gbounds != null) {
Rectangle2D gbounds2d = gbounds.getBounds2D();
if (gbounds.contains(x, y)) {
boolean isRightHalf =
(x > (gbounds2d.getX()+(gbounds2d.getWidth()/2d)));
boolean isLeadingEdge = !isRightHalf;
aci.setIndex(currentChar);
int charIndex = ((Integer)aci.getAttribute(
GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
textHit = new TextHit(charIndex, isLeadingEdge);
return textHit;
}
}
currentChar += getCharacterCount(i, i);
}