diff options
Diffstat (limited to 'tests/BiDiTests/src/com/android/bidi/BiDiTestView.java')
-rw-r--r-- | tests/BiDiTests/src/com/android/bidi/BiDiTestView.java | 94 |
1 files changed, 59 insertions, 35 deletions
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestView.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestView.java index e9b6fa6..cd415c2 100644 --- a/tests/BiDiTests/src/com/android/bidi/BiDiTestView.java +++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestView.java @@ -32,9 +32,8 @@ public class BiDiTestView extends View { private static final int BORDER_PADDING = 4; private static final int TEXT_PADDING = 16; - private static final int TEXT_SIZE = 32; - private static final int ORIGIN = 48; - private static final int DELTA_Y = TEXT_SIZE; + private static final int TEXT_SIZE = 16; + private static final int ORIGIN = 80; private static final float DEFAULT_ITALIC_SKEW_X = -0.25f; @@ -43,6 +42,8 @@ public class BiDiTestView extends View { private String NORMAL_TEXT; private String NORMAL_LONG_TEXT; + private String NORMAL_LONG_TEXT_2; + private String NORMAL_LONG_TEXT_3; private String ITALIC_TEXT; private String BOLD_TEXT; private String BOLD_ITALIC_TEXT; @@ -51,6 +52,8 @@ public class BiDiTestView extends View { private Typeface typeface; + private int currentTextSize; + public BiDiTestView(Context context) { super(context); init(context); @@ -69,6 +72,8 @@ public class BiDiTestView extends View { private void init(Context context) { NORMAL_TEXT = context.getString(R.string.normal_text); NORMAL_LONG_TEXT = context.getString(R.string.normal_long_text); + NORMAL_LONG_TEXT_2 = context.getString(R.string.normal_long_text_2); + NORMAL_LONG_TEXT_3 = context.getString(R.string.normal_long_text_3); ITALIC_TEXT = context.getString(R.string.italic_text); BOLD_TEXT = context.getString(R.string.bold_text); BOLD_ITALIC_TEXT = context.getString(R.string.bold_italic_text); @@ -79,34 +84,50 @@ public class BiDiTestView extends View { paint.setAntiAlias(true); } + public void setCurrentTextSize(int size) { + currentTextSize = size; + invalidate(); + } + @Override public void onDraw(Canvas canvas) { drawInsideRect(canvas, Color.BLACK); - int deltaX = testString(canvas, NORMAL_TEXT, ORIGIN, ORIGIN, paint, typeface, - false, false, Paint.DIRECTION_LTR); - deltaX += testString(canvas, ITALIC_TEXT, ORIGIN + deltaX, ORIGIN, paint, typeface, - true, false, Paint.DIRECTION_LTR); - deltaX += testString(canvas, BOLD_TEXT, ORIGIN + deltaX, ORIGIN, paint, typeface, - false, true, Paint.DIRECTION_LTR); - deltaX += testString(canvas, BOLD_ITALIC_TEXT, ORIGIN + deltaX, ORIGIN, paint, typeface, - true, true, Paint.DIRECTION_LTR); + int deltaX = testString(canvas, NORMAL_TEXT, ORIGIN, ORIGIN, + paint, typeface, false, false, Paint.DIRECTION_LTR, currentTextSize); + + deltaX += testString(canvas, ITALIC_TEXT, ORIGIN + deltaX, ORIGIN, + paint, typeface, true, false, Paint.DIRECTION_LTR, currentTextSize); + + deltaX += testString(canvas, BOLD_TEXT, ORIGIN + deltaX, ORIGIN, + paint, typeface, false, true, Paint.DIRECTION_LTR, currentTextSize); + + deltaX += testString(canvas, BOLD_ITALIC_TEXT, ORIGIN + deltaX, ORIGIN, + paint, typeface, true, true, Paint.DIRECTION_LTR, currentTextSize); // Test with a long string - deltaX = testString(canvas, NORMAL_LONG_TEXT, ORIGIN, ORIGIN + 2 * DELTA_Y, paint, typeface, - false, false, Paint.DIRECTION_LTR); + deltaX = testString(canvas, NORMAL_LONG_TEXT, ORIGIN, ORIGIN + 2 * currentTextSize, + paint, typeface, false, false, Paint.DIRECTION_LTR, currentTextSize); + + // Test with a long string + deltaX = testString(canvas, NORMAL_LONG_TEXT_2, ORIGIN, ORIGIN + 4 * currentTextSize, + paint, typeface, false, false, Paint.DIRECTION_LTR, currentTextSize); + + // Test with a long string + deltaX = testString(canvas, NORMAL_LONG_TEXT_3, ORIGIN, ORIGIN + 6 * currentTextSize, + paint, typeface, false, false, Paint.DIRECTION_LTR, currentTextSize); // Test Arabic ligature - deltaX = testString(canvas, ARABIC_TEXT, ORIGIN, ORIGIN + 4 * DELTA_Y, paint, typeface, - false, false, Paint.DIRECTION_RTL); + deltaX = testString(canvas, ARABIC_TEXT, ORIGIN, ORIGIN + 8 * currentTextSize, + paint, typeface, false, false, Paint.DIRECTION_RTL, currentTextSize); // Test Chinese - deltaX = testString(canvas, CHINESE_TEXT, ORIGIN, ORIGIN + 6 * DELTA_Y, paint, typeface, - false, false, Paint.DIRECTION_LTR); + deltaX = testString(canvas, CHINESE_TEXT, ORIGIN, ORIGIN + 10 * currentTextSize, + paint, typeface, false, false, Paint.DIRECTION_LTR, currentTextSize); } private int testString(Canvas canvas, String text, int x, int y, Paint paint, Typeface typeface, - boolean isItalic, boolean isBold, int dir) { + boolean isItalic, boolean isBold, int dir, int textSize) { paint.setTypeface(typeface); // Set paint properties @@ -118,27 +139,28 @@ public class BiDiTestView extends View { paint.setTextSkewX(DEFAULT_ITALIC_SKEW_X); } - drawTextWithCanvasDrawText(text, canvas, x, y, TEXT_SIZE, Color.WHITE); + drawTextWithCanvasDrawText(text, canvas, x, y, textSize, Color.WHITE); int length = text.length(); float[] advances = new float[length]; - float textWidth = paint.getTextRunAdvances(text, 0, length, 0, length, 0, advances, 0); + float textWidthHB = paint.getTextRunAdvances(text, 0, length, 0, length, 0, advances, 0); + float textWidthICU = paint.getTextRunAdvancesICU(text, 0, length, 0, length, 0, advances, 0); - logAdvances(text, textWidth, advances); - drawBoxAroundText(canvas, x, y, textWidth, TEXT_SIZE, Color.RED); + logAdvances(text, textWidthHB, textWidthICU, advances); + drawMetricsAroundText(canvas, x, y, textWidthHB, textWidthICU, textSize, Color.RED, Color.GREEN); paint.setColor(Color.WHITE); char[] glyphs = new char[2*length]; int count = getGlyphs(text, glyphs, dir); - logGlypths(glyphs, count); - drawTextWithDrawGlyph(canvas, glyphs, count, x, y + DELTA_Y); +// logGlypths(glyphs, count); + drawTextWithDrawGlyph(canvas, glyphs, count, x, y + currentTextSize); // Restore old paint properties paint.setFakeBoldText(oldFakeBold); paint.setTextSkewX(oldTextSkewX); - return (int) Math.ceil(textWidth) + TEXT_PADDING; + return (int) Math.ceil(textWidthHB) + TEXT_PADDING; } private void drawTextWithDrawGlyph(Canvas canvas, char[] glyphs, int count, int x, int y) { @@ -172,19 +194,21 @@ public class BiDiTestView extends View { canvas.drawText(text, x, y, paint); } - private void drawBoxAroundText(Canvas canvas, int x, int y, float textWidth, int textSize, - int color) { + private void drawMetricsAroundText(Canvas canvas, int x, int y, float textWidthHB, + float textWidthICU, int textSize, int color, int colorICU) { paint.setColor(color); canvas.drawLine(x, y - textSize, x, y + 8, paint); - canvas.drawLine(x, y + 8, x + textWidth, y + 8, paint); - canvas.drawLine(x + textWidth, y - textSize, x + textWidth, y + 8, paint); + canvas.drawLine(x, y + 8, x + textWidthHB, y + 8, paint); + canvas.drawLine(x + textWidthHB, y - textSize, x + textWidthHB, y + 8, paint); + paint.setColor(colorICU); + canvas.drawLine(x + textWidthICU, y - textSize, x + textWidthICU, y + 8, paint); } - private void logAdvances(String text, float textWidth, float[] advances) { - Log.v(TAG, "Advances for text: " + text + " total=" + textWidth); - int length = advances.length; - for(int n=0; n<length; n++){ - Log.v(TAG, "adv[" + n + "]=" + advances[n]); - } + private void logAdvances(String text, float textWidth, float textWidthICU, float[] advances) { + Log.v(TAG, "Advances for text: " + text + " total= " + textWidth + " - totalICU= " + textWidthICU); +// int length = advances.length; +// for(int n=0; n<length; n++){ +// Log.v(TAG, "adv[" + n + "]=" + advances[n]); +// } } } |