harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r438844 - in /incubator/harmony/enhanced/classlib/trunk/modules/text: META-INF/MANIFEST.MF src/main/java/java/text/Bidi.java src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java
Date Thu, 31 Aug 2006 08:54:24 GMT
Author: hindessm
Date: Thu Aug 31 01:54:23 2006
New Revision: 438844

URL: http://svn.apache.org/viewvc?rev=438844&view=rev
Log:
Applied patch from "[#HARMONY-650] [classlib][text]unexpected NPE for
object constructed by java.text.Bidi(AttributedCharacterIterator)".

And updated MANIFEST to reflect new dependency.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/text/META-INF/MANIFEST.MF
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/META-INF/MANIFEST.MF?rev=438844&r1=438843&r2=438844&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/META-INF/MANIFEST.MF (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/META-INF/MANIFEST.MF Thu Aug 31
01:54:23 2006
@@ -12,6 +12,7 @@
  java.net,
  java.security,
  java.util,
+ java.awt.font,
  org.apache.harmony.luni.util,
  tests.support;resolution:=optional;hy_usage=test,
  tests.util;resolution:=optional;hy_usage=test

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java?rev=438844&r1=438843&r2=438844&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java
Thu Aug 31 01:54:23 2006
@@ -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);
     }
 
 	/**
@@ -231,14 +287,18 @@
 
 		int runCount = BidiWrapper.ubidi_countRuns(pBidi);
 		if (runCount == 0) {
-			runCount = 1;
-			runs = new BidiRun[runCount];
-			runs[0] = new BidiRun(0, 0, baseLevel);
+            unidirectional = true;
+            runs = null;
 		} else if (runCount < 0) {
-			runCount = 0;
 			runs = null;
 		} else {
 			runs = BidiWrapper.ubidi_getRuns(pBidi);
+
+            // Simplified case for one run which has the base level
+            if (runCount == 1 && runs[0].getLevel() == baseLevel) {
+                unidirectional = true;
+                runs = null;
+            }
 		}
 
 		direction = BidiWrapper.ubidi_getDirection(pBidi);
@@ -254,6 +314,8 @@
 
 	private int direction;
 
+    private boolean unidirectional;
+
 	/**
 	 * Return whether the base level is from left to right.
 	 * 
@@ -320,7 +382,7 @@
 	 * 
 	 * @param offset
 	 *            the offset of the character.
-	 * @return the int value of the evel.
+	 * @return the int value of the level.
 	 */
 	public int getLevelAt(int offset) {
 		try {
@@ -336,7 +398,7 @@
 	 * @return the int value of runs, at least 1.
 	 */
 	public int getRunCount() {
-		return runs.length;
+		return unidirectional ? 1 : runs.length;
 	}
 
 	/**
@@ -347,7 +409,7 @@
 	 * @return the level of the run.
 	 */
 	public int getRunLevel(int run) {
-		return runs[run].getLevel();
+		return unidirectional ? baseLevel : runs[run].getLevel();
 	}
 
 	/**
@@ -358,7 +420,7 @@
 	 * @return the limit offset of the run.
 	 */
 	public int getRunLimit(int run) {
-		return runs[run].getLimit();
+		return unidirectional ? length : runs[run].getLimit();
 	}
 
 	/**
@@ -369,7 +431,7 @@
 	 * @return the start offset of the run.
 	 */
 	public int getRunStart(int run) {
-		return runs[run].getStart();
+		return unidirectional ? 0 : runs[run].getStart();
 	}
 
 	/**
@@ -466,6 +528,6 @@
 	 */
 	public String toString() {
 		return super.toString() + "[direction: " + direction + " baselevel: " + baseLevel
-			 + " length: " + length + " runs: " + runs + "]";
+			 + " length: " + length + " runs: " + (unidirectional ? "null" : runs.toString()) + "]";
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java?rev=438844&r1=438843&r2=438844&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java
Thu Aug 31 01:54:23 2006
@@ -15,6 +15,7 @@
 
 package org.apache.harmony.text.tests.java.text;
 
+import java.text.AttributedString; 
 import java.text.Bidi;
 import java.util.Arrays;
 
@@ -946,5 +947,22 @@
             assertEquals(expectedRuns[i][1], bi.getRunLimit(i));
         }
     }
+       public void testGetRunLimit() {
+         bd = new Bidi("text", Bidi.DIRECTION_LEFT_TO_RIGHT);
+         try {
+             assertTrue(4 == bd.getRunLimit(-1));
+         } catch (Exception e) {
+                       fail("Unexpected exception: " + e);
+         }
+       }
+       public void testBidiConstructor_Iterator() {
+               AttributedString paragraph = new AttributedString("text");
+         bd = new Bidi(paragraph.getIterator());
+         try {
+             assertTrue(4 == bd.getRunLimit(1));
+         } catch (Exception e) {
+                       fail("Unexpected exception: " + e);
+         }
+       }
 
 }



Mime
View raw message