Java Code Examples for java.awt.font.TextLayout.hitTestChar()

The following are Jave code examples for showing how to use hitTestChar() of the java.awt.font.TextLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: FoldView.java   Source Code and License Vote up 5 votes
static TextHitInfo x2RelOffset(TextLayout textLayout, float x) {
    TextHitInfo hit;
    x -= EXTRA_MARGIN_WIDTH;
    if (x >= textLayout.getAdvance()) {
        hit = TextHitInfo.trailing(textLayout.getCharacterCount());
    } else {
        hit = textLayout.hitTestChar(x, 0); // What about backward bias -> with higher offsets it may go back visually
    }
    return hit;

}
 
Example 2
Project: incubator-netbeans   File: HighlightsViewUtils.java   Source Code and License Vote up 5 votes
static TextHitInfo x2Index(TextLayout textLayout, float x) {
    TextHitInfo hit;
    hit = textLayout.hitTestChar(x, 0);
    // Use forward bias only since BaseCaret and other code is not sensitive to backward bias yet
    if (!hit.isLeadingEdge()) {
        hit = TextHitInfo.leading(hit.getInsertionIndex());
    }
    return hit;
}
 
Example 3
Project: OpenJSharp   File: TextMeasureTests.java   Source Code and License Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    TLExContext tlctx = (TLExContext)ctx;
    TextLayout tl = tlctx.tl;
    int numhits = tlctx.hits.length;
    Rectangle2D lb = tlctx.lb;
    TextHitInfo hit;
    for (int i = 0; i <= numhits; ++i) {
        float x = (float)(lb.getMinX() + lb.getWidth() * i / numhits);
        float y = (float)(lb.getMinY() + lb.getHeight() * i / numhits);
        hit = tl.hitTestChar(x, y, lb);
    }
}
 
Example 4
Project: OpenJSharp   File: CompositionArea.java   Source Code and License Vote up 5 votes
TextHitInfo getLocationOffset(int x, int y) {
    TextLayout layout = composedTextLayout;
    if (layout == null) {
        return null;
    } else {
        Point location = getLocationOnScreen();
        x -= location.x + TEXT_ORIGIN_X;
        y -= location.y + TEXT_ORIGIN_Y;
        if (layout.getBounds().contains(x, y)) {
            return layout.hitTestChar(x, y);
        } else {
            return null;
        }
    }
}
 
Example 5
Project: jdk8u-jdk   File: TextMeasureTests.java   Source Code and License Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    TLExContext tlctx = (TLExContext)ctx;
    TextLayout tl = tlctx.tl;
    int numhits = tlctx.hits.length;
    Rectangle2D lb = tlctx.lb;
    TextHitInfo hit;
    for (int i = 0; i <= numhits; ++i) {
        float x = (float)(lb.getMinX() + lb.getWidth() * i / numhits);
        float y = (float)(lb.getMinY() + lb.getHeight() * i / numhits);
        hit = tl.hitTestChar(x, y, lb);
    }
}
 
Example 6
Project: jdk8u-jdk   File: CompositionArea.java   Source Code and License Vote up 5 votes
TextHitInfo getLocationOffset(int x, int y) {
    TextLayout layout = composedTextLayout;
    if (layout == null) {
        return null;
    } else {
        Point location = getLocationOnScreen();
        x -= location.x + TEXT_ORIGIN_X;
        y -= location.y + TEXT_ORIGIN_Y;
        if (layout.getBounds().contains(x, y)) {
            return layout.hitTestChar(x, y);
        } else {
            return null;
        }
    }
}
 
Example 7
Project: openjdk-jdk10   File: TextMeasureTests.java   Source Code and License Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    TLExContext tlctx = (TLExContext)ctx;
    TextLayout tl = tlctx.tl;
    int numhits = tlctx.hits.length;
    Rectangle2D lb = tlctx.lb;
    TextHitInfo hit;
    for (int i = 0; i <= numhits; ++i) {
        float x = (float)(lb.getMinX() + lb.getWidth() * i / numhits);
        float y = (float)(lb.getMinY() + lb.getHeight() * i / numhits);
        hit = tl.hitTestChar(x, y, lb);
    }
}
 
Example 8
Project: openjdk-jdk10   File: CompositionArea.java   Source Code and License Vote up 5 votes
TextHitInfo getLocationOffset(int x, int y) {
    TextLayout layout = composedTextLayout;
    if (layout == null) {
        return null;
    } else {
        Point location = getLocationOnScreen();
        x -= location.x + TEXT_ORIGIN_X;
        y -= location.y + TEXT_ORIGIN_Y;
        if (layout.getBounds().contains(x, y)) {
            return layout.hitTestChar(x, y);
        } else {
            return null;
        }
    }
}