aboutsummaryrefslogtreecommitdiffstats
path: root/emoji
diff options
context:
space:
mode:
Diffstat (limited to 'emoji')
-rw-r--r--emoji/EmojiFont.cpp22
-rw-r--r--emoji/EmojiFont.h4
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 {