use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class BidiConformance method testMethod_requiresBidi.
private void testMethod_requiresBidi() {
System.out.println("*** Test requiresBidi()");
String paragraph;
char[] text;
Bidi bidi;
for (int textNo = 0; textNo < data4Constructor2.length; textNo++) {
paragraph = data4Constructor2[textNo][0];
text = paragraph.toCharArray();
boolean rBidi = Bidi.requiresBidi(text, 0, text.length);
if (rBidi != requiresBidi4Constructor2[textNo]) {
error = true;
System.err.println("Unexpected requiresBidi() value" + " for requiresBidi(\"" + paragraph + "\", " + 0 + ", " + text.length + ")." + "\n Expected: " + requiresBidi4Constructor2[textNo] + "\n Got : " + rBidi);
} else if (verbose) {
System.out.println(" Okay : requiresBidi() for" + " requiresBidi(\"" + paragraph + "\", " + 0 + ", " + text.length + ") Got: " + rBidi);
}
}
char[] txt = { 'A', 'B', 'C', 'D', 'E' };
int textLength = txt.length;
try {
Bidi.requiresBidi(txt, -1, textLength);
errorHandling("requiresBidi() should throw an IAE" + " when start is -1(too small).");
} catch (IllegalArgumentException e) {
} catch (ArrayIndexOutOfBoundsException e) {
errorHandling("requiresBidi() should not throw an AIOoBE " + "but an IAE when start is -1(too small).");
}
try {
Bidi.requiresBidi(txt, textLength, textLength);
} catch (Exception e) {
errorHandling("requiresBidi() should not throw an exception " + "when start is textLength.");
}
try {
Bidi.requiresBidi(txt, textLength + 1, textLength);
errorHandling("requiresBidi() should throw an IAE" + " when start is textLength+1(too large).");
} catch (IllegalArgumentException e) {
}
try {
Bidi.requiresBidi(txt, 0, -1);
errorHandling("requiresBidi() should throw an IAE" + " when limit is -1(too small).");
} catch (IllegalArgumentException e) {
}
try {
Bidi.requiresBidi(txt, 0, textLength + 1);
errorHandling("requiresBidi() should throw an IAE" + " when limit is textLength+1(too large).");
} catch (IllegalArgumentException e) {
} catch (ArrayIndexOutOfBoundsException e) {
errorHandling("requiresBidi() should not throw an AIOoBE " + "but an IAE when limit is textLength+1(too large).");
}
}
use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class TextLine method createLineFromText.
/**
* Create a TextLine from the Font and character data over the
* range. The range is relative to both the StyledParagraph and the
* character array.
*/
public static TextLine createLineFromText(char[] chars, StyledParagraph styledParagraph, TextLabelFactory factory, boolean isDirectionLTR, float[] baselineOffsets) {
factory.setLineContext(0, chars.length);
Bidi lineBidi = factory.getLineBidi();
int[] charsLtoV = null;
byte[] levels = null;
if (lineBidi != null) {
levels = BidiUtils.getLevels(lineBidi);
int[] charsVtoL = BidiUtils.createVisualToLogicalMap(levels);
charsLtoV = BidiUtils.createInverseMap(charsVtoL);
}
TextLineComponent[] components = getComponents(styledParagraph, chars, 0, chars.length, charsLtoV, levels, factory);
return new TextLine(factory.getFontRenderContext(), components, baselineOffsets, chars, 0, chars.length, charsLtoV, levels, isDirectionLTR);
}
use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class TextMeasurer method deleteChar.
/**
* Updates the <code>TextMeasurer</code> after a single character has
* been deleted
* from the paragraph currently represented by this
* <code>TextMeasurer</code>. After this call, this
* <code>TextMeasurer</code> is equivalent to a new <code>TextMeasurer</code>
* created from the text; however, it will usually be more efficient
* to update an existing <code>TextMeasurer</code> than to create a new one
* from scratch.
*
* @param newParagraph the text of the paragraph after performing
* the deletion. Cannot be null.
* @param deletePos the position in the text where the character was removed.
* Must not be less than
* the start of <code>newParagraph</code>, and must not be greater than the
* end of <code>newParagraph</code>.
* @throws IndexOutOfBoundsException if <code>deletePos</code> is
* less than the start of <code>newParagraph</code> or greater
* than the end of <code>newParagraph</code>
* @throws NullPointerException if <code>newParagraph</code> is
* <code>null</code>
*/
public void deleteChar(AttributedCharacterIterator newParagraph, int deletePos) {
fStart = newParagraph.getBeginIndex();
int end = newParagraph.getEndIndex();
if (end - fStart != fChars.length - 1) {
initAll(newParagraph);
}
char[] newChars = new char[end - fStart];
int changedIndex = deletePos - fStart;
System.arraycopy(fChars, 0, newChars, 0, deletePos - fStart);
System.arraycopy(fChars, changedIndex + 1, newChars, changedIndex, end - deletePos);
fChars = newChars;
if (fBidi != null) {
fBidi = new Bidi(newParagraph);
if (fBidi.isLeftToRight()) {
fBidi = null;
}
}
fParagraph = StyledParagraph.deleteChar(newParagraph, fChars, deletePos, fParagraph);
invalidateComponents();
}
use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class TextMeasurer method insertChar.
/**
* Updates the <code>TextMeasurer</code> after a single character has
* been inserted
* into the paragraph currently represented by this
* <code>TextMeasurer</code>. After this call, this
* <code>TextMeasurer</code> is equivalent to a new
* <code>TextMeasurer</code> created from the text; however, it will
* usually be more efficient to update an existing
* <code>TextMeasurer</code> than to create a new one from scratch.
*
* @param newParagraph the text of the paragraph after performing
* the insertion. Cannot be null.
* @param insertPos the position in the text where the character was
* inserted. Must not be less than the start of
* <code>newParagraph</code>, and must be less than the end of
* <code>newParagraph</code>.
* @throws IndexOutOfBoundsException if <code>insertPos</code> is less
* than the start of <code>newParagraph</code> or greater than
* or equal to the end of <code>newParagraph</code>
* @throws NullPointerException if <code>newParagraph</code> is
* <code>null</code>
*/
public void insertChar(AttributedCharacterIterator newParagraph, int insertPos) {
if (collectStats) {
printStats();
}
if (wantStats) {
collectStats = true;
}
fStart = newParagraph.getBeginIndex();
int end = newParagraph.getEndIndex();
if (end - fStart != fChars.length + 1) {
initAll(newParagraph);
}
char[] newChars = new char[end - fStart];
int newCharIndex = insertPos - fStart;
System.arraycopy(fChars, 0, newChars, 0, newCharIndex);
char newChar = newParagraph.setIndex(insertPos);
newChars[newCharIndex] = newChar;
System.arraycopy(fChars, newCharIndex, newChars, newCharIndex + 1, end - insertPos - 1);
fChars = newChars;
if (fBidi != null || Bidi.requiresBidi(newChars, newCharIndex, newCharIndex + 1) || newParagraph.getAttribute(TextAttribute.BIDI_EMBEDDING) != null) {
fBidi = new Bidi(newParagraph);
if (fBidi.isLeftToRight()) {
fBidi = null;
}
}
fParagraph = StyledParagraph.insertChar(newParagraph, fChars, insertPos, fParagraph);
invalidateComponents();
}
use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class TextMeasurer method makeTextLineOnRange.
private TextLine makeTextLineOnRange(int startPos, int limitPos) {
int[] charsLtoV = null;
byte[] charLevels = null;
if (fBidi != null) {
Bidi lineBidi = fBidi.createLineBidi(startPos, limitPos);
charLevels = BidiUtils.getLevels(lineBidi);
int[] charsVtoL = BidiUtils.createVisualToLogicalMap(charLevels);
charsLtoV = BidiUtils.createInverseMap(charsVtoL);
}
TextLineComponent[] components = makeComponentsOnRange(startPos, limitPos);
return new TextLine(fFrc, components, fBaselineOffsets, fChars, startPos, limitPos, charsLtoV, charLevels, fIsDirectionLTR);
}
Aggregations