aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Reed <>2009-03-25 15:10:50 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-25 15:10:50 -0700
commit07b2c540eeca2e21cfbe412a0737ae84e9f7a8ef (patch)
treef712eb3fe2a6e21d7b9fdaae5b85c938b9c8a027
parent47cd11d498fde65407846d4a223951cd4610d205 (diff)
downloadskia-android-sdk-1.5_r1.tar.gz
-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 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 {