From 37213558e6d269807cde031e59b9567d0db6e471 Mon Sep 17 00:00:00 2001 From: caryclark Date: Fri, 24 Jul 2015 11:08:01 -0700 Subject: make fontscalar gammatext lcdtext typeface verttext2 gm portable Pass generic font names to tool util function to generate platform specific fonts and gm test output by unique name. R=bungeman@google.com Review URL: https://codereview.chromium.org/1256903002 --- tools/sk_tool_utils.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) (limited to 'tools/sk_tool_utils.cpp') diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp index 9ab86edf2f..4897938f00 100644 --- a/tools/sk_tool_utils.cpp +++ b/tools/sk_tool_utils.cpp @@ -17,10 +17,52 @@ #include "SkTextBlob.h" DEFINE_bool(portableFonts, false, "Use portable fonts"); -DEFINE_bool(resourceFonts, false, "Use resource fonts"); namespace sk_tool_utils { +/* these are the default fonts chosen by Chrome for serif, sans-serif, and monospace */ +static const char* gStandardFontNames[][3] = { + { "Times", "Helvetica", "Courier" }, // Mac + { "Times New Roman", "Helvetica", "Courier" }, // iOS + { "Times New Roman", "Arial", "Courier New" }, // Win + { "Times New Roman", "Arial", "Monospace" }, // Ubuntu + { "Droid Serif", "Droid Sans", "Droid Sans Mono" }, // Android + { "Tinos", "Arimo", "Cousine" } // ChromeOS +}; + +const char* platform_font_name(const char* name) { + SkString platform = major_platform_os_name(); + int index; + if (!strcmp(name, "serif")) { + index = 0; + } else if (!strcmp(name, "san-serif")) { + index = 1; + } else if (!strcmp(name, "monospace")) { + index = 2; + } else { + return name; + } + if (platform.equals("Mac")) { + return gStandardFontNames[0][index]; + } + if (platform.equals("iOS")) { + return gStandardFontNames[1][index]; + } + if (platform.equals("Win")) { + return gStandardFontNames[2][index]; + } + if (platform.equals("Ubuntu")) { + return gStandardFontNames[3][index]; + } + if (platform.equals("Android")) { + return gStandardFontNames[4][index]; + } + if (platform.equals("ChromeOS")) { + return gStandardFontNames[5][index]; + } + return name; +} + const char* platform_os_emoji() { const char* osName = platform_os_name(); if (!strcmp(osName, "Android") || !strcmp(osName, "Ubuntu")) { @@ -69,6 +111,23 @@ const char* 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])) { @@ -103,8 +162,6 @@ SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style) SkTypeface* face; if (FLAGS_portableFonts) { face = create_font(name, style); - } else if (FLAGS_resourceFonts) { - face = resource_font(name, style); } else { face = SkTypeface::CreateFromName(name, style); } -- cgit v1.2.3