From c74f45a334f0e3725c23cdd270cbcb0efac4ea75 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Tue, 26 Feb 2013 19:10:14 -0800 Subject: Properly scale text This change does not apply to drawPosText() and drawTextOnPath() yet. Prior to this change, glyphs were always rasterized based on the font size specified in the paint. All transforms were then applied on the resulting texture. This creates rather ugly results when text is scaled and/or rotated. With this change, the font renderer will apply the current transform matrix to the glyph before they are rasterized. This generates much better looking results. Change-Id: I0141b6ff18db35e1213e7a3ab9db1ecaf03d7a9c --- .../com/android/test/hwui/ScaledTextActivity.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'tests/HwAccelerationTest/src') diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ScaledTextActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ScaledTextActivity.java index e1bf3ea..a4e9b52 100644 --- a/tests/HwAccelerationTest/src/com/android/test/hwui/ScaledTextActivity.java +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ScaledTextActivity.java @@ -54,6 +54,7 @@ public class ScaledTextActivity extends Activity { public ScaledTextView(Context c) { super(c); + setLayerType(LAYER_TYPE_HARDWARE, null); mPath = makePath(); @@ -92,11 +93,28 @@ public class ScaledTextActivity extends Activity { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); - canvas.drawARGB(255, 255, 255, 255); canvas.drawText(TEXT, 30.0f, 30.0f, mPaint); + mPaint.setTextAlign(Paint.Align.CENTER); + canvas.drawText(TEXT, 30.0f, 50.0f, mPaint); + mPaint.setTextAlign(Paint.Align.RIGHT); + canvas.drawText(TEXT, 30.0f, 70.0f, mPaint); - canvas.translate(0.0f, 50.0f); + canvas.save(); + canvas.translate(400.0f, 0.0f); + canvas.scale(3.0f, 3.0f); + mPaint.setTextAlign(Paint.Align.LEFT); + mPaint.setStrikeThruText(true); + canvas.drawText(TEXT, 30.0f, 30.0f, mPaint); + mPaint.setStrikeThruText(false); + mPaint.setTextAlign(Paint.Align.CENTER); + canvas.drawText(TEXT, 30.0f, 50.0f, mPaint); + mPaint.setTextAlign(Paint.Align.RIGHT); + canvas.drawText(TEXT, 30.0f, 70.0f, mPaint); + canvas.restore(); + + mPaint.setTextAlign(Paint.Align.LEFT); + canvas.translate(0.0f, 100.0f); canvas.save(); canvas.scale(mScale, mScale); -- cgit v1.1