From b251b72d3d91fb7976f7984ae60793c87d0dae4c Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Mon, 13 Nov 2017 11:03:16 -0500 Subject: 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 Commit-Queue: Mike Klein --- tools/sk_tool_utils.cpp | 74 +++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 36 deletions(-) (limited to 'tools/sk_tool_utils.cpp') diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp index 56c1f48ed9..d2063dfd88 100644 --- a/tools/sk_tool_utils.cpp +++ b/tools/sk_tool_utils.cpp @@ -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,42 +139,27 @@ 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 ""; + return false; } -// 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; - } +const char* platform_font_manager() { + if (extra_config_contains("GDI")) { + return "GDI"; } - 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; - } + if (extra_config_contains("NativeFonts")){ + return platform_os_name(); } return ""; } + const char* colortype_name(SkColorType ct) { switch (ct) { case kUnknown_SkColorType: return "Unknown"; -- cgit v1.2.3