aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar djsollen <djsollen@google.com>2014-08-27 07:03:13 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-27 07:03:13 -0700
commit0d393a92ca6c1a328e4fa0c4b311916789659de5 (patch)
tree1ced71ebdc2cf3d9c65b1f0b4c775428659a96b3 /gm
parent5219e57a021303444ecd7e054fd56a9efc884904 (diff)
Lookup glyphs based on character code and language tag.
This is particularly important on Android where we expect the FontManager to return different glyphs for the same character code depending on language. BUG=skia:2829 R=bungeman@google.com, tomhudson@google.com Author: djsollen@google.com Review URL: https://codereview.chromium.org/492763003
Diffstat (limited to 'gm')
-rw-r--r--gm/fontmgr.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/gm/fontmgr.cpp b/gm/fontmgr.cpp
index d9a0aa5f4b..79868982f4 100644
--- a/gm/fontmgr.cpp
+++ b/gm/fontmgr.cpp
@@ -24,6 +24,31 @@ static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x,
return x + paint.measureText(text.c_str(), text.size());
}
+static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
+ SkScalar y, SkPaint& paint, SkFontMgr* fm,
+ const char* fontName, const char* bpc47,
+ const SkFontStyle& fontStyle) {
+ // find typeface containing the requested character and draw it
+ SkString ch;
+ ch.appendUnichar(character);
+ SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle, bpc47, character);
+ SkSafeUnref(paint.setTypeface(typeface));
+ x = drawString(canvas, ch, x, y, paint) + 20;
+
+ if (NULL == typeface) {
+ return x;
+ }
+
+ // repeat the process, but this time use the family name of the typeface
+ // from the first pass. This emulates the behavior in Blink where it
+ // it expects to get the same glyph when following this pattern.
+ SkString familyName;
+ typeface->getFamilyName(&familyName);
+ SkTypeface* typefaceCopy = fm->legacyCreateTypeface(familyName.c_str(), typeface->style());
+ SkSafeUnref(paint.setTypeface(typefaceCopy));
+ return drawString(canvas, ch, x, y, paint) + 20;
+}
+
class FontMgrGM : public skiagm::GM {
public:
FontMgrGM(SkFontMgr* fontMgr = NULL) {
@@ -44,7 +69,7 @@ protected:
}
virtual SkISize onISize() {
- return SkISize::Make(640, 1024);
+ return SkISize::Make(1536, 768);
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
@@ -75,6 +100,12 @@ protected:
SkSafeUnref(paint.setTypeface(set->createTypeface(j)));
x = drawString(canvas, sname, x, y, paint) + 20;
+
+ // check to see that we get different glyphs in japanese and chinese
+ x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str(), "zh", fs);
+ x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str(), "ja", fs);
+ // check that emoji characters are found
+ x = drawCharacter(canvas, 0x1f601, x, y, paint, fm, fName.c_str(), NULL, fs);
}
y += 24;
}