use of java.awt.font.TextHitInfo in project jdk8u_jdk by JetBrains.
the class LigatureCaretTest method testLamAlef.
/**
* Ensure proper careting and hit-testing behavior with
* a lam-alef ligature.
* If the test fails, an Error is thrown.
* @exception an Error is thrown if the test fails
*/
public static void testLamAlef() {
// lam-alef form a mandantory ligature.
final String lamAlef = "لا";
final String ltrText = "abcd";
// Create a TextLayout with just a lam-alef sequence. There
// should only be two valid caret positions: one at
// insertion offset 0 and the other at insertion offset 2.
TextLayout layout = new TextLayout(lamAlef, map, frc);
TextHitInfo hit;
hit = layout.getNextLeftHit(0);
if (hit.getInsertionIndex() != 2) {
throw new Error("Left hit failed. Hit:" + hit);
}
hit = layout.getNextRightHit(2);
if (hit.getInsertionIndex() != 0) {
throw new Error("Right hit failed. Hit:" + hit);
}
hit = layout.hitTestChar(layout.getAdvance() / 2, 0);
if (hit.getInsertionIndex() != 0 && hit.getInsertionIndex() != 2) {
throw new Error("Hit-test allowed incorrect caret. Hit:" + hit);
}
// Create a TextLayout with some left-to-right text
// before the lam-alef sequence. There should not be
// a caret position between the lam and alef.
layout = new TextLayout(ltrText + lamAlef, map, frc);
final int ltrLen = ltrText.length();
final int layoutLen = layout.getCharacterCount();
for (int i = 0; i < ltrLen; i++) {
hit = layout.getNextRightHit(i);
if (hit.getInsertionIndex() != i + 1) {
throw new Error("Right hit failed in ltr text.");
}
}
hit = layout.getNextRightHit(ltrLen);
if (layoutLen != hit.getInsertionIndex()) {
throw new Error("Right hit failed at direction boundary.");
}
hit = layout.getNextLeftHit(layoutLen);
if (hit.getInsertionIndex() != ltrLen) {
throw new Error("Left hit failed at end of text.");
}
}
use of java.awt.font.TextHitInfo in project jdk8u_jdk by JetBrains.
the class LigatureCaretTest method testBidiWithNumbers.
/**
* Caret through text mixed-direction text and check the results.
* If the test fails an Error is thrown.
* @exception an Error is thrown if the test fails
*/
public static void testBidiWithNumbers() {
String bidiWithNumbers = "abcאבג123abc";
// visual order for the text:
// abc123<gimel><bet><aleph>abc
int[] carets = { 0, 1, 2, 3, 7, 8, 6, 5, 4, 9, 10, 11, 12 };
TextLayout layout = new TextLayout(bidiWithNumbers, map, frc);
// Caret through TextLayout in both directions and check results.
for (int i = 0; i < carets.length - 1; i++) {
TextHitInfo hit = layout.getNextRightHit(carets[i]);
if (hit.getInsertionIndex() != carets[i + 1]) {
throw new Error("right hit failed within layout");
}
}
if (layout.getNextRightHit(carets[carets.length - 1]) != null) {
throw new Error("right hit failed at end of layout");
}
for (int i = carets.length - 1; i > 0; i--) {
TextHitInfo hit = layout.getNextLeftHit(carets[i]);
if (hit.getInsertionIndex() != carets[i - 1]) {
throw new Error("left hit failed within layout");
}
}
if (layout.getNextLeftHit(carets[0]) != null) {
throw new Error("left hit failed at end of layout");
}
}
Aggregations