diff options
author | Mike Reed <> | 2009-03-25 15:10:50 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-25 15:10:50 -0700 |
commit | 07b2c540eeca2e21cfbe412a0737ae84e9f7a8ef (patch) | |
tree | f712eb3fe2a6e21d7b9fdaae5b85c938b9c8a027 | |
parent | 47cd11d498fde65407846d4a223951cd4610d205 (diff) | |
download | skia-android-sdk-1.5_r1.tar.gz |
Automated import from //branches/cupcake/...@142604,142604android-sdk-1.5_r3android-sdk-1.5_r1android-sdk-1.5-preandroid-1.5r4android-1.5r3android-1.5r2android-1.5cupcake-release
-rw-r--r-- | emoji/EmojiFont.cpp | 22 | ||||
-rw-r--r-- | emoji/EmojiFont.h | 4 |
2 files changed, 17 insertions, 9 deletions
diff --git a/emoji/EmojiFont.cpp b/emoji/EmojiFont.cpp index 3a794d0f69..5999325421 100644 --- a/emoji/EmojiFont.cpp +++ b/emoji/EmojiFont.cpp @@ -142,7 +142,7 @@ uint16_t EmojiFont::UnicharToGlyph(int32_t unichar) { return 0; } -SkScalar EmojiFont::GetAdvanceWidth(uint16_t glyphID) { +SkScalar EmojiFont::GetAdvanceWidth(uint16_t glyphID, const SkPaint& paint) { if (glyphID < kGlyphBase) { SkDebugf("-------- bad glyph passed to EmojiFont::GetAdvanceWidth %d\n", glyphID); @@ -154,20 +154,28 @@ SkScalar EmojiFont::GetAdvanceWidth(uint16_t glyphID) { return 0; } - // add one for 1-pixel right-side-bearing - return SkIntToScalar(bitmap->width() + 1); + // assume that our advance width is always the pointsize + return paint.getTextSize(); } +/* This tells us to shift the emoji bounds down by 20% below the baseline, + to better align with the Kanji characters' placement in the line. + */ +static const SkScalar gBaselinePercentDrop = SkFloatToScalar(0.2f); + void EmojiFont::Draw(SkCanvas* canvas, uint16_t glyphID, - SkScalar x, SkScalar y, const SkPaint* paint) { + SkScalar x, SkScalar y, const SkPaint& paint) { if (glyphID < kGlyphBase) { SkDebugf("-------- bad glyph passed to EmojiFont::Draw %d\n", glyphID); } const SkBitmap* bitmap = get_bitmap(glyphID - kGlyphBase); - if (bitmap) { - canvas->drawBitmap(*bitmap, x, y - SkIntToScalar(bitmap->height()), - paint); + if (bitmap && !bitmap->empty()) { + SkRect dst; + SkScalar size = paint.getTextSize(); + y += SkScalarMul(size, gBaselinePercentDrop); + dst.set(x, y - size, x + size, y); + canvas->drawBitmapRect(*bitmap, NULL, dst, &paint); } } diff --git a/emoji/EmojiFont.h b/emoji/EmojiFont.h index 22192b8a1c..1c8aef55f1 100644 --- a/emoji/EmojiFont.h +++ b/emoji/EmojiFont.h @@ -54,14 +54,14 @@ namespace android { /** Returns the advance width for the specified emoji form. */ - static SkScalar GetAdvanceWidth(uint16_t index); + static SkScalar GetAdvanceWidth(uint16_t index, const SkPaint& paint); /** Draw the specified emoji form, given the x,y origin of the text version. The paint is the one associated with the text that has the emoji in it. */ static void Draw(SkCanvas*, uint16_t index, SkScalar x, SkScalar y, - const SkPaint* paintOrNull); + const SkPaint& paint); private: enum { |