use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class BidiConformance method testMethod_createLineBidi1.
private void testMethod_createLineBidi1() {
System.out.println("*** Test createLineBidi() 1");
String str = " ABC 123. " + HebrewABC + " " + NKo123 + ". ABC 123";
int lineStart = str.indexOf('.') + 2;
int lineLimit = str.lastIndexOf('.') + 2;
Bidi bidi = new Bidi(str, FLAGS[0]);
Bidi lineBidi = bidi.createLineBidi(lineStart, lineLimit);
checkResult("getBaseLevel()", bidi.getBaseLevel(), lineBidi.getBaseLevel());
checkResult("getLevelAt(5)", bidi.getLevelAt(lineStart + 5), lineBidi.getLevelAt(5));
}
use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class BidiConformance method testMethod_getRunLevel.
private void testMethod_getRunLevel() {
System.out.println("*** Test getRunLevel()");
String str = "ABC 123";
Bidi bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
try {
if (// runCount - 2 (out of range)
bidi.getRunLevel(-1) != 0 || // runCount - 1
bidi.getRunLevel(0) != 0 || // runCount (out of range)
bidi.getRunLevel(1) != 0 || bidi.getRunLevel(2) != 0) {
// runCount + 1 (out of range)
errorHandling("Incorrect getRunLevel() value(s).");
}
} catch (Exception e) {
errorHandling("getRunLevel() should not throw an exception: " + e);
}
str = "ABC " + HebrewABC + " 123";
bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
try {
if (// runCount - 4 (out of range)
bidi.getRunLevel(-1) != 0 || // runCount - 3
bidi.getRunLevel(0) != 0 || // runCount - 2
bidi.getRunLevel(1) != 1 || // runCount - 1
bidi.getRunLevel(2) != 2 || // runCount (out of range)
bidi.getRunLevel(3) != 0 || bidi.getRunLevel(4) != 0) {
// runCount + 1 (out of range)
errorHandling("Incorrect getRunLevel() value(s).");
}
} catch (Exception e) {
errorHandling("getRunLevel() should not throw an exception: " + e);
}
str = "ABC";
bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
try {
if (// runCount - 2 (out of range)
bidi.getRunLevel(-1) != 0 || // runCount - 1
bidi.getRunLevel(0) != 0 || // runCount (out of range)
bidi.getRunLevel(1) != 0 || bidi.getRunLevel(2) != 0) {
// runCount + 1 (out of range)
errorHandling("Incorrect getRunLevel() value(s).");
}
} catch (Exception e) {
errorHandling("getRunLevel() should not throw an exception: " + e);
}
str = "ABC";
bidi = new Bidi(str, Bidi.DIRECTION_RIGHT_TO_LEFT);
try {
if (// runCount - 2 (out of range)
bidi.getRunLevel(-1) != 1 || // runCount - 1
bidi.getRunLevel(0) != 2 || // runCount (out of range)
bidi.getRunLevel(1) != 1 || bidi.getRunLevel(2) != 1) {
// runCount + 1 (out of range)
errorHandling("Incorrect getRunLevel() value(s).");
}
} catch (Exception e) {
errorHandling("getRunLevel() should not throw an exception: " + e);
}
str = "ABC";
bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
try {
if (// runCount - 2 (out of range)
bidi.getRunLevel(-1) != 0 || // runCount - 1
bidi.getRunLevel(0) != 0 || // runCount (out of range)
bidi.getRunLevel(1) != 0 || bidi.getRunLevel(2) != 0) {
// runCount + 1 (out of range)
errorHandling("Incorrect getRunLevel() value(s).");
}
} catch (Exception e) {
errorHandling("getRunLevel() should not throw an exception: " + e);
}
str = "ABC";
bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
try {
if (// runCount - 2 (out of range)
bidi.getRunLevel(-1) != 0 || // runCount - 1
bidi.getRunLevel(0) != 0 || // runCount (out of range)
bidi.getRunLevel(1) != 0 || bidi.getRunLevel(2) != 0) {
// runCount + 1 (out of range)
errorHandling("Incorrect getRunLevel() value(s).");
}
} catch (Exception e) {
errorHandling("getRunLevel() should not throw an exception: " + e);
}
str = HebrewABC;
bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
try {
if (// runCount - 2 (out of range)
bidi.getRunLevel(-1) != 0 || // runCount - 1
bidi.getRunLevel(0) != 1 || // runCount (out of range)
bidi.getRunLevel(1) != 0 || bidi.getRunLevel(2) != 0) {
// runCount + 1 (out of range)
errorHandling("Incorrect getRunLevel() value(s).");
}
} catch (Exception e) {
errorHandling("getRunLevel() should not throw an exception: " + e);
}
str = HebrewABC;
bidi = new Bidi(str, Bidi.DIRECTION_RIGHT_TO_LEFT);
try {
if (// runCount - 2 (out of range)
bidi.getRunLevel(-1) != 1 || // runCount - 1
bidi.getRunLevel(0) != 1 || // runCount (out of range)
bidi.getRunLevel(1) != 1 || bidi.getRunLevel(2) != 1) {
// runCount + 1 (out of range)
errorHandling("Incorrect getRunLevel() value(s).");
}
} catch (Exception e) {
errorHandling("getRunLevel() should not throw an exception: " + e);
}
str = HebrewABC;
bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
try {
if (// runCount - 2 (out of range)
bidi.getRunLevel(-1) != 1 || // runCount - 1
bidi.getRunLevel(0) != 1 || // runCount (out of range)
bidi.getRunLevel(1) != 1 || bidi.getRunLevel(2) != 1) {
// runCount + 1 (out of range)
errorHandling("Incorrect getRunLevel() value(s).");
}
} catch (Exception e) {
errorHandling("getRunLevel() should not throw an exception: " + e);
}
str = HebrewABC;
bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
try {
if (// runCount - 2 (out of range)
bidi.getRunLevel(-1) != 1 || // runCount - 1
bidi.getRunLevel(0) != 1 || // runCount (out of range)
bidi.getRunLevel(1) != 1 || bidi.getRunLevel(2) != 1) {
// runCount + 1 (out of range)
errorHandling("Incorrect getRunLevel() value(s).");
}
} catch (Exception e) {
errorHandling("getRunLevel() should not throw an exception: " + e);
}
}
use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class AbstractDocument method calculateBidiLevels.
/**
* Calculate the levels array for a range of paragraphs.
*/
private byte[] calculateBidiLevels(int firstPStart, int lastPEnd) {
byte[] levels = new byte[lastPEnd - firstPStart];
int levelsEnd = 0;
Boolean defaultDirection = null;
Object d = getProperty(TextAttribute.RUN_DIRECTION);
if (d instanceof Boolean) {
defaultDirection = (Boolean) d;
}
// levels array and add it to the levels array for the entire span.
for (int o = firstPStart; o < lastPEnd; ) {
Element p = getParagraphElement(o);
int pStart = p.getStartOffset();
int pEnd = p.getEndOffset();
// default run direction for the paragraph. This will be
// null if there is no direction override specified (i.e.
// the direction will be determined from the content).
Boolean direction = defaultDirection;
d = p.getAttributes().getAttribute(TextAttribute.RUN_DIRECTION);
if (d instanceof Boolean) {
direction = (Boolean) d;
}
//System.out.println("updateBidi: paragraph start = " + pStart + " paragraph end = " + pEnd);
// Create a Bidi over this paragraph then get the level
// array.
Segment seg = SegmentCache.getSharedSegment();
try {
getText(pStart, pEnd - pStart, seg);
} catch (BadLocationException e) {
throw new Error("Internal error: " + e.toString());
}
// REMIND(bcb) we should really be using a Segment here.
Bidi bidiAnalyzer;
int bidiflag = Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT;
if (direction != null) {
if (TextAttribute.RUN_DIRECTION_LTR.equals(direction)) {
bidiflag = Bidi.DIRECTION_LEFT_TO_RIGHT;
} else {
bidiflag = Bidi.DIRECTION_RIGHT_TO_LEFT;
}
}
bidiAnalyzer = new Bidi(seg.array, seg.offset, null, 0, seg.count, bidiflag);
BidiUtils.getLevels(bidiAnalyzer, levels, levelsEnd);
levelsEnd += bidiAnalyzer.getLength();
o = p.getEndOffset();
SegmentCache.releaseSharedSegment(seg);
}
// REMIND(bcb) remove this code when debugging is done.
if (levelsEnd != levels.length)
throw new Error("levelsEnd assertion failed.");
return levels;
}
use of java.text.Bidi in project intellij-community by JetBrains.
the class LineLayout method addRunsNoTabs.
private static void addRunsNoTabs(List<BidiRun> runs, char[] text, int start, int end, int flags) {
if (start >= end)
return;
Bidi bidi = new Bidi(text, start, null, 0, end - start, flags);
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)));
}
}
use of java.text.Bidi in project ArsMagica2 by Mithion.
the class AM2FontRenderer method bidiReorder.
/**
* Apply Unicode Bidirectional Algorithm to string and return a new possibly reordered string for visual rendering.
*/
private String bidiReorder(String par1Str) {
if (par1Str != null && Bidi.requiresBidi(par1Str.toCharArray(), 0, par1Str.length())) {
Bidi bidi = new Bidi(par1Str, -2);
byte[] abyte = new byte[bidi.getRunCount()];
String[] astring = new String[abyte.length];
int i;
for (int j = 0; j < abyte.length; ++j) {
int k = bidi.getRunStart(j);
i = bidi.getRunLimit(j);
int l = bidi.getRunLevel(j);
String s1 = par1Str.substring(k, i);
abyte[j] = (byte) l;
astring[j] = s1;
}
String[] astring1 = (String[]) astring.clone();
Bidi.reorderVisually(abyte, 0, astring, 0, abyte.length);
StringBuilder stringbuilder = new StringBuilder();
i = 0;
while (i < astring.length) {
byte b0 = abyte[i];
int i1 = 0;
while (true) {
if (i1 < astring1.length) {
if (!astring1[i1].equals(astring[i])) {
++i1;
continue;
}
b0 = abyte[i1];
}
if ((b0 & 1) == 0) {
stringbuilder.append(astring[i]);
} else {
for (i1 = astring[i].length() - 1; i1 >= 0; --i1) {
char c0 = astring[i].charAt(i1);
if (c0 == 40) {
c0 = 41;
} else if (c0 == 41) {
c0 = 40;
}
stringbuilder.append(c0);
}
}
++i;
break;
}
}
return stringbuilder.toString();
} else {
return par1Str;
}
}
Aggregations