Index: src/main/java/java/text/Bidi.java =================================================================== --- src/main/java/java/text/Bidi.java (revision 430780) +++ src/main/java/java/text/Bidi.java (working copy) @@ -18,6 +18,8 @@ import java.util.Arrays; import java.util.LinkedList; +import java.awt.font.TextAttribute; +import java.awt.font.NumericShaper; import org.apache.harmony.text.BidiRun; import org.apache.harmony.text.BidiWrapper; @@ -91,11 +93,65 @@ public Bidi(AttributedCharacterIterator paragraph) { if (paragraph == null) { throw new IllegalArgumentException("paragraph is null"); - /* - * TODO: dependency on java.awt.font.TextAttribute and - * java.awt.font.NumericShaper which is not implemented yet. - */ } + + int begin = paragraph.getBeginIndex(); + int end = paragraph.getEndIndex(); + int length = end - begin; + char text[] = new char[length+1]; // One more char for AttributedCharacterIterator.DONE + + if (length != 0) { + text[0] = paragraph.first(); + } else { + paragraph.first(); + } + + // First check the RUN_DIRECTION attribute. + int flags = DIRECTION_DEFAULT_LEFT_TO_RIGHT; + Object direction = paragraph.getAttribute(TextAttribute.RUN_DIRECTION); + if (direction != null && direction instanceof Boolean) { + if (direction.equals(TextAttribute.RUN_DIRECTION_LTR)) { + flags = DIRECTION_LEFT_TO_RIGHT; + } else { + flags = DIRECTION_RIGHT_TO_LEFT; + } + } + + // Retrieve the text and gather BIDI_EMBEDDINGS + byte embeddings[] = null; + for ( + int textLimit = 1, i = 1; + i < length; + textLimit = paragraph.getRunLimit(TextAttribute.BIDI_EMBEDDING) - begin + 1 + ) { + Object embedding = paragraph.getAttribute(TextAttribute.BIDI_EMBEDDING); + if (embedding != null && embedding instanceof Integer) { + int embLevel = ((Integer) embedding).intValue(); + + if (embeddings == null) { + embeddings = new byte[length]; + } + + for (; i < textLimit; i++) { + text[i] = paragraph.next(); + embeddings[i-1] = (byte) embLevel; + } + } else { + for (; i < textLimit; i++) { + text[i] = paragraph.next(); + } + } + } + + // Apply NumericShaper to the text + Object numericShaper = paragraph.getAttribute(TextAttribute.NUMERIC_SHAPING); + if (numericShaper != null && numericShaper instanceof NumericShaper) { + ((NumericShaper) numericShaper).shape(text, 0, length); + } + + long pBidi = createUBiDi(text, 0, embeddings, 0, length, flags); + readBidiInfo(pBidi); + BidiWrapper.ubidi_close(pBidi); } /**