diff options
author | Fabrice Di Meglio <fdimeglio@google.com> | 2011-04-13 16:07:37 -0700 |
---|---|---|
committer | Fabrice Di Meglio <fdimeglio@google.com> | 2011-04-15 19:39:47 -0700 |
commit | 689e515ed2b8064c15e54d8ab69d87de54c5e0d6 (patch) | |
tree | 92c6b436a8c4e7d6b76286f076aa2b0f6bd50648 /tests/BiDiTests | |
parent | 0343a7eb6d7cd2bd44dabe5119e2366e84427c93 (diff) | |
download | frameworks_base-689e515ed2b8064c15e54d8ab69d87de54c5e0d6.zip frameworks_base-689e515ed2b8064c15e54d8ab69d87de54c5e0d6.tar.gz frameworks_base-689e515ed2b8064c15e54d8ab69d87de54c5e0d6.tar.bz2 |
Add Unicode BiDi Algo before drawing text in Canvas
- only for temporary API
- update BiDiTest
Change-Id: Ifd445799dc0fda4da896246e41978cd8d71aa035
Diffstat (limited to 'tests/BiDiTests')
-rw-r--r-- | tests/BiDiTests/AndroidManifest.xml | 3 | ||||
-rw-r--r-- | tests/BiDiTests/res/values/strings.xml | 3 | ||||
-rw-r--r-- | tests/BiDiTests/src/com/android/bidi/BiDiTestView.java | 28 |
3 files changed, 26 insertions, 8 deletions
diff --git a/tests/BiDiTests/AndroidManifest.xml b/tests/BiDiTests/AndroidManifest.xml index 346ace8..727f980 100644 --- a/tests/BiDiTests/AndroidManifest.xml +++ b/tests/BiDiTests/AndroidManifest.xml @@ -25,7 +25,8 @@ android:versionName="1.0"> <application android:label="BiDiTests"> - <activity android:name="BiDiTestActivity"> + <activity android:name="BiDiTestActivity" + android:windowSoftInputMode="stateAlwaysHidden"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> diff --git a/tests/BiDiTests/res/values/strings.xml b/tests/BiDiTests/res/values/strings.xml index 632a02e..d20600e 100644 --- a/tests/BiDiTests/res/values/strings.xml +++ b/tests/BiDiTests/res/values/strings.xml @@ -20,9 +20,10 @@ <string name="normal_long_text">mmmmmmmmmmmmmmmmmmmmmmmm</string> <string name="normal_long_text_2">nnnnnnnnnnnnnnnnnnnnnnnn</string> <string name="normal_long_text_3">Notify me when an open network is available</string> - <string name="arabic_text">لا</string> + <string name="arabic_text">لا انا hello world</string> <string name="chinese_text">利比亚局势或影响美俄关系发展</string> <string name="italic_text">Italic String</string> <string name="bold_text">Bold String - other text</string> <string name="bold_italic_text">Bold Italic String</string> + <string name="mixed_text_1">he said in Arabic: لا. Wow this is cool</string> </resources>
\ No newline at end of file diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestView.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestView.java index f00bd06..2f9b026 100644 --- a/tests/BiDiTests/src/com/android/bidi/BiDiTestView.java +++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestView.java @@ -49,6 +49,7 @@ public class BiDiTestView extends View { private String BOLD_ITALIC_TEXT; private String ARABIC_TEXT; private String CHINESE_TEXT; + private String MIXED_TEXT_1; private Typeface typeface; @@ -79,6 +80,7 @@ public class BiDiTestView extends View { BOLD_ITALIC_TEXT = context.getString(R.string.bold_italic_text); ARABIC_TEXT = context.getString(R.string.arabic_text); CHINESE_TEXT = context.getString(R.string.chinese_text); + MIXED_TEXT_1 = context.getString(R.string.mixed_text_1); typeface = paint.getTypeface(); paint.setAntiAlias(true); @@ -124,6 +126,10 @@ public class BiDiTestView extends View { // Test Chinese deltaX = testString(canvas, CHINESE_TEXT, ORIGIN, ORIGIN + 10 * currentTextSize, paint, typeface, false, false, Paint.DIRECTION_LTR, currentTextSize); + + // Test Mixed (English and Arabic) + deltaX = testString(canvas, MIXED_TEXT_1, ORIGIN, ORIGIN + 12 * currentTextSize, + paint, typeface, false, false, Paint.DIRECTION_LTR, currentTextSize); } private int testString(Canvas canvas, String text, int x, int y, Paint paint, Typeface typeface, @@ -139,12 +145,15 @@ public class BiDiTestView extends View { paint.setTextSkewX(DEFAULT_ITALIC_SKEW_X); } - drawTextWithCanvasDrawText(text, canvas, x, y, textSize, Color.WHITE); + Log.v(TAG, "START -- drawTextWithCanvasDrawText"); + drawTextWithCanvasDrawText(text, canvas, x, y, textSize, Color.WHITE, dir); + Log.v(TAG, "END -- drawTextWithCanvasDrawText"); int length = text.length(); float[] advances = new float[length]; - float textWidthHB = paint.getTextRunAdvances(text, 0, length, 0, length, 0, advances, 0); - float textWidthICU = paint.getTextRunAdvancesICU(text, 0, length, 0, length, 0, advances, 0); + float textWidthHB = paint.getTextRunAdvances(text, 0, length, 0, length, dir, advances, 0); + setPaintDir(paint, dir); + float textWidthICU = paint.getTextRunAdvancesICU(text, 0, length, 0, length, dir, advances, 0); logAdvances(text, textWidthHB, textWidthICU, advances); drawMetricsAroundText(canvas, x, y, textWidthHB, textWidthICU, textSize, Color.RED, Color.GREEN); @@ -156,7 +165,9 @@ public class BiDiTestView extends View { // logGlypths(glyphs, count); // drawTextWithDrawGlyph(canvas, glyphs, count, x, y + currentTextSize); + Log.v(TAG, "START -- drawTextWithGlyphs"); drawTextWithGlyphs(canvas, text, x, y + currentTextSize, dir); + Log.v(TAG, "END -- drawTextWithGlyphs"); // Restore old paint properties paint.setFakeBoldText(oldFakeBold); @@ -165,12 +176,17 @@ public class BiDiTestView extends View { return (int) Math.ceil(textWidthHB) + TEXT_PADDING; } + private void setPaintDir(Paint paint, int dir) { + Log.v(TAG, "Setting Paint dir=" + dir); + paint.setBidiFlags(dir); + } + private void drawTextWithDrawGlyph(Canvas canvas, char[] glyphs, int count, int x, int y) { canvas.drawGlyphs(glyphs, 0, count, x, y, paint); } private void drawTextWithGlyphs(Canvas canvas, String text, int x, int y, int dir) { - paint.setBidiFlags(dir); + setPaintDir(paint, dir); canvas.drawTextWithGlyphs(text, x, y, paint); } @@ -182,7 +198,6 @@ public class BiDiTestView extends View { } private int getGlyphs(String text, char[] glyphs, int dir) { -// int dir = 1; // Paint.DIRECTION_LTR; return paint.getTextGlypths(text, 0, text.length(), 0, text.length(), dir, glyphs); } @@ -195,7 +210,8 @@ public class BiDiTestView extends View { } private void drawTextWithCanvasDrawText(String text, Canvas canvas, - float x, float y, float textSize, int color) { + float x, float y, float textSize, int color, int dir) { + setPaintDir(paint, dir); paint.setColor(color); paint.setTextSize(textSize); canvas.drawText(text, x, y, paint); |