本文整理匯總了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;
}
}
}