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
8 #include "sk_tool_utils.h"
9
10 #include "Resources.h"
11 #include "SkCommonFlags.h"
12 #include "SkFontMgr.h"
13 #include "SkFontStyle.h"
14 #include "SkMutex.h"
15 #include "SkOSFile.h"
16 #include "SkTestFontMgr.h"
17 #include "SkTypeface.h"
18 #include "SkUTF.h"
19
20 namespace sk_tool_utils {
21
emoji_typeface()22 sk_sp<SkTypeface> emoji_typeface() {
23 const char* filename;
24 #if defined(SK_BUILD_FOR_WIN)
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);
32 if (typeface) {
33 return typeface;
34 }
35 return SkTypeface::MakeFromName("Emoji", SkFontStyle());
36 }
37
emoji_sample_text()38 const char* emoji_sample_text() {
39 return "\xF0\x9F\x98\x80" " " "\xE2\x99\xA2"; // ♢
40 }
41
platform_os_name()42 static const char* platform_os_name() {
43 for (int index = 0; index < FLAGS_key.count(); index += 2) {
44 if (!strcmp("os", FLAGS_key[index])) {
45 return FLAGS_key[index + 1];
46 }
47 }
48 return "";
49 }
50
extra_config_contains(const char * substring)51 static bool extra_config_contains(const char* substring) {
52 for (int index = 0; index < FLAGS_key.count(); index += 2) {
53 if (0 == strcmp("extra_config", FLAGS_key[index])
54 && strstr(FLAGS_key[index + 1], substring)) {
55 return true;
56 }
57 }
58 return false;
59 }
60
platform_font_manager()61 const char* platform_font_manager() {
62 if (extra_config_contains("GDI")) {
63 return "GDI";
64 }
65 if (extra_config_contains("NativeFonts")){
66 return platform_os_name();
67 }
68 return "";
69 }
70
create_font(const char * name,SkFontStyle style)71 static sk_sp<SkTypeface> create_font(const char* name, SkFontStyle style) {
72 static sk_sp<SkFontMgr> portableFontMgr = MakePortableFontMgr();
73 return portableFontMgr->legacyMakeTypeface(name, style);
74 }
75
create_portable_typeface(const char * name,SkFontStyle style)76 sk_sp<SkTypeface> create_portable_typeface(const char* name, SkFontStyle style) {
77 return create_font(name, style);
78 }
79 }
80