Java Code Examples for java.awt.font.TextLayout#hitTestChar()
The following examples show how to use
java.awt.font.TextLayout#hitTestChar() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextMeasureTests.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 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 2
Source File: TextMeasureTests.java From openjdk-8-source with GNU General Public License v2.0 | 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 3
Source File: CompositionArea.java From jdk8u_jdk with GNU General Public License v2.0 | 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 4
Source File: CompositionArea.java From jdk8u-jdk with GNU General Public License v2.0 | 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
Source File: TextMeasureTests.java From jdk8u-jdk with GNU General Public License v2.0 | 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
Source File: TextMeasureTests.java From jdk8u-jdk with GNU General Public License v2.0 | 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 7
Source File: CompositionArea.java From openjdk-jdk9 with GNU General Public License v2.0 | 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 8
Source File: TextMeasureTests.java From openjdk-8 with GNU General Public License v2.0 | 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 9
Source File: CompositionArea.java From Bytecoder with Apache License 2.0 | 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 10
Source File: CompositionArea.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 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 11
Source File: ZyCaret.java From binnavi with Apache License 2.0 | 5 votes |
private int calcHitPosition(final int caretPosition, final double x, final double y, final double zoomFactor) { boolean switched = false; int lp = m_mouse_pressed_y; int lr = m_mouse_released_y; if (lp > lr) { lp = m_mouse_released_y; lr = m_mouse_pressed_y; switched = true; } final int linecount = m_content.getLineCount(); final double height = (float) m_content.getLineHeight(); int maxIndex = caretPosition; for (int line = lp; line <= lr; line++) { double deltaY = 0; if (switched) { deltaY = height * zoomFactor * line; } else { deltaY = -(height * zoomFactor * (linecount - line)); } final TextLayout textLayout = m_content.getLineContent(line).getTextLayout(); final TextHitInfo hitInfo = textLayout.hitTestChar((float) x, (float) (y + deltaY), textLayout.getBounds()); final int insertionIndex = hitInfo.getInsertionIndex(); if ((caretPosition < insertionIndex) && (insertionIndex > maxIndex)) { maxIndex = insertionIndex; } } return maxIndex; }
Example 12
Source File: TextMeasureTests.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 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 13
Source File: FoldView.java From netbeans with Apache License 2.0 | 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 14
Source File: TextMeasureTests.java From jdk8u_jdk with GNU General Public License v2.0 | 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 15
Source File: TextMeasureTests.java From openjdk-jdk8u with GNU General Public License v2.0 | 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 16
Source File: CompositionArea.java From jdk8u60 with GNU General Public License v2.0 | 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 17
Source File: TextMeasureTests.java From jdk8u60 with GNU General Public License v2.0 | 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 18
Source File: CompositionArea.java From TencentKona-8 with GNU General Public License v2.0 | 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 19
Source File: TextMeasureTests.java From TencentKona-8 with GNU General Public License v2.0 | 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 20
Source File: CompositionArea.java From dragonwell8_jdk with GNU General Public License v2.0 | 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; } } }