本文整理汇总了Java中java.awt.font.TextLayout.hitTestChar方法的典型用法代码示例。如果您正苦于以下问题:Java TextLayout.hitTestChar方法的具体用法?Java TextLayout.hitTestChar怎么用?Java TextLayout.hitTestChar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.font.TextLayout
的用法示例。
在下文中一共展示了TextLayout.hitTestChar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: x2RelOffset
import java.awt.font.TextLayout; //导入方法依赖的package包/类
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;
}
示例2: x2Index
import java.awt.font.TextLayout; //导入方法依赖的package包/类
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;
}
示例3: runTest
import java.awt.font.TextLayout; //导入方法依赖的package包/类
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);
}
}
示例4: getLocationOffset
import java.awt.font.TextLayout; //导入方法依赖的package包/类
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;
}
}
}