summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFabrice Di Meglio <fdimeglio@google.com>2011-04-18 11:15:57 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-04-18 11:15:57 -0700
commitf7b9e7848623efcb4f596aa06f055bb4d2ebe7f5 (patch)
tree3e18905c9bd88828217e6aed6603f3e49e988faa /tests
parent95814b0268ce3943930156afd3f423af8afed8e9 (diff)
parent689e515ed2b8064c15e54d8ab69d87de54c5e0d6 (diff)
downloadframeworks_base-f7b9e7848623efcb4f596aa06f055bb4d2ebe7f5.zip
frameworks_base-f7b9e7848623efcb4f596aa06f055bb4d2ebe7f5.tar.gz
frameworks_base-f7b9e7848623efcb4f596aa06f055bb4d2ebe7f5.tar.bz2
Merge "Add Unicode BiDi Algo before drawing text in Canvas"
Diffstat (limited to 'tests')
-rw-r--r--tests/BiDiTests/AndroidManifest.xml3
-rw-r--r--tests/BiDiTests/res/values/strings.xml3
-rw-r--r--tests/BiDiTests/src/com/android/bidi/BiDiTestView.java28
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">&#x0644;&#x0627;</string>
+ <string name="arabic_text">&#x0644;&#x0627; &#x0627;&#x0646;&#x0627; 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: &#x0644;&#x0627;. 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);