diff options
author | Eric Fischer <> | 2009-03-27 15:52:38 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-27 15:52:38 -0700 |
commit | c2d54f46ac13e029e6d53f7471cd9c90fe6bbfe9 (patch) | |
tree | e9eaaa3ec99ec64a326ba844f8b48e0530398ca5 | |
parent | 3b840af148766f6214c36f4a845dd5b26b18819d (diff) | |
download | frameworks_base-c2d54f46ac13e029e6d53f7471cd9c90fe6bbfe9.zip frameworks_base-c2d54f46ac13e029e6d53f7471cd9c90fe6bbfe9.tar.gz frameworks_base-c2d54f46ac13e029e6d53f7471cd9c90fe6bbfe9.tar.bz2 |
AI 143165: am: CL 142861 Make TextView Emoji scale to match the size of the text.
Original author: enf
Merged from: //branches/cupcake/...
Automated import of CL 143165
-rw-r--r-- | core/java/android/text/Layout.java | 61 | ||||
-rw-r--r-- | core/java/android/text/StaticLayout.java | 14 |
2 files changed, 58 insertions, 17 deletions
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java index 23e740d..a6ed922 100644 --- a/core/java/android/text/Layout.java +++ b/core/java/android/text/Layout.java @@ -21,6 +21,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; +import android.graphics.RectF; import android.graphics.Path; import com.android.internal.util.ArrayUtils; import android.util.Config; @@ -52,6 +53,8 @@ public abstract class Layout { } }; + private RectF mEmojiRect; + /** * Return how wide a layout would be necessary to display the * specified text with one line per paragraph. @@ -1327,7 +1330,7 @@ public abstract class Layout { return right; } - private static void drawText(Canvas canvas, + private void drawText(Canvas canvas, CharSequence text, int start, int end, int dir, Directions directions, float x, int top, int y, int bottom, @@ -1384,8 +1387,26 @@ public abstract class Layout { top, y, bottom, paint, workPaint, start + j != end); - canvas.drawBitmap(bm, x + h, y - bm.getHeight(), paint); - h += bm.getWidth(); + if (mEmojiRect == null) { + mEmojiRect = new RectF(); + } + + workPaint.set(paint); + Styled.measureText(paint, workPaint, text, + start + j, start + j + 1, + null); + + float bitmapHeight = bm.getHeight(); + float textHeight = -workPaint.ascent(); + float scale = textHeight / bitmapHeight; + float width = bm.getWidth() * scale; + + mEmojiRect.set(x + h, y - textHeight, + x + h + width, y); + + canvas.drawBitmap(bm, null, mEmojiRect, paint); + h += width; + j++; segstart = j + 1; } @@ -1503,10 +1524,17 @@ public abstract class Layout { } if (bm != null) { + workPaint.set(paint); + Styled.measureText(paint, workPaint, text, + offset, offset + 1, null); + + float wid = (float) bm.getWidth() * + -workPaint.ascent() / bm.getHeight(); + if (dir == DIR_RIGHT_TO_LEFT) { - h -= bm.getWidth(); + h -= wid; } else { - h += bm.getWidth(); + h += wid; } j++; @@ -1587,7 +1615,14 @@ public abstract class Layout { if (bm == null) { h = nextTab(text, start, end, h, tabs); } else { - h += bm.getWidth(); + workPaint.set(paint); + Styled.measureText(paint, workPaint, text, + start + i, start + i + 1, null); + + float wid = (float) bm.getWidth() * + -workPaint.ascent() / bm.getHeight(); + + h += wid; i++; } } @@ -1607,16 +1642,10 @@ public abstract class Layout { bot = fm.bottom; } - if (bm != null) { - int ht = -bm.getHeight(); - - if (ht < ab) { - ab = ht; - } - if (ht < top) { - top = ht; - } - } + /* + * No need to take bitmap height into account here, + * since it is scaled to match the text height. + */ } here = i + 1; diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java index 720d15a..686e8f5 100644 --- a/core/java/android/text/StaticLayout.java +++ b/core/java/android/text/StaticLayout.java @@ -567,7 +567,19 @@ extends Layout getBitmapFromAndroidPua(emoji); if (bm != null) { - w += bm.getWidth(); + Paint whichPaint; + + if (spanned == null) { + whichPaint = paint; + } else { + whichPaint = mWorkPaint; + } + + float wid = (float) bm.getWidth() * + -whichPaint.ascent() / + bm.getHeight(); + + w += wid; tab = true; j++; } else { |