diff options
author | Fabrice Di Meglio <fdimeglio@google.com> | 2011-03-24 17:21:23 -0700 |
---|---|---|
committer | Fabrice Di Meglio <fdimeglio@google.com> | 2011-03-29 19:44:33 -0700 |
commit | eee49c699c035ffba188417489f40d34f587d65c (patch) | |
tree | 09e0aff1a1d1adb13fd6389406ed35a6a6b98d21 /tests/BiDiTests/src | |
parent | a3cbe69ae693004b2fa459d95578b4b3189c86fb (diff) | |
download | frameworks_base-eee49c699c035ffba188417489f40d34f587d65c.zip frameworks_base-eee49c699c035ffba188417489f40d34f587d65c.tar.gz frameworks_base-eee49c699c035ffba188417489f40d34f587d65c.tar.bz2 |
Fix text redering issue where the text was sometimes truncated
- mostly was visible in Settings apps / Wi-Fi networks summary info for each network
- correctly setup the local SkPaint for advances computation
- improve test app for adding live resizing
Change-Id: Ia031fe1b115b521ba55c7e68f2a26300f02e48ca
Diffstat (limited to 'tests/BiDiTests/src')
3 files changed, 109 insertions, 35 deletions
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java index 3d7dd81..6c71574 100644 --- a/tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java +++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java @@ -20,16 +20,44 @@ import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; +import android.widget.SeekBar; + +import static com.android.bidi.BiDiTestConstants.FONT_MIN_SIZE; +import static com.android.bidi.BiDiTestConstants.FONT_MAX_SIZE; public class BiDiTestActivity extends Activity { static final String TAG = "BiDiTestActivity"; + static final int INIT_TEXT_SIZE = (FONT_MAX_SIZE - FONT_MIN_SIZE) / 2; + + private BiDiTestView textView; + private SeekBar textSizeSeekBar; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.biditest_main); + + textView = (BiDiTestView) findViewById(R.id.main); + textView.setCurrentTextSize(INIT_TEXT_SIZE); + + textSizeSeekBar = (SeekBar) findViewById(R.id.seekbar); + textSizeSeekBar.setProgress(INIT_TEXT_SIZE); + textSizeSeekBar.setMax(FONT_MAX_SIZE - FONT_MIN_SIZE); + + textSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + textView.setCurrentTextSize(FONT_MIN_SIZE + progress); + } + + public void onStartTrackingTouch(SeekBar seekBar) { + } + + public void onStopTrackingTouch(SeekBar seekBar) { + } + }); } @Override diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestConstants.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestConstants.java new file mode 100644 index 0000000..5c28e3d --- /dev/null +++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestConstants.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * 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. + */ + +package com.android.bidi; + +public class BiDiTestConstants { + public static final int FONT_MIN_SIZE = 8; + public static final int FONT_MAX_SIZE = 72; +} 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]); +// } } } |