本文整理匯總了Java中java.text.Bidi.getRunCount方法的典型用法代碼示例。如果您正苦於以下問題:Java Bidi.getRunCount方法的具體用法?Java Bidi.getRunCount怎麽用?Java Bidi.getRunCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.text.Bidi
的用法示例。
在下文中一共展示了Bidi.getRunCount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLevels
import java.text.Bidi; //導入方法依賴的package包/類
/**
* Return the level of each character into the levels array starting at start.
* This is a convenience method for clients who prefer to use an explicit levels
* array instead of iterating over the runs.
*
* @param levels the array to receive the character levels
* @param start the starting offset into the the array
* @throws IndexOutOfBoundsException if <code>start</code> is less than 0 or
* <code>start + getLength()</code> is greater than <code>levels.length</code>.
*/
public static void getLevels(Bidi bidi, byte[] levels, int start) {
int limit = start + bidi.getLength();
if (start < 0 || limit > levels.length) {
throw new IndexOutOfBoundsException("levels.length = " + levels.length +
" start: " + start + " limit: " + limit);
}
int runCount = bidi.getRunCount();
int p = start;
for (int i = 0; i < runCount; ++i) {
int rlimit = start + bidi.getRunLimit(i);
byte rlevel = (byte)bidi.getRunLevel(i);
while (p < rlimit) {
levels[p++] = rlevel;
}
}
}
示例2: getLevels
import java.text.Bidi; //導入方法依賴的package包/類
/**
* Return the level of each character into the levels array starting at start.
* This is a convenience method for clients who prefer to use an explicit levels
* array instead of iterating over the runs.
*
* @param levels the array to receive the character levels
* @param start the starting offset into the array
* @throws IndexOutOfBoundsException if {@code start} is less than 0 or
* {@code start + getLength()} is greater than {@code levels.length}.
*/
public static void getLevels(Bidi bidi, byte[] levels, int start) {
int limit = start + bidi.getLength();
if (start < 0 || limit > levels.length) {
throw new IndexOutOfBoundsException("levels.length = " + levels.length +
" start: " + start + " limit: " + limit);
}
int runCount = bidi.getRunCount();
int p = start;
for (int i = 0; i < runCount; ++i) {
int rlimit = start + bidi.getRunLimit(i);
byte rlevel = (byte)bidi.getRunLevel(i);
while (p < rlimit) {
levels[p++] = rlevel;
}
}
}
示例3: testGetRunStart
import java.text.Bidi; //導入方法依賴的package包/類
public void testGetRunStart() {
bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -7,
(byte) -2, (byte) 3 }, 0, 3,
Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
assertEquals(0, bd.getRunStart(0));
assertEquals(1, bd.getRunStart(1));
assertEquals(2, bd.getRunStart(2));
String LTR = "\u0061\u0062";
String RTL = "\u05DC\u05DD";
String newLine = "\n";
String defText = LTR + newLine + RTL + LTR + RTL;
int[][] expectedRuns = { { 0, 3 }, { 3, 5 }, { 5, 7 }, { 7, 9 }, };
Bidi bi = new Bidi(defText, 0);
final int count = bi.getRunCount();
for (int i = 0; i < count; i++) {
assertEquals(expectedRuns[i][0], bi.getRunStart(i));
}
}
示例4: test2
import java.text.Bidi; //導入方法依賴的package包/類
static void test2() {
String str = "If this text is >" + target + "< the test passed.";
int length = str.length();
int start = str.indexOf(target);
int limit = start + target.length();
AttributedString astr = new AttributedString(str);
astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
astr.addAttribute(TextAttribute.BIDI_EMBEDDING,
new Integer(-3),
start,
limit);
Bidi bidi = new Bidi(astr.getIterator());
if (bidi.getRunCount() != 6) { // runs of spaces and angles at embedding bound,s and final period, each get level 1
throw new Error("Bidi embedding processing failed");
}
}
示例5: assertRunArrayEquals
import java.text.Bidi; //導入方法依賴的package包/類
public static void assertRunArrayEquals(int[][] expected, Bidi bidi) {
assertEquals("different length", expected.length, bidi.getRunCount());
FORRUN: for (int i = 0; i < bidi.getRunCount(); i++) {
int[] butWas = new int[] { bidi.getRunStart(i),
bidi.getRunLimit(i), bidi.getRunLevel(i) };
for (int j = 0; j < expected.length; j++) {
if (expected[j][0] == butWas[0] && expected[j][1] == butWas[1]
&& expected[j][2] == butWas[2]) {
continue FORRUN;
}
}
fail("expected [" + i + "] " + " start: " + butWas[0] + " limit: "
+ butWas[1] + " level: " + butWas[2]);
}
}
示例6: test1
import java.text.Bidi; //導入方法依賴的package包/類
static void test1() {
String str = "If this text is >" + target + "< the test passed.";
int start = str.indexOf(target);
int limit = start + target.length();
AttributedString astr = new AttributedString(str);
astr.addAttribute(TextAttribute.BIDI_EMBEDDING,
new Integer(-1),
start,
limit);
Bidi bidi = new Bidi(astr.getIterator());
byte[] embs = new byte[str.length() + 3];
for (int i = start + 1; i < limit + 1; ++i) {
embs[i] = -1;
}
Bidi bidi2 = new Bidi(str.toCharArray(), 0, embs, 1, str.length(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
if (bidi.getRunCount() != 3 || bidi2.getRunCount() != 3) {
throw new Error("Bidi run count incorrect");
}
}
示例7: testGetRuns
import java.text.Bidi; //導入方法依賴的package包/類
public void testGetRuns() {
//Regression test for Harmony-1028
String LTR = "\u0061\u0062";
String RTL = "\u05DC\u05DD";
String newLine = "\n";
String defText = LTR + newLine + RTL + LTR + RTL;
int[][] expectedRuns = {
{0, 3},
{3, 5},
{5, 7},
{7, 9},
};
Bidi bi = new Bidi(defText, 0);
final int count = bi.getRunCount();
for (int i = 0; i < count; i++) {
assertEquals(expectedRuns[i][0], bi.getRunStart(i));
assertEquals(expectedRuns[i][1], bi.getRunLimit(i));
}
}
示例8: layoutBidi
import java.text.Bidi; //導入方法依賴的package包/類
private int layoutBidi(String str) {
final char[] text = str.toCharArray();
/* Avoid performing full bidirectional analysis if text has no "strong" right-to-left characters */
if (!Bidi.requiresBidi(text, 0, text.length))
return layoutFont(text, 0, text.length, Font.LAYOUT_LEFT_TO_RIGHT);
final Bidi bidi = new Bidi(text, 0, null, 0, text.length, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
/* If text is entirely right-to-left, then just lay it out */
if (bidi.isRightToLeft())
return layoutFont(text, 0, text.length, Font.LAYOUT_RIGHT_TO_LEFT);
/* Otherwise text has a mixture of LTR and RLT, and it requires full bidirectional analysis */
final int runCount = bidi.getRunCount();
final byte[] levels = new byte[runCount];
final Integer[] ranges = new Integer[runCount];
for (int i = 0; i < runCount; i++) {
levels[i] = (byte) bidi.getRunLevel(i);
ranges[i] = i;
}
Bidi.reorderVisually(levels, 0, ranges, 0, runCount);
int width = 0;
for (int i = 0; i < runCount; i++) {
final int index = ranges[i];
width += layoutFont(text, bidi.getRunStart(index), bidi.getRunLimit(index), (bidi.getRunLevel(index) & 1));
}
return width;
}
示例9: test2
import java.text.Bidi; //導入方法依賴的package包/類
static void test2() {
String target = "BACK WARDS";
String str = "If this text is >" + target + "< the test passed.";
int length = str.length();
int start = str.indexOf(target);
int limit = start + target.length();
System.out.println("start: " + start + " limit: " + limit);
AttributedString astr = new AttributedString(str);
astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
astr.addAttribute(TextAttribute.BIDI_EMBEDDING,
new Integer(-3),
start,
limit);
Bidi bidi = new Bidi(astr.getIterator());
for (int i = 0; i < bidi.getRunCount(); ++i) {
System.out.println("run " + i +
" from " + bidi.getRunStart(i) +
" to " + bidi.getRunLimit(i) +
" at level " + bidi.getRunLevel(i));
}
System.out.println(bidi + "\n");
if (bidi.getRunCount() != 6) { // runs of spaces and angles at embedding bound,s and final period, each get level 1
throw new Error("Bidi embedding processing failed");
} else {
System.out.println("test2() passed.\n");
}
}
示例10: main
import java.text.Bidi; //導入方法依賴的package包/類
public static void main(String[] args) {
boolean err = false;
String string = "\u05D0\u05D1\u05D2";
Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);
int result = bidi.getRunCount();
if (result != 1) {
System.err.println("Incorrect run count: " + result);
err = true;
}
result = bidi.getRunStart(0);
if (result != 0) {
System.err.println("Incorrect run start: " + result);
err = true;
}
result = bidi.getRunLimit(0);
if (result != 3) {
System.err.println("Incorrect run limit: " + result);
err = true;
}
result = bidi.getRunLevel(0);
if (result != 1) {
System.err.println("Incorrect run level: " + result);
err = true;
}
if (err) {
throw new RuntimeException("Failed.");
}
}
示例11: testBidi
import java.text.Bidi; //導入方法依賴的package包/類
void testBidi(String string, int rtlstart, int rtllength) {
Bidi bidi = new Bidi(string, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
for (int i = 0; i < bidi.getRunCount(); ++i) {
if ((bidi.getRunLevel(i) & 1) != 0) {
if (bidi.getRunStart(i) != rtlstart ||
bidi.getRunLimit(i) != rtlstart + rtllength) {
throw new RuntimeException("first rtl run didn't match " + rtlstart + ", " + rtllength);
}
break;
}
}
}
示例12: addRunsNoTabs
import java.text.Bidi; //導入方法依賴的package包/類
private static void addRunsNoTabs(List<BidiRun> runs, char[] text, int start, int end) {
if (start >= end) return;
Bidi bidi = new Bidi(text, start, null, 0, end - start, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
int runCount = bidi.getRunCount();
for (int i = 0; i < runCount; i++) {
addOrMergeRun(runs, new BidiRun((byte)bidi.getRunLevel(i), start + bidi.getRunStart(i), start + bidi.getRunLimit(i)));
}
}
示例13: bidiParseParagraph
import java.text.Bidi; //導入方法依賴的package包/類
private void bidiParseParagraph(final List<Element> added, final Element par,
final Segment text) {
final int parStart = par.getStartOffset();
final int parEnd = par.getEndOffset();
final int parLen = parEnd - parStart;
try {
content.getChars(parStart, parLen, text);
} catch (final BadLocationException e) { }
Bidi bidi = new Bidi(text.array, text.offset, null, 0, text.count,
getDefaultDirection(par));
final int runCount = bidi.getRunCount();
for (int i = 0; i < runCount; i++) {
int level = bidi.getRunLevel(i);
if (i == 0 && added.size() > 0) {
Element prevBidi = added.get(added.size() - 1);
if (getBidiLevel(prevBidi) == level) {
added.remove(added.size() - 1);
added.add(new BidiElement(prevBidi.getAttributes(),
prevBidi.getStartOffset(),
parStart + bidi.getRunLimit(i)));
continue;
}
}
added.add(
new BidiElement(context.addAttribute(context.getEmptySet(),
StyleConstants.BidiLevel,
new Integer(level)),
parStart + bidi.getRunStart(i),
parStart + bidi.getRunLimit(i)));
}
}
示例14: test1
import java.text.Bidi; //導入方法依賴的package包/類
static void test1() {
String target = "BACK WARDS";
String str = "If this text is >" + target + "< the test passed.";
int start = str.indexOf(target);
int limit = start + target.length();
System.out.println("start: " + start + " limit: " + limit);
AttributedString astr = new AttributedString(str);
astr.addAttribute(TextAttribute.BIDI_EMBEDDING,
new Integer(-1),
start,
limit);
Bidi bidi = new Bidi(astr.getIterator());
for (int i = 0; i < bidi.getRunCount(); ++i) {
System.out.println("run " + i +
" from " + bidi.getRunStart(i) +
" to " + bidi.getRunLimit(i) +
" at level " + bidi.getRunLevel(i));
}
System.out.println(bidi);
byte[] embs = new byte[str.length() + 3];
for (int i = start + 1; i < limit + 1; ++i) {
embs[i] = -1;
}
Bidi bidi2 = new Bidi(str.toCharArray(), 0, embs, 1, str.length(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
for (int i = 0; i < bidi2.getRunCount(); ++i) {
System.out.println("run " + i +
" from " + bidi2.getRunStart(i) +
" to " + bidi2.getRunLimit(i) +
" at level " + bidi2.getRunLevel(i));
}
System.out.println(bidi2 + "\n");
if (bidi.getRunCount() != 3 || bidi2.getRunCount() != 3) {
throw new Error("Bidi run count incorrect");
} else {
System.out.println("test1() passed.\n");
}
}
示例15: testEachMethod
import java.text.Bidi; //導入方法依賴的package包/類
private void testEachMethod(Bidi bidi,
String text,
String expectedLevels,
boolean expectedBaseIsLTR,
boolean expectedIsLTR,
boolean expectedIsRTL
) {
/* Test baseIsLeftToRight() */
boolean actualBoolean = bidi.baseIsLeftToRight();
checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);
/* Test getBaseLevel() */
int expectedInt = (expectedBaseIsLTR) ? 0 : 1;
int actualInt = bidi.getBaseLevel();
checkResult("getBaseLevel()", expectedInt, actualInt);
/* Test getLength() */
expectedInt = text.length();
actualInt = bidi.getLength();
checkResult("getLength()", expectedInt, actualInt);
/* Test getLevelAt() */
sb.setLength(0);
for (int i = 0; i < text.length(); i++) {
sb.append(bidi.getLevelAt(i));
}
checkResult("getLevelAt()", expectedLevels, sb.toString());
/* Test getRunCount() */
expectedInt = getRunCount(expectedLevels);
actualInt = bidi.getRunCount();
checkResult("getRunCount()", expectedInt, actualInt);
/* Test getRunLevel(), getRunLimit() and getRunStart() */
if (expectedInt == actualInt) {
int runCount = expectedInt;
int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);
int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);
int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);
int[] actualRunLevels = new int[runCount];
int[] actualRunLimits = new int[runCount];
int[] actualRunStarts = new int[runCount];
for (int k = 0; k < runCount; k++) {
actualRunLevels[k] = bidi.getRunLevel(k);
actualRunLimits[k] = bidi.getRunLimit(k);
actualRunStarts[k] = bidi.getRunStart(k);
}
checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);
checkResult("getRunStart()", expectedRunStarts, actualRunStarts);
checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);
}
/* Test isLeftToRight() */
boolean expectedBoolean = expectedIsLTR;
actualBoolean = bidi.isLeftToRight();
checkResult("isLeftToRight()", expectedBoolean, actualBoolean);
/* Test isMixed() */
expectedBoolean = !(expectedIsLTR || expectedIsRTL);
actualBoolean = bidi.isMixed();
checkResult("isMixed()", expectedBoolean, actualBoolean);
/* Test isRightToLeft() */
expectedBoolean = expectedIsRTL;
actualBoolean = bidi.isRightToLeft();
checkResult("isRightToLeft()", expectedBoolean, actualBoolean);
}