本文整理匯總了Java中java.text.Bidi.isRightToLeft方法的典型用法代碼示例。如果您正苦於以下問題:Java Bidi.isRightToLeft方法的具體用法?Java Bidi.isRightToLeft怎麽用?Java Bidi.isRightToLeft使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.text.Bidi
的用法示例。
在下文中一共展示了Bidi.isRightToLeft方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: testBidi
import java.text.Bidi; //導入方法依賴的package包/類
void testBidi(String string, boolean directionIsRTL) {
Bidi bidi = new Bidi(string, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
if (bidi.isMixed()) {
throw new RuntimeException("bidi is mixed");
}
if (bidi.isRightToLeft() != directionIsRTL) {
throw new RuntimeException("bidi is not " + (directionIsRTL ? "rtl" : "ltr"));
}
}
示例3: 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);
}
示例4: layoutBidiString
import java.text.Bidi; //導入方法依賴的package包/類
/**
* Split a string into contiguous LTR or RTL sections by applying the Unicode Bidirectional Algorithm. Calls layoutString()
* for each contiguous run to perform further analysis.
*
* @param glyphList will hold all new Glyph objects allocated by layoutFont()
* @param text the string to lay out
* @param start the offset into text at which to start the layout
* @param limit the (offset + length) at which to stop performing the layout
* @return the total advance (horizontal distance) of this string
*/
private int layoutBidiString(List<Glyph> glyphList, char text[], int start, int limit, ColorCode colors[])
{
int advance = 0;
/* Avoid performing full bidirectional analysis if text has no "strong" right-to-left characters */
if (Bidi.requiresBidi(text, start, limit))
{
/* Note that while requiresBidi() uses start/limit the Bidi constructor uses start/length */
Bidi bidi = new Bidi(text, start, null, 0, limit - start, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
/* If text is entirely right-to-left, then insert an EntryText node for the entire string */
if (bidi.isRightToLeft())
{
return layoutStyle(glyphList, text, start, limit, Font.LAYOUT_RIGHT_TO_LEFT, advance, colors);
}
/* Otherwise text has a mixture of LTR and RLT, and it requires full bidirectional analysis */
else
{
int runCount = bidi.getRunCount();
byte levels[] = new byte[runCount];
Integer ranges[] = new Integer[runCount];
/* Reorder contiguous runs of text into their display order from left to right */
for (int index = 0; index < runCount; index++)
{
levels[index] = (byte) bidi.getRunLevel(index);
ranges[index] = new Integer(index);
}
Bidi.reorderVisually(levels, 0, ranges, 0, runCount);
/*
* Every GlyphVector must be created on a contiguous run of left-to-right or right-to-left text. Keep track of
* the horizontal advance between each run of text, so that the glyphs in each run can be assigned a position relative
* to the start of the entire string and not just relative to that run.
*/
for (int visualIndex = 0; visualIndex < runCount; visualIndex++)
{
int logicalIndex = ranges[visualIndex];
/* An odd numbered level indicates right-to-left ordering */
int layoutFlag = (bidi.getRunLevel(logicalIndex) & 1) == 1 ? Font.LAYOUT_RIGHT_TO_LEFT : Font.LAYOUT_LEFT_TO_RIGHT;
advance = layoutStyle(glyphList, text, start + bidi.getRunStart(logicalIndex), start + bidi.getRunLimit(logicalIndex),
layoutFlag, advance, colors);
}
}
return advance;
}
/* If text is entirely left-to-right, then insert an EntryText node for the entire string */
else
{
return layoutStyle(glyphList, text, start, limit, Font.LAYOUT_LEFT_TO_RIGHT, advance, colors);
}
}
示例5: layoutBidiString
import java.text.Bidi; //導入方法依賴的package包/類
/**
* Split a string into contiguous LTR or RTL sections by applying the Unicode Bidirectional Algorithm. Calls layoutString()
* for each contiguous run to perform further analysis.
*
* @param glyphList will hold all new Glyph objects allocated by layoutFont()
* @param text the string to lay out
* @param start the offset into text at which to start the layout
* @param limit the (offset + length) at which to stop performing the layout
* @return the total advance (horizontal distance) of this string
*/
private int layoutBidiString(List<Glyph> glyphList, char text[], int start, int limit, ColorCode colors[]) {
int advance = 0;
/* Avoid performing full bidirectional analysis if text has no "strong" right-to-left characters */
if (Bidi.requiresBidi(text, start, limit)) {
/* Note that while requiresBidi() uses start/limit the Bidi constructor uses start/length */
Bidi bidi = new Bidi(text, start, null, 0, limit - start, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
/* If text is entirely right-to-left, then insert an EntryText node for the entire string */
if (bidi.isRightToLeft()) {
return layoutStyle(glyphList, text, start, limit, Font.LAYOUT_RIGHT_TO_LEFT, advance, colors);
}
/* Otherwise text has a mixture of LTR and RLT, and it requires full bidirectional analysis */
else {
int runCount = bidi.getRunCount();
byte levels[] = new byte[runCount];
Integer ranges[] = new Integer[runCount];
/* Reorder contiguous runs of text into their display order from left to right */
for (int index = 0; index < runCount; index++) {
levels[index] = (byte) bidi.getRunLevel(index);
ranges[index] = new Integer(index);
}
Bidi.reorderVisually(levels, 0, ranges, 0, runCount);
/*
* Every GlyphVector must be created on a contiguous run of left-to-right or right-to-left text. Keep track of
* the horizontal advance between each run of text, so that the glyphs in each run can be assigned a position relative
* to the start of the entire string and not just relative to that run.
*/
for (int visualIndex = 0; visualIndex < runCount; visualIndex++) {
int logicalIndex = ranges[visualIndex];
/* An odd numbered level indicates right-to-left ordering */
int layoutFlag = (bidi.getRunLevel(logicalIndex) & 1) == 1 ? Font.LAYOUT_RIGHT_TO_LEFT : Font.LAYOUT_LEFT_TO_RIGHT;
advance = layoutStyle(glyphList, text, start + bidi.getRunStart(logicalIndex), start + bidi.getRunLimit(logicalIndex),
layoutFlag, advance, colors);
}
}
return advance;
}
/* If text is entirely left-to-right, then insert an EntryText node for the entire string */
else {
return layoutStyle(glyphList, text, start, limit, Font.LAYOUT_LEFT_TO_RIGHT, advance, colors);
}
}