2018-02-20 22:06:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2018-08-21 15:45:46 +00:00
|
|
|
#include "sk_tool_utils.h"
|
|
|
|
|
2018-02-20 22:06:07 +00:00
|
|
|
#include "Resources.h"
|
|
|
|
#include "SkCommonFlags.h"
|
|
|
|
#include "SkFontMgr.h"
|
|
|
|
#include "SkFontStyle.h"
|
|
|
|
#include "SkMutex.h"
|
|
|
|
#include "SkOSFile.h"
|
2018-07-10 23:40:15 +00:00
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkTestFontMgr.h"
|
2018-08-21 15:45:46 +00:00
|
|
|
#include "SkTypeface.h"
|
|
|
|
#include "SkUTF.h"
|
2018-02-20 22:06:07 +00:00
|
|
|
|
|
|
|
namespace sk_tool_utils {
|
|
|
|
|
|
|
|
sk_sp<SkTypeface> emoji_typeface() {
|
2018-02-15 15:20:04 +00:00
|
|
|
const char* filename;
|
2018-02-20 22:06:07 +00:00
|
|
|
#if defined(SK_BUILD_FOR_WIN)
|
2018-02-15 15:20:04 +00:00
|
|
|
filename = "fonts/colr.ttf";
|
2018-03-27 18:15:53 +00:00
|
|
|
#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
2018-02-15 15:20:04 +00:00
|
|
|
filename = "fonts/sbix.ttf";
|
2018-03-27 18:15:53 +00:00
|
|
|
#else
|
2018-02-15 15:20:04 +00:00
|
|
|
filename = "fonts/cbdt.ttf";
|
2018-03-27 18:15:53 +00:00
|
|
|
#endif
|
2018-02-15 15:20:04 +00:00
|
|
|
sk_sp<SkTypeface> typeface = MakeResourceAsTypeface(filename);
|
|
|
|
if (typeface) {
|
|
|
|
return typeface;
|
|
|
|
}
|
|
|
|
return SkTypeface::MakeFromName("Emoji", SkFontStyle());
|
2018-02-20 22:06:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* emoji_sample_text() {
|
2018-02-15 15:20:04 +00:00
|
|
|
return "\xF0\x9F\x98\x80" " " "\xE2\x99\xA2"; // 😀 ♢
|
2018-02-20 22:06:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char* platform_os_name() {
|
|
|
|
for (int index = 0; index < FLAGS_key.count(); index += 2) {
|
|
|
|
if (!strcmp("os", FLAGS_key[index])) {
|
|
|
|
return FLAGS_key[index + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool extra_config_contains(const char* substring) {
|
|
|
|
for (int index = 0; index < FLAGS_key.count(); index += 2) {
|
|
|
|
if (0 == strcmp("extra_config", FLAGS_key[index])
|
|
|
|
&& strstr(FLAGS_key[index + 1], substring)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* platform_font_manager() {
|
|
|
|
if (extra_config_contains("GDI")) {
|
|
|
|
return "GDI";
|
|
|
|
}
|
|
|
|
if (extra_config_contains("NativeFonts")){
|
|
|
|
return platform_os_name();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2018-07-10 23:40:15 +00:00
|
|
|
static sk_sp<SkTypeface> create_font(const char* name, SkFontStyle style) {
|
|
|
|
static sk_sp<SkFontMgr> portableFontMgr = MakePortableFontMgr();
|
|
|
|
return portableFontMgr->legacyMakeTypeface(name, style);
|
|
|
|
}
|
|
|
|
|
2018-02-20 22:06:07 +00:00
|
|
|
sk_sp<SkTypeface> create_portable_typeface(const char* name, SkFontStyle style) {
|
|
|
|
return create_font(name, style);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_portable_typeface(SkPaint* paint, const char* name, SkFontStyle style) {
|
|
|
|
paint->setTypeface(create_font(name, style));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|