add platform_font_manager()
This string replaces {major_}platform_os_name() and platform_extra_config() for the font-focused GMs using them. The GDI bots will report "GDI", the NativeFont bots their OS, and other bots "". Change-Id: I8f7bb1ffea3cc91601c98b4ccff7a3a234ac77d3 Reviewed-on: https://skia-review.googlesource.com/70500 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
This commit is contained in:
parent
f1729a7937
commit
b251b72d3d
@ -65,8 +65,7 @@ public:
|
||||
} else {
|
||||
fFM = SkFontMgr::RefDefault();
|
||||
}
|
||||
fName.append(sk_tool_utils::platform_os_name());
|
||||
fName.append(sk_tool_utils::platform_extra_config("GDI"));
|
||||
fName.append(sk_tool_utils::platform_font_manager());
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -134,8 +133,7 @@ public:
|
||||
protected:
|
||||
SkString onShortName() override {
|
||||
SkString name("fontmgr_match");
|
||||
name.append(sk_tool_utils::platform_os_name());
|
||||
name.append(sk_tool_utils::platform_extra_config("GDI"));
|
||||
name.append(sk_tool_utils::platform_font_manager());
|
||||
return name;
|
||||
}
|
||||
|
||||
@ -223,8 +221,7 @@ public:
|
||||
if (scale != 1 || skew != 0) {
|
||||
fName.appendf("_%g_%g", scale, skew);
|
||||
}
|
||||
fName.append(sk_tool_utils::platform_os_name());
|
||||
fName.append(sk_tool_utils::platform_extra_config("GDI"));
|
||||
fName.append(sk_tool_utils::platform_font_manager());
|
||||
fFM = SkFontMgr::RefDefault();
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ protected:
|
||||
|
||||
SkString onShortName() override {
|
||||
SkString name("fontscaler");
|
||||
name.append(sk_tool_utils::major_platform_os_name());
|
||||
name.append(sk_tool_utils::platform_font_manager());
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ class GammaTextGM : public skiagm::GM {
|
||||
protected:
|
||||
SkString onShortName() override {
|
||||
SkString name("gammatext");
|
||||
name.append(sk_tool_utils::major_platform_os_name());
|
||||
name.append(sk_tool_utils::platform_font_manager());
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ protected:
|
||||
|
||||
SkString onShortName() {
|
||||
SkString name("lcdtext");
|
||||
name.append(sk_tool_utils::major_platform_os_name());
|
||||
name.append(sk_tool_utils::platform_font_manager());
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@ -66,14 +66,11 @@ protected:
|
||||
sk_tool_utils::add_to_text_blob(&builder, bigtext2, paint, 0, offset);
|
||||
|
||||
// color emoji
|
||||
sk_sp<SkTypeface> origEmoji = sk_tool_utils::emoji_typeface();
|
||||
const char* osName = sk_tool_utils::platform_os_name();
|
||||
// The mac emoji string will break us
|
||||
if (origEmoji && (!strcmp(osName, "Android") || !strcmp(osName, "Ubuntu") || !strcmp(osName, "Debian"))) {
|
||||
if (sk_sp<SkTypeface> origEmoji = sk_tool_utils::emoji_typeface()) {
|
||||
const char* emojiText = sk_tool_utils::emoji_sample_text();
|
||||
paint.measureText(emojiText, strlen(emojiText), &bounds);
|
||||
offset += bounds.height();
|
||||
paint.setTypeface(sk_make_sp<SkRandomTypeface>(orig, paint, false));
|
||||
paint.setTypeface(sk_make_sp<SkRandomTypeface>(origEmoji, paint, false));
|
||||
sk_tool_utils::add_to_text_blob(&builder, emojiText, paint, 0, offset);
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ protected:
|
||||
if (fApplyKerning) {
|
||||
name.append("_kerning");
|
||||
}
|
||||
name.append(sk_tool_utils::major_platform_os_name());
|
||||
name.append(sk_tool_utils::platform_font_manager());
|
||||
return name;
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ static void draw_typeface_rendering_gm(SkCanvas* canvas, sk_sp<SkTypeface> face,
|
||||
|
||||
DEF_SIMPLE_GM_BG_NAME(typefacerendering, canvas, 640, 680, SK_ColorWHITE,
|
||||
SkStringPrintf("typefacerendering%s",
|
||||
sk_tool_utils::major_platform_os_name().c_str())) {
|
||||
sk_tool_utils::platform_font_manager())) {
|
||||
if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("/fonts/hintgasp.ttf")) {
|
||||
draw_typeface_rendering_gm(canvas, std::move(face));
|
||||
}
|
||||
@ -279,7 +279,7 @@ DEF_SIMPLE_GM_BG_NAME(typefacerendering, canvas, 640, 680, SK_ColorWHITE,
|
||||
|
||||
DEF_SIMPLE_GM_BG_NAME(typefacerendering_pfa, canvas, 640, 680, SK_ColorWHITE,
|
||||
SkStringPrintf("typefacerendering_pfa%s",
|
||||
sk_tool_utils::major_platform_os_name().c_str())) {
|
||||
sk_tool_utils::platform_font_manager())) {
|
||||
if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/Roboto2-Regular.pfa")) {
|
||||
// This subsetted typeface doesn't have the character 'A'.
|
||||
draw_typeface_rendering_gm(canvas, std::move(face), 'O');
|
||||
@ -288,7 +288,7 @@ DEF_SIMPLE_GM_BG_NAME(typefacerendering_pfa, canvas, 640, 680, SK_ColorWHITE,
|
||||
|
||||
DEF_SIMPLE_GM_BG_NAME(typefacerendering_pfb, canvas, 640, 680, SK_ColorWHITE,
|
||||
SkStringPrintf("typefacerendering_pfb%s",
|
||||
sk_tool_utils::major_platform_os_name().c_str())) {
|
||||
sk_tool_utils::platform_font_manager())) {
|
||||
if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/Roboto2-Regular.pfb")) {
|
||||
draw_typeface_rendering_gm(canvas, std::move(face), 'O');
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ protected:
|
||||
|
||||
SkString onShortName() override {
|
||||
SkString name("verttext2");
|
||||
name.append(sk_tool_utils::major_platform_os_name());
|
||||
name.append(sk_tool_utils::platform_font_manager());
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,20 @@ static const char* gStandardFontNames[][3] = {
|
||||
{ "Tinos", "Arimo", "Cousine" } // ChromeOS
|
||||
};
|
||||
|
||||
static bool starts_with(const char* str, const char* prefix) {
|
||||
return 0 == strncmp(str, prefix, strlen(prefix));
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
const char* platform_font_name(const char* name) {
|
||||
SkString platform = major_platform_os_name();
|
||||
int index;
|
||||
if (!strcmp(name, "serif")) {
|
||||
index = 0;
|
||||
@ -44,22 +56,25 @@ const char* platform_font_name(const char* name) {
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
if (platform.equals("Mac")) {
|
||||
|
||||
const char* platform = platform_os_name();
|
||||
|
||||
if (starts_with(platform, "Mac")) {
|
||||
return gStandardFontNames[0][index];
|
||||
}
|
||||
if (platform.equals("iOS")) {
|
||||
if (starts_with(platform, "iOS")) {
|
||||
return gStandardFontNames[1][index];
|
||||
}
|
||||
if (platform.equals("Win")) {
|
||||
if (starts_with(platform, "Win")) {
|
||||
return gStandardFontNames[2][index];
|
||||
}
|
||||
if (platform.equals("Ubuntu") || platform.equals("Debian")) {
|
||||
if (starts_with(platform, "Ubuntu") || starts_with(platform, "Debian")) {
|
||||
return gStandardFontNames[3][index];
|
||||
}
|
||||
if (platform.equals("Android")) {
|
||||
if (starts_with(platform, "Android")) {
|
||||
return gStandardFontNames[4][index];
|
||||
}
|
||||
if (platform.equals("ChromeOS")) {
|
||||
if (starts_with(platform, "ChromeOS")) {
|
||||
return gStandardFontNames[5][index];
|
||||
}
|
||||
return name;
|
||||
@ -67,13 +82,15 @@ const char* platform_font_name(const char* name) {
|
||||
|
||||
const char* platform_os_emoji() {
|
||||
const char* osName = platform_os_name();
|
||||
if (!strcmp(osName, "Android") || !strcmp(osName, "Ubuntu") || !strcmp(osName, "Debian")) {
|
||||
if (starts_with(osName, "Android") ||
|
||||
starts_with(osName, "Ubuntu") ||
|
||||
starts_with(osName, "Debian")) {
|
||||
return "CBDT";
|
||||
}
|
||||
if (!strncmp(osName, "Mac", 3) || !strncmp(osName, "iOS", 3)) {
|
||||
if (starts_with(osName, "Mac") || starts_with(osName, "iOS")) {
|
||||
return "SBIX";
|
||||
}
|
||||
if (!strncmp(osName, "Win", 3)) {
|
||||
if (starts_with(osName, "Win")) {
|
||||
return "COLR";
|
||||
}
|
||||
return "";
|
||||
@ -122,41 +139,26 @@ const char* emoji_sample_text() {
|
||||
return "";
|
||||
}
|
||||
|
||||
const char* platform_os_name() {
|
||||
static bool extra_config_contains(const char* substring) {
|
||||
for (int index = 0; index < FLAGS_key.count(); index += 2) {
|
||||
if (!strcmp("os", FLAGS_key[index])) {
|
||||
return FLAGS_key[index + 1];
|
||||
if (0 == strcmp("extra_config", FLAGS_key[index])
|
||||
&& strstr(FLAGS_key[index + 1], substring)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// when running SampleApp or dm without a --key pair, omit the platform name
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* platform_font_manager() {
|
||||
if (extra_config_contains("GDI")) {
|
||||
return "GDI";
|
||||
}
|
||||
if (extra_config_contains("NativeFonts")){
|
||||
return platform_os_name();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// omit version number in returned value
|
||||
SkString major_platform_os_name() {
|
||||
SkString name;
|
||||
for (int index = 0; index < FLAGS_key.count(); index += 2) {
|
||||
if (!strcmp("os", FLAGS_key[index])) {
|
||||
const char* platform = FLAGS_key[index + 1];
|
||||
const char* end = platform;
|
||||
while (*end && (*end < '0' || *end > '9')) {
|
||||
++end;
|
||||
}
|
||||
name.append(platform, end - platform);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
const char* platform_extra_config(const char* config) {
|
||||
for (int index = 0; index < FLAGS_key.count(); index += 2) {
|
||||
if (!strcmp("extra_config", FLAGS_key[index]) && !strcmp(config, FLAGS_key[index + 1])) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
const char* colortype_name(SkColorType ct) {
|
||||
switch (ct) {
|
||||
|
@ -52,19 +52,9 @@ namespace sk_tool_utils {
|
||||
const char* platform_os_emoji();
|
||||
|
||||
/**
|
||||
* Return the platform name with the version number ("Mac10.9", "Win8", etc.) if available.
|
||||
* Returns a string describing the platform font manager, if we're using one, otherwise "".
|
||||
*/
|
||||
const char* platform_os_name();
|
||||
|
||||
/**
|
||||
* Return the platform name without the version number ("Mac", "Win", etc.) if available.
|
||||
*/
|
||||
SkString major_platform_os_name();
|
||||
|
||||
/**
|
||||
* Return the platform extra config (e.g. "GDI") if available.
|
||||
*/
|
||||
const char* platform_extra_config(const char* config);
|
||||
const char* platform_font_manager();
|
||||
|
||||
/**
|
||||
* Map serif, san-serif, and monospace to the platform-specific font name.
|
||||
|
Loading…
Reference in New Issue
Block a user