}
}
// We Just want it to do BIDI for us...
// In 1.4 we might be able to use the BIDI class...
TextLayout tl = new TextLayout(as.getIterator(), frc);
int[] charIndices = new int[numChars];
int[] charLevels = new int[numChars];
int runStart = 0;
int currBiDi = tl.getCharacterLevel(0);
charIndices[0] = 0;
charLevels [0] = currBiDi;
int maxBiDi = currBiDi;
for (int i = 1; i < numChars; i++) {
int newBiDi = tl.getCharacterLevel(i);
charIndices[i] = i;
charLevels [i] = newBiDi;
if (newBiDi != currBiDi) {
as.addAttribute
(GVTAttributedCharacterIterator.TextAttribute.BIDI_LEVEL,
new Integer(currBiDi), runStart, i);
runStart = i;
currBiDi = newBiDi;
if (newBiDi > maxBiDi) maxBiDi = newBiDi;
}
}
as.addAttribute
(GVTAttributedCharacterIterator.TextAttribute.BIDI_LEVEL,
new Integer(currBiDi), runStart, numChars);
if ((runStart == 0) && (currBiDi==0)) {
// This avoids all the mucking about we need to do when
// bidi is actually performed for cases where it
// is not actually needed.
this.aci = this.reorderedACI = as.getIterator();
newCharOrder = new int[numChars];
for (int i=0; i<numChars; i++)
newCharOrder[i] = chunkStart+i;
return;
}
this.aci = as.getIterator();
// work out the new character order
newCharOrder = doBidiReorder(charIndices, charLevels,
numChars, maxBiDi);
// construct the string in the new order
StringBuffer reorderedString = new StringBuffer();
char c;
for (int i = 0; i < numChars; i++) {
c = this.aci.setIndex(newCharOrder[i]);
// check for mirrored char
int bidiLevel = tl.getCharacterLevel(newCharOrder[i]);
if ((bidiLevel & 0x01) != 0) {
// bidi level is odd so writing dir is right to left
// So get the mirror version of the char if there
// is one.
c = (char)mirrorChar(c);