本文整理匯總了Java中java.text.Bidi.isLeftToRight方法的典型用法代碼示例。如果您正苦於以下問題:Java Bidi.isLeftToRight方法的具體用法?Java Bidi.isLeftToRight怎麽用?Java Bidi.isLeftToRight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.text.Bidi
的用法示例。
在下文中一共展示了Bidi.isLeftToRight方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: standardCreateTextLine
import java.text.Bidi; //導入方法依賴的package包/類
/**
* Create a TextLine from the text. chars is just the text in the iterator.
*/
public static TextLine standardCreateTextLine(FontRenderContext frc,
AttributedCharacterIterator text,
char[] chars,
float[] baselineOffsets) {
StyledParagraph styledParagraph = new StyledParagraph(text, chars);
Bidi bidi = new Bidi(text);
if (bidi.isLeftToRight()) {
bidi = null;
}
int layoutFlags = 0; // no extra info yet, bidi determines run and line direction
TextLabelFactory factory = new TextLabelFactory(frc, chars, bidi, layoutFlags);
boolean isDirectionLTR = true;
if (bidi != null) {
isDirectionLTR = bidi.baseIsLeftToRight();
}
return createLineFromText(chars, styledParagraph, factory, isDirectionLTR, baselineOffsets);
}
示例2: bidiUpdateProperty
import java.text.Bidi; //導入方法依賴的package包/類
private boolean bidiUpdateProperty(final int offset, final Segment text) {
final boolean hasBidiInfo = hasBidiInfo();
if (!hasBidiInfo && TextUtils.isLTR(getDefaultDirection(offset))
&& !Bidi.requiresBidi(text.array, text.offset,
text.offset + text.count)) {
return false;
}
final Bidi bidi = new Bidi(text.array, text.offset, null, 0, text.count,
getDefaultDirection(offset));
if (hasBidiInfo && !bidi.isMixed()
&& isLeftToRight(offset) == bidi.isLeftToRight()) {
return false;
}
if (!hasBidiInfo) {
putProperty(StringConstants.BIDI_PROPERTY, Boolean.TRUE);
}
return true;
}
示例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: visualToLogical
import java.text.Bidi; //導入方法依賴的package包/類
/**
* Handles the LTR and RTL direction of the given words. The whole implementation stands and falls with the given
* word. If the word is a full line, the results will be the best. If the word contains of single words or
* characters, the order of the characters in a word or words in a line may wrong, due to RTL and LTR marks and
* characters!
*
* Based on http://www.nesterovsky-bros.com/weblog/2013/07/28/VisualToLogicalConversionInJava.aspx
*
* @param text The word that shall be processed
* @return new word with the correct direction of the containing characters
*/
public static String visualToLogical(String text)
{
if (!CharUtils.isBlank(text))
{
Bidi bidi = new Bidi(text, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
if (!bidi.isLeftToRight())
{
// collect individual bidi information
int runCount = bidi.getRunCount();
byte[] levels = new byte[runCount];
Integer[] runs = new Integer[runCount];
for (int i = 0; i < runCount; i++)
{
levels[i] = (byte) bidi.getRunLevel(i);
runs[i] = i;
}
// reorder individual parts based on their levels
Bidi.reorderVisually(levels, 0, runs, 0, runCount);
// collect the parts based on the direction within the run
StringBuilder result = new StringBuilder();
for (int i = 0; i < runCount; i++)
{
int index = runs[i];
int start = bidi.getRunStart(index);
int end = bidi.getRunLimit(index);
int level = levels[index];
if ((level & 1) != 0)
{
while (--end >= start)
{
char character = text.charAt(end);
if (Character.isMirrored(text.codePointAt(end))
&& MIRRORING_CHAR_MAP.containsKey(character))
{
result.append(MIRRORING_CHAR_MAP.get(character));
}
else
{
result.append(character);
}
}
}
else
{
result.append(text, start, end);
}
}
return result.toString();
}
}
return text;
}