Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Hal Canary | ea60b95 | 2018-08-21 11:45:46 -0400 | [diff] [blame] | 8 | #include "sk_tool_utils.h" |
| 9 | |
Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 10 | #include "Resources.h" |
| 11 | #include "SkCommonFlags.h" |
| 12 | #include "SkFontMgr.h" |
| 13 | #include "SkFontStyle.h" |
| 14 | #include "SkMutex.h" |
| 15 | #include "SkOSFile.h" |
Ben Wagner | 83c6b96 | 2018-07-10 19:40:15 -0400 | [diff] [blame] | 16 | #include "SkTestFontMgr.h" |
Hal Canary | ea60b95 | 2018-08-21 11:45:46 -0400 | [diff] [blame] | 17 | #include "SkTypeface.h" |
| 18 | #include "SkUTF.h" |
Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 19 | |
| 20 | namespace sk_tool_utils { |
| 21 | |
Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 22 | sk_sp<SkTypeface> emoji_typeface() { |
Ben Wagner | 97182cc | 2018-02-15 10:20:04 -0500 | [diff] [blame] | 23 | const char* filename; |
Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 24 | #if defined(SK_BUILD_FOR_WIN) |
Ben Wagner | 97182cc | 2018-02-15 10:20:04 -0500 | [diff] [blame] | 25 | filename = "fonts/colr.ttf"; |
| 26 | #elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
| 27 | filename = "fonts/sbix.ttf"; |
| 28 | #else |
| 29 | filename = "fonts/cbdt.ttf"; |
| 30 | #endif |
| 31 | sk_sp<SkTypeface> typeface = MakeResourceAsTypeface(filename); |
Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 32 | if (typeface) { |
| 33 | return typeface; |
| 34 | } |
Ben Wagner | 97182cc | 2018-02-15 10:20:04 -0500 | [diff] [blame] | 35 | return SkTypeface::MakeFromName("Emoji", SkFontStyle()); |
Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | const char* emoji_sample_text() { |
Ben Wagner | 97182cc | 2018-02-15 10:20:04 -0500 | [diff] [blame] | 39 | return "\xF0\x9F\x98\x80" " " "\xE2\x99\xA2"; // 😀 ♢ |
Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 40 | } |
Ben Wagner | 83c6b96 | 2018-07-10 19:40:15 -0400 | [diff] [blame] | 41 | static sk_sp<SkTypeface> create_font(const char* name, SkFontStyle style) { |
| 42 | static sk_sp<SkFontMgr> portableFontMgr = MakePortableFontMgr(); |
| 43 | return portableFontMgr->legacyMakeTypeface(name, style); |
| 44 | } |
| 45 | |
Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 46 | sk_sp<SkTypeface> create_portable_typeface(const char* name, SkFontStyle style) { |
| 47 | return create_font(name, style); |
| 48 | } |
Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 49 | } |