Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(769)

Unified Diff: gm/coloremoji.cpp

Issue 797043002: Add sbix font to coloremoji gm. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Create string from explicit utf-8. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/coloremoji.cpp
diff --git a/gm/coloremoji.cpp b/gm/coloremoji.cpp
index 5d8c6ba8e3c3979a3bdef8166f984734acccb9df..8276ea8974ecd42464e52811689884ec6c07a0dc 100644
--- a/gm/coloremoji.cpp
+++ b/gm/coloremoji.cpp
@@ -46,23 +46,32 @@ namespace skiagm {
class ColorEmojiGM : public GM {
public:
- ColorEmojiGM() {
- fTypeface = NULL;
- }
+ ColorEmojiGM() : fCBDT_CBLC_Typeface(NULL), fSBIX_Typeface(NULL) { }
- ~ColorEmojiGM() {
- SkSafeUnref(fTypeface);
- }
protected:
- void onOnceBeforeDraw() SK_OVERRIDE {
+ struct EmojiFont {
+ SkTypeface* typeface;
+ const char* text;
+ } emojiFonts[2];
+ virtual void onOnceBeforeDraw() SK_OVERRIDE {
SkString filename = GetResourcePath("/Funkster.ttf");
SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
- if (!stream->isValid()) {
+ if (stream->isValid()) {
+ fCBDT_CBLC_Typeface.reset(SkTypeface::CreateFromStream(stream.detach()));
+ emojiFonts[0].typeface = fCBDT_CBLC_Typeface;
+ } else {
SkDebugf("Could not find Funkster.ttf, please set --resourcePath correctly.\n");
- return;
+ emojiFonts[0].typeface = NULL;
}
-
- fTypeface = SkTypeface::CreateFromStream(stream.detach());
+ emojiFonts[0].text = "hamburgerfons";
+
+ fSBIX_Typeface.reset(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kNormal));
+ emojiFonts[1].typeface = fSBIX_Typeface;
+ emojiFonts[1].text = "\xF0\x9F\x92\xB0" "\xF0\x9F\x8F\xA1" "\xF0\x9F\x8E\x85" // πŸ’°πŸ‘πŸŽ…
+ "\xF0\x9F\x8D\xAA" "\xF0\x9F\x8D\x95" "\xF0\x9F\x9A\x80" // πŸͺπŸ•πŸš€
+ "\xF0\x9F\x9A\xBB" "\xF0\x9F\x92\xA9" "\xF0\x9F\x93\xB7" // πŸš»πŸ’©πŸ“·
+ "\xF0\x9F\x93\xA6" // πŸ“¦
+ "\xF0\x9F\x87\xBA" "\xF0\x9F\x87\xB8" "\xF0\x9F\x87\xA6"; // πŸ‡ΊπŸ‡ΈπŸ‡¦
}
SkString onShortName() SK_OVERRIDE {
@@ -70,98 +79,101 @@ protected:
}
SkISize onISize() SK_OVERRIDE {
- return SkISize::Make(650, 480);
+ return SkISize::Make(650, 900);
}
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
canvas->drawColor(SK_ColorGRAY);
- SkPaint paint;
- paint.setTypeface(fTypeface);
-
- const char* text = "hamburgerfons";
-
- // draw text at different point sizes
- const int textSize[] = { 10, 30, 50, };
- const int textYOffset[] = { 10, 40, 100, };
- SkASSERT(sizeof(textSize) == sizeof(textYOffset));
- size_t y_offset = 0;
- for (size_t y = 0; y < sizeof(textSize) / sizeof(int); y++) {
- paint.setTextSize(SkIntToScalar(textSize[y]));
- canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffset[y]), paint);
- y_offset += textYOffset[y];
- }
-
- // draw with shaders and image filters
- for (int i = 0; i < 2; i++) {
- for (int j = 0; j < 2; j++) {
- for (int k = 0; k < 2; k++) {
- SkPaint shaderPaint;
- shaderPaint.setTypeface(fTypeface);
- if (SkToBool(i)) {
- shaderPaint.setShader(MakeLinear())->unref();
- }
+ for (size_t i = 0; i < SK_ARRAY_COUNT(emojiFonts); ++i) {
+ SkPaint paint;
+ paint.setTypeface(emojiFonts[i].typeface);
+ const char* text = emojiFonts[i].text;
+
+ // draw text at different point sizes
+ const int textSize[] = { 10, 30, 50, };
+ const int textYOffset[] = { 10, 40, 100, };
+ SkASSERT(sizeof(textSize) == sizeof(textYOffset));
+ size_t y_offset = 0;
+ for (size_t y = 0; y < sizeof(textSize) / sizeof(int); y++) {
+ paint.setTextSize(SkIntToScalar(textSize[y]));
+ canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffset[y]), paint);
+ y_offset += textYOffset[y];
+ }
- if (SkToBool(j) && SkToBool(k)) {
- SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(NULL));
- SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, grayScale));
- shaderPaint.setImageFilter(blur);
- } else if (SkToBool(j)) {
- SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, NULL));
- shaderPaint.setImageFilter(blur);
- } else if (SkToBool(k)) {
- SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(NULL));
- shaderPaint.setImageFilter(grayScale);
+ // draw with shaders and image filters
+ for (int makeLinear = 0; makeLinear < 2; makeLinear++) {
+ for (int makeBlur = 0; makeBlur < 2; makeBlur++) {
+ for (int makeGray = 0; makeGray < 2; makeGray++) {
+ SkPaint shaderPaint;
+ shaderPaint.setTypeface(paint.getTypeface());
+ if (SkToBool(makeLinear)) {
+ shaderPaint.setShader(MakeLinear())->unref();
+ }
+
+ if (SkToBool(makeBlur) && SkToBool(makeGray)) {
+ SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(NULL));
+ SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, grayScale));
+ shaderPaint.setImageFilter(blur);
+ } else if (SkToBool(makeBlur)) {
+ SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, NULL));
+ shaderPaint.setImageFilter(blur);
+ } else if (SkToBool(makeGray)) {
+ SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(NULL));
+ shaderPaint.setImageFilter(grayScale);
+ }
+ shaderPaint.setTextSize(30);
+ canvas->drawText(text, strlen(text), 380, SkIntToScalar(y_offset),
+ shaderPaint);
+ y_offset += 32;
}
- shaderPaint.setTextSize(30);
- canvas->drawText(text, strlen(text), 380, SkIntToScalar(y_offset), shaderPaint);
- y_offset += 32;
}
}
- }
- // setup work needed to draw text with different clips
- canvas->translate(10, 160);
- paint.setTextSize(40);
-
- // compute the bounds of the text
- SkRect bounds;
- paint.measureText(text, strlen(text), &bounds);
-
- const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf;
- const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf;
- const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf;
- const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf;
-
- SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(),
- boundsHalfWidth, boundsHalfHeight);
- SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.centerY(),
- boundsHalfWidth, boundsHalfHeight);
- SkRect interiorClip = bounds;
- interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight);
-
- const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, interiorClip };
-
- SkPaint clipHairline;
- clipHairline.setColor(SK_ColorWHITE);
- clipHairline.setStyle(SkPaint::kStroke_Style);
-
- for (size_t x = 0; x < sizeof(clipRects) / sizeof(SkRect); ++x) {
- canvas->save();
- canvas->drawRect(clipRects[x], clipHairline);
- paint.setAlpha(0x20);
- canvas->drawText(text, strlen(text), 0, 0, paint);
- canvas->clipRect(clipRects[x]);
- paint.setAlpha(0xFF);
- canvas->drawText(text, strlen(text), 0, 0, paint);
- canvas->restore();
- canvas->translate(0, bounds.height() + SkIntToScalar(25));
+ // setup work needed to draw text with different clips
+ canvas->translate(10, 160);
+ paint.setTextSize(40);
+
+ // compute the bounds of the text
+ SkRect bounds;
+ paint.measureText(text, strlen(text), &bounds);
+
+ const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf;
+ const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf;
+ const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf;
+ const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf;
+
+ SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(),
+ boundsHalfWidth, boundsHalfHeight);
+ SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.centerY(),
+ boundsHalfWidth, boundsHalfHeight);
+ SkRect interiorClip = bounds;
+ interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight);
+
+ const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, interiorClip };
+
+ SkPaint clipHairline;
+ clipHairline.setColor(SK_ColorWHITE);
+ clipHairline.setStyle(SkPaint::kStroke_Style);
+
+ for (size_t x = 0; x < sizeof(clipRects) / sizeof(SkRect); ++x) {
+ canvas->save();
+ canvas->drawRect(clipRects[x], clipHairline);
+ paint.setAlpha(0x20);
+ canvas->drawText(text, strlen(text), 0, 0, paint);
+ canvas->clipRect(clipRects[x]);
+ paint.setAlpha(0xFF);
+ canvas->drawText(text, strlen(text), 0, 0, paint);
+ canvas->restore();
+ canvas->translate(0, bounds.height() + SkIntToScalar(25));
+ }
}
}
private:
- SkTypeface* fTypeface;
+ SkAutoTUnref<SkTypeface> fCBDT_CBLC_Typeface;
+ SkAutoTUnref<SkTypeface> fSBIX_Typeface;
typedef GM INHERITED;
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698