diff options
author | Mike Reed <> | 2009-03-25 16:03:47 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-25 16:03:47 -0700 |
commit | 60018267cf9b91fc4eb58ecb5b559b8dc5c454a7 (patch) | |
tree | d865f48084691c972b87ac7483dcec00efb8da1b | |
parent | 2541007b6f82bd777b3e938271a9ec0c20ae5cc8 (diff) | |
download | external_skia-60018267cf9b91fc4eb58ecb5b559b8dc5c454a7.zip external_skia-60018267cf9b91fc4eb58ecb5b559b8dc5c454a7.tar.gz external_skia-60018267cf9b91fc4eb58ecb5b559b8dc5c454a7.tar.bz2 |
Automated import from //branches/master/...@142750,142750
-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 3a794d0..5999325 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 22192b8..1c8aef5 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 { |