diff options
author | Eran Mizrahi <eranmizra@gmail.com> | 2011-04-02 07:02:39 +0300 |
---|---|---|
committer | Eyad Aboulouz <eyad.aboulouz@gmail.com> | 2011-04-03 07:53:05 -0400 |
commit | 43e45eb94e1aa0d1c4dbd10e99df8e366f637261 (patch) | |
tree | dd02263d10be1e9200d0be7f0015957b4ae4a05f /graphics | |
parent | 1c2b1998ace65331b5ddef9c56ff76faa1ae6407 (diff) | |
download | frameworks_base-43e45eb94e1aa0d1c4dbd10e99df8e366f637261.zip frameworks_base-43e45eb94e1aa0d1c4dbd10e99df8e366f637261.tar.gz frameworks_base-43e45eb94e1aa0d1c4dbd10e99df8e366f637261.tar.bz2 |
-Adds RTL (Right-To-Left) support for all RTL languages
-Paragraphs containing RTL text are consistently aligned to the right and text is measured correctly when reshaped
-Supports reshaping (connecting) of standard Arabic letters, including Farsi, Kurdish, Turkish and Urdu
-Supports reshaping of supplement Arabic letters used in languages such as Farsi and Urdu
-Mirroring of symetric symbols such as '(' and ')' when surrouded by RTL text
-Tested by several Arabic native speakers
By Eyad Aboulouz.
Change-Id: Ifd3e24cde0c68c97245e97cf41b71c3701078e48
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/Canvas.java | 320 | ||||
-rw-r--r-- | graphics/java/android/graphics/Paint.java | 114 | ||||
-rw-r--r-- | graphics/java/android/graphics/utils/ArabicReshape.java | 403 |
3 files changed, 118 insertions, 719 deletions
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 285a1b2..2f94f7a 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -16,7 +16,7 @@ package android.graphics; -import android.graphics.utils.ArabicReshape; +import android.text.Layout; import android.text.TextUtils; import android.text.SpannedString; import android.text.SpannableString; @@ -35,8 +35,6 @@ import javax.microedition.khronos.opengles.GL; public class Canvas { // assigned in constructors, freed in finalizer final int mNativeCanvas; - private static final char FIRST_RIGHT_TO_LEFT = '\u0590'; - private static final char LAST_RIGHT_TO_LEFT = '\u07b1'; /* Our native canvas can be either a raster, gl, or picture canvas. If we are raster, then mGL will be null, and mBitmap may or may not be @@ -1235,142 +1233,6 @@ public class Canvas { } /** - * Since the reshaping algorithm does not test for arabic prior to starting, this is made to - * @hide - **/ - public static boolean bidiTest(char[] text,int start,int srcCount) { - - boolean hasBidi=false; - - // Check if there are BiDi characters in the string, of so, we need to work. - for (int i=start;i<(srcCount+start);i++){ - if (text[i]>=FIRST_RIGHT_TO_LEFT&&text[i]<=LAST_RIGHT_TO_LEFT){ - hasBidi=true; - break; - } - } - return hasBidi; - } - /** - * Since the reshaping algorithm does not test for arabic prior to starting, this is made to - * @hide - **/ - public static boolean bidiTest(String text,int start,int srcCount) { - - boolean hasBidi=false; - - // Check if there are BiDi characters in the string, of so, we need to work. - for (int i=start;i<(srcCount+start);i++){ - if (text.charAt(i)>=FIRST_RIGHT_TO_LEFT&&text.charAt(i)<=LAST_RIGHT_TO_LEFT){ - hasBidi=true; - break; - } - } - return hasBidi; - } - /** @hide */ - private static boolean isPunctuation(char c) { - return c<='\u002f' || c=='\u0040' || (c>'\u005a' && c<='\u0060') || (c>'\u007a' && c<='\u00BF'); - } - /** @hide */ - private static boolean isRTL(char c) { - return c>=FIRST_RIGHT_TO_LEFT && c<=LAST_RIGHT_TO_LEFT; - } - /** - * A lightweight BiDi processing to make all draw text work with RTL languages. - * @hide - **/ - private static char reverseParen(char c) { - switch (c) { - case '[': - c=']'; - break; - case ']': - c='['; - break; - case '}': - c='{'; - break; - case '{': - c='}'; - break; - case '(': - c=')'; - break; - case ')': - c='('; - break; - case '>': - c='<'; - break; - case '<': - c='>'; - break; - } - return c; - } - /** @hide */ - public static char[] bidiProcess(char[] text,int start,int count) { - String cut=new String(text,start,count); - char[] tt=new char[count]; - cut.getChars(0, count, tt, 0); - boolean hasRTL=false; - for (int ii=0; ii<count; ++ii) - if (isRTL(tt[ii])) { - hasRTL = true; - break; - } - if (hasRTL) { - char[] rev=new char[count]; - for(int ii=0; ii<count; ++ii) - rev[ii] = tt[count-ii-1]; - // now copy reverse back over tt, but reverse again (fixing) any non-RTL sequences: - for(int ii=0; ii<count; ) { - if (isRTL(rev[ii]) || isPunctuation(rev[ii])) { - tt[ii] = reverseParen(rev[ii]); - ++ii; - } else { - int end=ii+1; - while (end<count && !isRTL(rev[end]) && !isPunctuation(rev[end])) - ++end; - int jj=end; - while (ii<end) - tt[ii++] = rev[--jj]; - } - } - } - return tt; - } - - /** @hide **/ - public void drawText(char[] text, int index, int count, float x, float y, - Paint paint,boolean bidi) { - if (((index | count | (index + count)) < 0) || - (index + count) > text.length) { - throw new IndexOutOfBoundsException(); - } - boolean hasBidi=bidiTest(text,index,count); - if (hasBidi) { - if (bidi) { - char[] bidiText=bidiProcess(text,index,count); - String reshapedText=ArabicReshape.reshape(new String(bidiText)); - /* The reshaping may make the string smaller */ - native_drawText(mNativeCanvas, reshapedText.toCharArray(), 0, count - ((count - reshapedText.length())>0 ? (count - reshapedText.length()) : 0), x, y, - paint.mNativePaint); - } else { - String reshapedText=ArabicReshape.reshape(new String(text)); - /* The reshaping may make the string smaller */ - native_drawText(mNativeCanvas, reshapedText.toCharArray(), index, - count - ((text.length - reshapedText.length())>0 ? (text.length - reshapedText.length()) : 0), x, y, - paint.mNativePaint); - } - } else { - native_drawText(mNativeCanvas, text, index, count, x, y, - paint.mNativePaint); - } - } - - /** * Draw the text, with origin at (x,y), using the specified paint. The * origin is interpreted based on the Align setting in the paint. * @@ -1386,13 +1248,10 @@ public class Canvas { throw new IndexOutOfBoundsException(); } - boolean hasBidi=bidiTest(text,index,count); - if (hasBidi) { - drawText(text,index,count,x,y,paint,true); - } else { - native_drawText(mNativeCanvas, text, index, count, x, y, - paint.mNativePaint); - } + char[] text2 = TextUtils.processBidi(text, index, index+count); + + native_drawText(mNativeCanvas, text2, index, count, x, y, + paint.mNativePaint); } /** @@ -1404,30 +1263,22 @@ public class Canvas { * @param y The y-coordinate of the origin of the text being drawn * @param paint The paint used for the text (e.g. color, size, style) */ - private native void native_drawText(String text, float x, float y, Paint paint); - - /** @hide */ - public void drawText(String text, float x, float y, Paint paint,boolean bidi){ - boolean hasBidi=bidiTest(text,0,text.length()); - if (hasBidi) { - if (!bidi) { - native_drawText(ArabicReshape.reshape(text),x,y,paint); - } else { - if (text.length() > 0) { - String bidiText; - bidiText=new String(bidiProcess(text.toCharArray(),0,text.length())); - native_drawText(ArabicReshape.reshape(bidiText),x,y,paint); - } - } - } else { - native_drawText(text,x,y,paint); - } - } - public void drawText(String text, float x, float y, Paint paint){ - drawText(text,x,y,paint,true); + public void drawText(String text, float x, float y, Paint paint) { + native_drawText (TextUtils.processBidi(text), x, y, paint); } /** + * Draw the text, with origin at (x,y), using the specified paint. The + * origin is interpreted based on the Align setting in the paint. + * + * @param text The text to be drawn + * @param x The x-coordinate of the origin of the text being drawn + * @param y The y-coordinate of the origin of the text being drawn + * @param paint The paint used for the text (e.g. color, size, style) + */ + private native void native_drawText(String text, float x, float y, Paint paint); + + /** * Draw the text, with origin at (x,y), using the specified paint. * The origin is interpreted based on the Align setting in the paint. * @@ -1443,16 +1294,11 @@ public class Canvas { if ((start | end | (end - start) | (text.length() - end)) < 0) { throw new IndexOutOfBoundsException(); } - boolean hasBidi=bidiTest(text,start,end-start); - if (hasBidi) { - String reshapedText=ArabicReshape.reshape(new String(bidiProcess(text.toCharArray(),start,end-start))); - /* The reshaping may make the string smaller */ - native_drawText(mNativeCanvas, reshapedText, 0, end-start - ((end-start - reshapedText.length())>0?(end-start - reshapedText.length()):0), x, y, - paint.mNativePaint); - } else { - native_drawText(mNativeCanvas, text, start, end, x, y, - paint.mNativePaint); - } + + String text2 = TextUtils.processBidi(text, start, end); + + native_drawText(mNativeCanvas, text2, start, end, x, y, + paint.mNativePaint); } /** @@ -1470,49 +1316,24 @@ public class Canvas { */ public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) { - drawText(text,start,end,x,y,paint,true); - } - - /** @hide */ - public void drawText(CharSequence text, int start, int end, float x, - float y, Paint paint,boolean bidi) { - boolean hasBidi=bidiTest(text.toString(),start,end-start); if (text instanceof String || text instanceof SpannedString || - text instanceof SpannableString) { - if (hasBidi) { - if (bidi) { - String bidiText=new String(bidiProcess(text.toString().toCharArray(),start,end-start)); - String reshapedText=ArabicReshape.reshape(bidiText); - /* The reshaping may make the string smaller */ - native_drawText(mNativeCanvas, reshapedText, 0, (end-start) - ((end-start - reshapedText.length())>0 ? (end-start - reshapedText.length()) : 0), x, y, - paint.mNativePaint); - } else { - String reshapedText=ArabicReshape.reshape(text.toString()); - /* The reshaping may make the string smaller */ - native_drawText(mNativeCanvas, reshapedText, 0, (end-start) - ((end-start - reshapedText.length())>0 ? (end-start - reshapedText.length()) : 0), x, y, - paint.mNativePaint); - } - } else { - native_drawText(mNativeCanvas, text.toString() , start, end, x, y, + text instanceof SpannableString) { + + String text2 = TextUtils.processBidi(text.toString(), start, end); + + native_drawText(mNativeCanvas, text2, start, end, x, y, paint.mNativePaint); - } } else if (text instanceof GraphicsOperations) { ((GraphicsOperations) text).drawText(this, start, end, x, y, - paint); - } - else { - char[] buf = TemporaryBuffer.obtain(end - start); - TextUtils.getChars(text, start, end, buf, 0); - if (hasBidi) { - String reshapedText=ArabicReshape.reshape(new String(buf)); - /* The reshaping may make the string smaller */ - drawText(reshapedText.toCharArray(), 0, (end - start) - (((end - start) - reshapedText.length())>0?((end - start) - reshapedText.length()):0), x, y, paint,false); - } else { - drawText(buf, 0, end - start, x, y, paint,false); - } - TemporaryBuffer.recycle(buf); - } + paint); + } + else { + char[] buf = TemporaryBuffer.obtain(end - start); + TextUtils.getChars(text, start, end, buf, 0); + drawText(buf, 0, end - start, x, y, paint); + TemporaryBuffer.recycle(buf); + } } /** @@ -1532,20 +1353,10 @@ public class Canvas { throw new IndexOutOfBoundsException(); } - boolean hasBidi=bidiTest(text,index,count); - if (hasBidi) { - float[] relativePos = new float[count*2]; - System.arraycopy(pos , index*2 , relativePos , 0, count*2); - char[] bidiText; - bidiText=bidiProcess(text,index,count); - String reshapedText=ArabicReshape.reshape(new String(bidiText)); - /* The reshaping may make the string smaller */ - native_drawPosText(mNativeCanvas, reshapedText.toCharArray(), 0, count - ((count - reshapedText.length())>0 ? (count - reshapedText.length()) : 0), relativePos, - paint.mNativePaint); - } else { - native_drawPosText(mNativeCanvas, text, index, count, pos, - paint.mNativePaint); - } + char[] text2 = TextUtils.processBidi(text, index, index+count); + + native_drawPosText(mNativeCanvas, text2, index, count, pos, + paint.mNativePaint); } /** @@ -1561,15 +1372,9 @@ public class Canvas { throw new ArrayIndexOutOfBoundsException(); } - boolean hasBidi=bidiTest(text,0,text.length()); - if (hasBidi) { - String bidiText; - bidiText=new String(bidiProcess(text.toCharArray(),0,text.length())); - native_drawPosText(mNativeCanvas, ArabicReshape.reshape(bidiText), pos, paint.mNativePaint); - } else { - native_drawPosText(mNativeCanvas, text, pos, - paint.mNativePaint); - } + String text2 = TextUtils.processBidi(text); + + native_drawPosText(mNativeCanvas, text2, pos, paint.mNativePaint); } /** @@ -1590,21 +1395,12 @@ public class Canvas { if (index < 0 || index + count > text.length) { throw new ArrayIndexOutOfBoundsException(); } - boolean hasBidi=bidiTest(text,index,count); - if (hasBidi) { - char[] bidiText; - bidiText=bidiProcess(text,index,count); - String reshapedText=ArabicReshape.reshape(new String(bidiText)); - /* The reshaping may make the string smaller */ - native_drawTextOnPath(mNativeCanvas, reshapedText.toCharArray(), 0, count - ((count - reshapedText.length())>0 ? (count - reshapedText.length()) : 0), - path.ni(), hOffset, vOffset, - paint.mNativePaint); - } else { - native_drawTextOnPath(mNativeCanvas, text, index, count, - path.ni(), hOffset, vOffset, - paint.mNativePaint); - } - // TODO: Handle index>0 + + char[] text2 = TextUtils.processBidi(text, index, index+count); + + native_drawTextOnPath(mNativeCanvas, text2, index, count, + path.ni(), hOffset, vOffset, + paint.mNativePaint); } /** @@ -1623,17 +1419,11 @@ public class Canvas { public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) { if (text.length() > 0) { - boolean hasBidi=bidiTest(text,0,text.length()); - if (hasBidi) { - String bidiText; - bidiText=new String(bidiProcess(text.toCharArray(),0,text.length())); - native_drawTextOnPath(mNativeCanvas, ArabicReshape.reshape(bidiText), path.ni(), - hOffset, vOffset, paint.mNativePaint); - } else { - native_drawTextOnPath(mNativeCanvas, text, - path.ni(), hOffset, vOffset, - paint.mNativePaint); - } + + String text2 = TextUtils.processBidi(text); + + native_drawTextOnPath(mNativeCanvas, text2, path.ni(), + hOffset, vOffset, paint.mNativePaint); } } @@ -1823,4 +1613,4 @@ public class Canvas { private static native void native_drawPicture(int nativeCanvas, int nativePicture); private static native void finalizer(int nativeCanvas); -} +}
\ No newline at end of file diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index 6d6f730..847aa69 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -16,11 +16,11 @@ package android.graphics; -import android.graphics.utils.ArabicReshape; import android.text.TextUtils; import android.text.SpannableString; import android.text.SpannedString; import android.text.GraphicsOperations; +import android.util.Log; /** * The Paint class holds the style and color information about how to draw @@ -999,16 +999,19 @@ public class Paint { * @return The width of the text */ public float measureText(char[] text, int index, int count) { - if (!mHasCompatScaling) return native_measureText(text, index, count); + + char[] text2 = TextUtils.processBidi(text, index, index+count); + + if (!mHasCompatScaling) return native_measureText(text2, index, count); final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); - float w = native_measureText(text, index, count); + float w = native_measureText(text2, index, count); setTextSize(oldSize); return w*mInvCompatScaling; } private native float native_measureText(char[] text, int index, int count); - + /** * Return the width of the text. * @@ -1018,16 +1021,19 @@ public class Paint { * @return The width of the text */ public float measureText(String text, int start, int end) { - if (!mHasCompatScaling) return native_measureText(text, start, end); + + String text2 = TextUtils.processBidi(text, start, end); + + if (!mHasCompatScaling) return native_measureText(text2, start, end); final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); - float w = native_measureText(text, start, end); + float w = native_measureText(text2, start, end); setTextSize(oldSize); return w*mInvCompatScaling; } private native float native_measureText(String text, int start, int end); - + /** * Return the width of the text. * @@ -1035,7 +1041,10 @@ public class Paint { * @return The width of the text */ public float measureText(String text) { - if (!mHasCompatScaling) return native_measureText(text); + + String text2 = TextUtils.processBidi(text); + + if (!mHasCompatScaling) return native_measureText(text2); final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); float w = native_measureText(text); @@ -1044,7 +1053,7 @@ public class Paint { } private native float native_measureText(String text); - + /** * Return the width of the text. * @@ -1071,7 +1080,7 @@ public class Paint { TemporaryBuffer.recycle(buf); return result; } - + /** * Measure the text, stopping early if the measured width exceeds maxWidth. * Return the number of chars that were measured, and if measuredWidth is @@ -1091,12 +1100,15 @@ public class Paint { */ public int breakText(char[] text, int index, int count, float maxWidth, float[] measuredWidth) { + + char[] text2 = TextUtils.processBidi(text); + if (!mHasCompatScaling) { - return native_breakText(text, index, count, maxWidth, measuredWidth); + return native_breakText(text2, index, count, maxWidth, measuredWidth); } final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); - int res = native_breakText(text, index, count, maxWidth*mCompatScaling, + int res = native_breakText(text2, index, count, maxWidth*mCompatScaling, measuredWidth); setTextSize(oldSize); if (measuredWidth != null) measuredWidth[0] *= mInvCompatScaling; @@ -1163,12 +1175,15 @@ public class Paint { */ public int breakText(String text, boolean measureForwards, float maxWidth, float[] measuredWidth) { + + String text2 = TextUtils.processBidi(text); + if (!mHasCompatScaling) { - return native_breakText(text, measureForwards, maxWidth, measuredWidth); + return native_breakText(text2, measureForwards, maxWidth, measuredWidth); } final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); - int res = native_breakText(text, measureForwards, maxWidth*mCompatScaling, + int res = native_breakText(text2, measureForwards, maxWidth*mCompatScaling, measuredWidth); setTextSize(oldSize); if (measuredWidth != null) measuredWidth[0] *= mInvCompatScaling; @@ -1194,13 +1209,15 @@ public class Paint { || count > widths.length) { throw new ArrayIndexOutOfBoundsException(); } - + + char[] text2 = TextUtils.processBidi(text, index, index+count); + if (!mHasCompatScaling) { - return native_getTextWidths(mNativePaint, text, index, count, widths); + return native_getTextWidths(mNativePaint, text2, index, count, widths); } final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); - int res = native_getTextWidths(mNativePaint, text, index, count, widths); + int res = native_getTextWidths(mNativePaint, text2, index, count, widths); setTextSize(oldSize); for (int i=0; i<res; i++) { widths[i] *= mInvCompatScaling; @@ -1233,10 +1250,10 @@ public class Paint { } char[] buf = TemporaryBuffer.obtain(end - start); - TextUtils.getChars(text, start, end, buf, 0); - int result = getTextWidths(buf, 0, end - start, widths); + TextUtils.getChars(text, start, end, buf, 0); + int result = getTextWidths(buf, 0, end - start, widths); TemporaryBuffer.recycle(buf); - return result; + return result; } /** @@ -1250,26 +1267,29 @@ public class Paint { * @return the number of unichars in the specified text. */ public int getTextWidths(String text, int start, int end, float[] widths) { + if ((start | end | (end - start) | (text.length() - end)) < 0) { throw new IndexOutOfBoundsException(); } if (end - start > widths.length) { throw new ArrayIndexOutOfBoundsException(); } - + + String text2 = TextUtils.processBidi(text, start, end); + if (!mHasCompatScaling) { - return native_getTextWidths(mNativePaint, text, start, end, widths); + return native_getTextWidths(mNativePaint, text2, start, end, widths); } final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); - int res = native_getTextWidths(mNativePaint, text, start, end, widths); + int res = native_getTextWidths(mNativePaint, text2, start, end, widths); setTextSize(oldSize); for (int i=0; i<res; i++) { widths[i] *= mInvCompatScaling; } return res; } - + /** * Return the advance widths for the characters in the string. * @@ -1279,6 +1299,7 @@ public class Paint { * @return the number of unichars in the specified text. */ public int getTextWidths(String text, float[] widths) { + return getTextWidths(text, 0, text.length(), widths); } @@ -1300,18 +1321,10 @@ public class Paint { if ((index | count) < 0 || index + count > text.length) { throw new ArrayIndexOutOfBoundsException(); } - boolean hasBidi=Canvas.bidiTest(text,index,count); - if (hasBidi) { - char[] bidiText; - bidiText=Canvas.bidiProcess(text,index,count); - String reshapedText=ArabicReshape.reshape(new String(bidiText)); - /* The reshaping may make the string smaller */ - native_getTextPath(mNativePaint, reshapedText.toCharArray(), 0, - count - ((count-reshapedText.length())>0 ? (count-reshapedText.length()) : 0), - x, y, path.ni()); - } else { - native_getTextPath(mNativePaint, text, index, count, x, y, path.ni()); - } + + char[] text2 = TextUtils.processBidi(text, index, index+count); + + native_getTextPath(mNativePaint, text2, index, count, x, y, path.ni()); } /** @@ -1332,19 +1345,12 @@ public class Paint { if ((start | end | (end - start) | (text.length() - end)) < 0) { throw new IndexOutOfBoundsException(); } - boolean hasBidi=Canvas.bidiTest(text,start,start+end); - if (hasBidi) { - char[] bidiText; - bidiText=Canvas.bidiProcess(text.toCharArray(),start,start+end); - String reshapedText=ArabicReshape.reshape(new String(bidiText)); - /* The reshaping may make the string smaller */ - native_getTextPath(mNativePaint, reshapedText, 0, end-start - ((end-start - reshapedText.length())>0 ? (end-start - reshapedText.length()) : 0), - x, y, path.ni()); - } else { - native_getTextPath(mNativePaint, text, start, end, x, y, path.ni()); - } + + String text2 = TextUtils.processBidi(text, start, end); + + native_getTextPath(mNativePaint, text2, start, end, x, y, path.ni()); } - + /** * Return in bounds (allocated by the caller) the smallest rectangle that * encloses all of the characters, with an implied origin at (0,0). @@ -1362,9 +1368,12 @@ public class Paint { if (bounds == null) { throw new NullPointerException("need bounds Rect"); } - nativeGetStringBounds(mNativePaint, text, start, end, bounds); + + String text2 = TextUtils.processBidi(text, start, end); + + nativeGetStringBounds(mNativePaint, text2, start, end, bounds); } - + /** * Return in bounds (allocated by the caller) the smallest rectangle that * encloses all of the characters, with an implied origin at (0,0). @@ -1382,7 +1391,10 @@ public class Paint { if (bounds == null) { throw new NullPointerException("need bounds Rect"); } - nativeGetCharArrayBounds(mNativePaint, text, index, count, bounds); + + char[] text2 = TextUtils.processBidi(text, index, index+count); + + nativeGetCharArrayBounds(mNativePaint, text2, index, count, bounds); } protected void finalize() throws Throwable { diff --git a/graphics/java/android/graphics/utils/ArabicReshape.java b/graphics/java/android/graphics/utils/ArabicReshape.java deleted file mode 100644 index 785b4c6..0000000 --- a/graphics/java/android/graphics/utils/ArabicReshape.java +++ /dev/null @@ -1,403 +0,0 @@ -/* - * Copyright (C) 2010 Abdulaziz Alhussien - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* @hide */ -package android.graphics.utils; - -/** - * This code is for Arabic Reshaping. - * Writtien by Abdulaziz Alhussien. - * azizanroid@gmail.com - * - * This code is used in Mirsal, Ibrahim Keyboard, Arabic Contact, Arabic notepad applications - * - * @hide - */ -public class ArabicReshape { - - static final char RIGHT_LEFT_CHAR = 0x0001; - static final char RIGHT_NOLEFT_CHAR_ALEF = 0x0006; - static final char RIGHT_NOLEFT_CHAR = 0x0004; - static final char RIGHT_LEFT_CHAR_LAM = 0x0003; - static final char TANWEEN = 0x000C; - static final char TASHKEEL = 0x000A; - static final char TATWEEL_CHAR = 0x0008; - static final char NORIGHT_NOLEFT_CHAR = 0x0007; - static final char NOTUSED_CHAR = 0x000F; - static final char NOTARABIC_CHAR = 0x0000; - static final char RIGHT_LEFT_CHAR_MASK = 0x0880; - static final char RIGHT_NOLEFT_CHAR_MASK = 0x0800; - static final char LEFT_CHAR_MASK = 0x0080; - - private static final char allchar[][] = { - {0x0621, 0x0007, 0xFE80, 0xFE80, 0xFE80, 0xFE80}, - {0x0622, 0x0806, 0xFE81, 0xFE82, 0xFEF5, 0xFEF6}, - {0x0623, 0x0806, 0xFE83, 0xFE84, 0xFEF7, 0xFEF8}, - {0x0624, 0x0804, 0xFE85, 0xFE86, 0xFE86, 0xFE86}, - {0x0625, 0x0806, 0xFE87, 0xFE88, 0xFEF9, 0xFEFA}, - {0x0626, 0x0881, 0xFE89, 0xFE8A, 0xFE8B, 0xFE8C}, - {0x0627, 0x0806, 0xFE8D, 0xFE8E, 0xFEFB, 0xFEFC}, - {0x0628, 0x0881, 0xFE8F, 0xFE90, 0xFE91, 0xFE92}, - {0x0629, 0x0804, 0xFE93, 0xFE94, 0xFE94, 0xFE94}, - {0x062A, 0x0881, 0xFE95, 0xFE96, 0xFE97, 0xFE98}, - {0x062B, 0x0881, 0xFE99, 0xFE9A, 0xFE9B, 0xFE9C}, - {0x062C, 0x0881, 0xFE9D, 0xFE9E, 0xFE9F, 0xFEA0}, - {0x062D, 0x0881, 0xFEA1, 0xFEA2, 0xFEA3, 0xFEA4}, - {0x062E, 0x0881, 0xFEA5, 0xFEA6, 0xFEA7, 0xFEA8}, - {0x062F, 0x0804, 0xFEA9, 0xFEAA, 0xFEAA, 0xFEAA}, - {0x0630, 0x0804, 0xFEAB, 0xFEAC, 0xFEAC, 0xFEAC}, - {0x0631, 0x0804, 0xFEAD, 0xFEAE, 0xFEAE, 0xFEAE}, - {0x0632, 0x0804, 0xFEAF, 0xFEB0, 0xFEB0, 0xFEB0}, - {0x0633, 0x0881, 0xFEB1, 0xFEB2, 0xFEB3, 0xFEB4}, - {0x0634, 0x0881, 0xFEB5, 0xFEB6, 0xFEB7, 0xFEB8}, - {0x0635, 0x0881, 0xFEB9, 0xFEBA, 0xFEBB, 0xFEBC}, - {0x0636, 0x0881, 0xFEBD, 0xFEBE, 0xFEBF, 0xFEC0}, - {0x0637, 0x0881, 0xFEC1, 0xFEC2, 0xFEC3, 0xFEC4}, - {0x0638, 0x0881, 0xFEC5, 0xFEC6, 0xFEC7, 0xFEC8}, - {0x0639, 0x0881, 0xFEC9, 0xFECA, 0xFECB, 0xFECC}, - {0x063A, 0x0881, 0xFECD, 0xFECE, 0xFECF, 0xFED0}, - {0x063B, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x063C, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x063D, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x063E, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x063F, 0x000F, 0x0, 0x0, 0x0, 0x0}, - - {0x0640, 0x0888, 0x0640, 0x0640, 0x0640, 0x0640}, - {0x0641, 0x0881, 0xFED1, 0xFED2, 0xFED3, 0xFED4}, - {0x0642, 0x0881, 0xFED5, 0xFED6, 0xFED7, 0xFED8}, - {0x0643, 0x0881, 0xFED9, 0xFEDA, 0xFEDB, 0xFEDC}, - {0x0644, 0x0883, 0xFEDD, 0xFEDE, 0xFEDF, 0xFEE0}, - {0x0645, 0x0881, 0xFEE1, 0xFEE2, 0xFEE3, 0xFEE4}, - {0x0646, 0x0881, 0xFEE5, 0xFEE6, 0xFEE7, 0xFEE8}, - {0x0647, 0x0881, 0xFEE9, 0xFEEA, 0xFEEB, 0xFEEC}, - {0x0648, 0x0804, 0xFEED, 0xFEEE, 0xFEEE, 0xFEEE}, - {0x0649, 0x0804, 0xFEEF, 0xFEF0, 0xFEF0, 0xFEF0}, - {0x064A, 0x0881, 0xFEF1, 0xFEF2, 0xFEF3, 0xFEF4}, - {0x064B, 0x000C, 0x064B, 0xFE70, 0xFE71, 0xFE70}, - {0x064C, 0x000C, 0x064C, 0xFE72, 0xFE72, 0xFE72}, - {0x064D, 0x000C, 0x064D, 0xFE74, 0xFE74, 0xFE74}, - {0x064E, 0x000A, 0x064E, 0xFE76, 0xFE77, 0xFE76}, - {0x064F, 0x000A, 0x064F, 0xFE78, 0xFE79, 0xFE78}, - {0x0650, 0x000A, 0x0650, 0xFE7A, 0xFE7B, 0xFE7A}, - {0x0651, 0x000A, 0x0651, 0xFE7C, 0xFE7D, 0xFE7C}, - {0x0652, 0x000A, 0x0652, 0xFE7E, 0xFE7F, 0xFE7E}, - - {0x0653, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0654, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0655, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0656, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0657, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0658, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0659, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x065A, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x065B, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x065C, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x065D, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x065E, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x065F, 0x000F, 0x0, 0x0, 0x0, 0x0}, - - {0x0660, 0x000B, 0x0660, 0x0660, 0x0660, 0x0660}, - {0x0661, 0x000B, 0x0661, 0x0661, 0x0661, 0x0661}, - {0x0662, 0x000B, 0x0662, 0x0662, 0x0662, 0x0662}, - {0x0663, 0x000B, 0x0663, 0x0663, 0x0663, 0x0663}, - {0x0664, 0x000B, 0x0665, 0x0664, 0x0664, 0x0664}, - {0x0665, 0x000B, 0x0665, 0x0665, 0x0665, 0x0665}, - {0x0666, 0x000B, 0x0666, 0x0666, 0x0666, 0x0666}, - {0x0667, 0x000B, 0x0667, 0x0667, 0x0667, 0x0667}, - {0x0668, 0x000B, 0x0668, 0x0668, 0x0668, 0x0668}, - {0x0669, 0x000B, 0x0669, 0x0669, 0x0669, 0x0669}, - - {0x066A, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x066B, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x066C, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x066D, 0x000F, 0x0, 0x0, 0x0, 0x0}, - - {0x066E, 0x000E, 0x065E, 0x065E, 0x065E, 0x065E}, - {0x066F, 0x000E, 0x065F, 0x065F, 0x065F, 0x065F}, - - {0x0670, 0x000F, 0x0, 0x0, 0x0, 0x0}, - - {0x0671, 0x0804, 0xFB50, 0xFB51, 0xFB51, 0xFB51}, - {0x0672, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0673, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0674, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0675, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0676, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0677, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0678, 0x000F, 0x0, 0x0, 0x0, 0x0}, - - - {0x0679, 0x0881, 0xFB66, 0xFB67, 0xFB68, 0xFB69}, - {0x067A, 0x0881, 0xFB5E, 0xFB5F, 0xFB60, 0xFB61}, - {0x067B, 0x0881, 0xFB52, 0xFB53, 0xFB54, 0xFB55}, - {0x067C, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x067D, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x067E, 0x0881, 0xFB56, 0xFB57, 0xFB58, 0xFB59}, - {0x067F, 0x0881, 0xFB62, 0xFB63, 0xFB64, 0xFB65}, - {0x0680, 0x0881, 0xFB5A, 0xFB5B, 0xFB5C, 0xFB5D}, - - {0x0681, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0682, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0683, 0x0881, 0xFB76, 0xFB77, 0xFB78, 0xFB79}, - {0x0684, 0x0881, 0xFB72, 0xFB73, 0xFB74, 0xFB75}, - {0x0685, 0x000F, 0x0, 0x0, 0x0, 0x0}, - - {0x0686, 0x0881, 0xFB7A, 0xFB7B, 0xFB7C, 0xFB7D}, - {0x0687, 0x0881, 0xFB7E, 0xFB7F, 0xFB80, 0xFB81}, - {0x0688, 0x0804, 0xFB88, 0xFB89, 0xFB89, 0xFB89}, - {0x0689, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x068A, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x068B, 0x000F, 0x0, 0x0, 0x0, 0x0}, - - {0x068C, 0x0804, 0xFB84, 0xFB85, 0xFB85, 0xFB85}, - {0x068D, 0x0804, 0xFB82, 0xFB83, 0xFB83, 0xFB83}, - {0x068E, 0x0804, 0xFB86, 0xFB87, 0xFB83, 0xFB83}, - {0x068F, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0690, 0x000F, 0x0, 0x0, 0x0, 0x0}, - - {0x0691, 0x0804, 0xFB8C, 0xFB8D, 0xFB8D, 0xFB8D}, - {0x0692, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0693, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0694, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0695, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0696, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x0697, 0x000F, 0x0, 0x0, 0x0, 0x0}, - - {0x0698, 0x0804, 0xFB8A, 0xFB8B, 0xFB8B, 0xFB8B}, - {0x0699, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x069A, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x069B, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x069C, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x069D, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x069E, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x069F, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06A0, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06A1, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06A2, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06A3, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06A4, 0x0881, 0xFB6A, 0xFB6B, 0xFB6C, 0xFB6D}, - {0x06A5, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06A6, 0x0881, 0xFB6E, 0xFB6F, 0xFB70, 0xFB71}, - {0x06A7, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06A8, 0x000F, 0x0, 0x0, 0x0, 0x0}, - - {0x06A9, 0x0881, 0xFB8E, 0xFB8F, 0xFB90, 0xFB91}, - {0x06AA, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06AB, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06AC, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06AD, 0x0881, 0xFBD3, 0xFBD4, 0xFBD5, 0xFBD6}, - {0x06AE, 0x000F, 0x0, 0x0, 0x0, 0x0}, - - {0x06AF, 0x0881, 0xFB92, 0xFB93, 0xFB94, 0xFB95}, - {0x06B0, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06B1, 0x0881, 0xFB9A, 0xFB9B, 0xFB9C, 0xFB9D}, - {0x06B2, 0x000F, 0x0, 0x0, 0x0, 0x0}, - - {0x06B3, 0x0881, 0xFB96, 0xFB97, 0xFB98, 0xFB99}, - {0x06B4, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06B5, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06B6, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06B7, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06B8, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06B9, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06BA, 0x0804, 0xFB9E, 0xFB9F, 0xFB9F, 0xFB9F}, - {0x06BB, 0x0881, 0xFBA0, 0xFBA1, 0xFBA2, 0xFBA3}, - {0x06BC, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06BD, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06BE, 0x0881, 0xFBAA, 0xFBAB, 0xFBAC, 0xFBAD}, - {0x06BF, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06C0, 0x0804, 0xFBA4, 0xFBA5, 0xFBA5, 0xFBA5}, - {0x06C1, 0x0881, 0xFBA6, 0xFBA7, 0xFBA8, 0xFBA9}, - {0x06C2, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06C3, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06C4, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06C5, 0x0804, 0xFBE0, 0xFBE1, 0xFBE1, 0xFBE1}, - {0x06C6, 0x0804, 0xFBD9, 0xFBDA, 0xFBDA, 0xFBDA}, - {0x06C7, 0x0804, 0xFBD7, 0xFBD8, 0xFBD8, 0xFBD8}, - {0x06C8, 0x0804, 0xFBDB, 0xFBDC, 0xFBDC, 0xFBDC}, - {0x06C9, 0x0804, 0xFBE2, 0xFBE3, 0xFBE3, 0xFBE3}, - {0x06CA, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06CB, 0x0804, 0xFBDE, 0xFBDF, 0xFBDF, 0xFBDF}, - {0x06CC, 0x0881, 0xFBFC, 0xFBFD, 0xFBFE, 0xFBFF}, - {0x06CD, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06CE, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06CF, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06D0, 0x0881, 0xFBE4, 0xFBE5, 0xFBE6, 0xFBE7}, - {0x06D1, 0x000F, 0x0, 0x0, 0x0, 0x0}, - {0x06D2, 0x0804, 0xFBAE, 0xFBAF, 0xFBAF, 0xFBAF}, - {0x06D3, 0x0804, 0xFBB0, 0xFBB1, 0xFBB1, 0xFBB1} - }; - - /* @hide */ - public static String reshape(String Str) { - String Temp = " " + Str + " "; - char pre, at, post; - StringBuilder reshapedString = new StringBuilder(); - int i = 0; - int len = Str.length(); - - char post_post; - char pre_pre = ' '; - - while (i < len) { - pre = Temp.charAt(i + 2); - at = Temp.charAt(i + 1); - post = Temp.charAt(i); - - int which_case = getCase(at); - int what_case_post = getCase(post); - int what_case_pre = getCase(pre); - int what_case_post_post; - int what_case_pre_pre; - // which_case=0x000F& - // Log.v("what case"," :" +which_case); - int pre_step = 0; - if (what_case_pre == TASHKEEL) { - pre = pre_pre; - what_case_pre = getCase(pre); - } - if ((what_case_pre & LEFT_CHAR_MASK) == LEFT_CHAR_MASK) { - pre_step = 1; - - } - - switch (which_case & 0x000F) { - - case NOTUSED_CHAR: - case NOTARABIC_CHAR: - - reshapedString.append(at); - - i++; - continue; - case NORIGHT_NOLEFT_CHAR: - case TATWEEL_CHAR: - reshapedString.append(getShape(at, 0)); - - i++; - continue; - case RIGHT_LEFT_CHAR_LAM: - - if ((what_case_post & 0x000F) == RIGHT_NOLEFT_CHAR_ALEF) { - reshapedString.append(getShape(post, pre_step + 2)); - i = i + 2; - - continue; - } else if ((what_case_post & RIGHT_NOLEFT_CHAR_MASK) == RIGHT_NOLEFT_CHAR_MASK) { - reshapedString.append(getShape(at, 2 + pre_step)); - i = i + 1; - - continue; - - } else if (what_case_post == TANWEEN) { - reshapedString.append(getShape(at, pre_step)); - i = i + 1; - continue; - - } else if (what_case_post == TASHKEEL) { - post_post = Temp.charAt(i + 3); - what_case_post_post = getCase(post_post); - if ((what_case_post_post & RIGHT_NOLEFT_CHAR_MASK) == RIGHT_NOLEFT_CHAR_MASK) { - reshapedString.append(getShape(at, 2 + pre_step)); - i = i + 1; - - continue; - - } else { - reshapedString.append(getShape(at, pre_step)); - i = i + 1; - continue; - - } - - } else { - reshapedString.append(getShape(at, pre_step)); - i = i + 1; - continue; - - } - - case RIGHT_LEFT_CHAR: - if ((what_case_post & RIGHT_NOLEFT_CHAR_MASK) == RIGHT_NOLEFT_CHAR_MASK) { - reshapedString.append(getShape(at, 2 + pre_step)); - i = i + 1; - continue; - - } else if (what_case_post == TANWEEN) { - reshapedString.append(getShape(at, pre_step)); - i = i + 1; - continue; - - } else if (what_case_post == TASHKEEL) { - post_post = Temp.charAt(i + 3); - what_case_post_post = getCase(post_post); - if ((what_case_post_post & RIGHT_NOLEFT_CHAR_MASK) == RIGHT_NOLEFT_CHAR_MASK) { - reshapedString.append(getShape(at, 2 + pre_step)); - i = i + 1; - continue; - - } else { - reshapedString.append(getShape(at, pre_step)); - i = i + 1; - continue; - - } - - } else { - reshapedString.append(getShape(at, pre_step)); - i = i + 1; - continue; - - } - case RIGHT_NOLEFT_CHAR_ALEF: - case RIGHT_NOLEFT_CHAR: - reshapedString.append(getShape(at, pre_step)); - i = i + 1; - continue; - case TASHKEEL: - reshapedString.append(getShape(at, 0)); - i++; - pre_pre = pre; - continue; - case TANWEEN: - reshapedString.append(getShape(at, 0)); - i++; - pre_pre = pre; - continue; - - default: - reshapedString.append(getShape(at, 0)); - i++; - - } - } - - return reshapedString.toString(); - } - - static int getCase(char ch) { - if (ch < 0x0621 || ch > 0x06d2) { - return 0; - } else { - return allchar[(int) ch - 0x0621][1]; - } - } - - static char getShape(char ch, int which_shape) { - return allchar[(int) ch - 0x0621][2 + which_shape]; - } - -} |