Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: tools/sk_tool_utils.cpp

Issue 1256903002: make fontscalar gammatext lcdtext typeface verttext2 gm portable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove useless gm; fix nit Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/sk_tool_utils.h ('k') | tools/sk_tool_utils_font.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "sk_tool_utils.h" 8 #include "sk_tool_utils.h"
9 #include "sk_tool_utils_flags.h" 9 #include "sk_tool_utils_flags.h"
10 10
11 #include "Resources.h" 11 #include "Resources.h"
12 #include "SkBitmap.h" 12 #include "SkBitmap.h"
13 #include "SkCanvas.h" 13 #include "SkCanvas.h"
14 #include "SkCommonFlags.h" 14 #include "SkCommonFlags.h"
15 #include "SkShader.h" 15 #include "SkShader.h"
16 #include "SkTestScalerContext.h" 16 #include "SkTestScalerContext.h"
17 #include "SkTextBlob.h" 17 #include "SkTextBlob.h"
18 18
19 DEFINE_bool(portableFonts, false, "Use portable fonts"); 19 DEFINE_bool(portableFonts, false, "Use portable fonts");
20 DEFINE_bool(resourceFonts, false, "Use resource fonts");
21 20
22 namespace sk_tool_utils { 21 namespace sk_tool_utils {
23 22
23 /* these are the default fonts chosen by Chrome for serif, sans-serif, and monos pace */
24 static const char* gStandardFontNames[][3] = {
25 { "Times", "Helvetica", "Courier" }, // Mac
26 { "Times New Roman", "Helvetica", "Courier" }, // iOS
27 { "Times New Roman", "Arial", "Courier New" }, // Win
28 { "Times New Roman", "Arial", "Monospace" }, // Ubuntu
29 { "Droid Serif", "Droid Sans", "Droid Sans Mono" }, // Android
30 { "Tinos", "Arimo", "Cousine" } // ChromeOS
31 };
32
33 const char* platform_font_name(const char* name) {
34 SkString platform = major_platform_os_name();
35 int index;
36 if (!strcmp(name, "serif")) {
37 index = 0;
38 } else if (!strcmp(name, "san-serif")) {
39 index = 1;
40 } else if (!strcmp(name, "monospace")) {
41 index = 2;
42 } else {
43 return name;
44 }
45 if (platform.equals("Mac")) {
46 return gStandardFontNames[0][index];
47 }
48 if (platform.equals("iOS")) {
49 return gStandardFontNames[1][index];
50 }
51 if (platform.equals("Win")) {
52 return gStandardFontNames[2][index];
53 }
54 if (platform.equals("Ubuntu")) {
55 return gStandardFontNames[3][index];
56 }
57 if (platform.equals("Android")) {
58 return gStandardFontNames[4][index];
59 }
60 if (platform.equals("ChromeOS")) {
61 return gStandardFontNames[5][index];
62 }
63 return name;
64 }
65
24 const char* platform_os_emoji() { 66 const char* platform_os_emoji() {
25 const char* osName = platform_os_name(); 67 const char* osName = platform_os_name();
26 if (!strcmp(osName, "Android") || !strcmp(osName, "Ubuntu")) { 68 if (!strcmp(osName, "Android") || !strcmp(osName, "Ubuntu")) {
27 return "CBDT"; 69 return "CBDT";
28 } 70 }
29 if (!strncmp(osName, "Mac", 3)) { 71 if (!strncmp(osName, "Mac", 3)) {
30 return "SBIX"; 72 return "SBIX";
31 } 73 }
32 return ""; 74 return "";
33 } 75 }
(...skipping 28 matching lines...) Expand all
62 const char* platform_os_name() { 104 const char* platform_os_name() {
63 for (int index = 0; index < FLAGS_key.count(); index += 2) { 105 for (int index = 0; index < FLAGS_key.count(); index += 2) {
64 if (!strcmp("os", FLAGS_key[index])) { 106 if (!strcmp("os", FLAGS_key[index])) {
65 return FLAGS_key[index + 1]; 107 return FLAGS_key[index + 1];
66 } 108 }
67 } 109 }
68 // when running SampleApp or dm without a --key pair, omit the platform name 110 // when running SampleApp or dm without a --key pair, omit the platform name
69 return ""; 111 return "";
70 } 112 }
71 113
114 // omit version number in returned value
115 SkString major_platform_os_name() {
116 SkString name;
117 for (int index = 0; index < FLAGS_key.count(); index += 2) {
118 if (!strcmp("os", FLAGS_key[index])) {
119 const char* platform = FLAGS_key[index + 1];
120 const char* end = platform;
121 while (*end && (*end < '0' || *end > '9')) {
122 ++end;
123 }
124 name.append(platform, end - platform);
125 break;
126 }
127 }
128 return name;
129 }
130
72 const char* platform_extra_config(const char* config) { 131 const char* platform_extra_config(const char* config) {
73 for (int index = 0; index < FLAGS_key.count(); index += 2) { 132 for (int index = 0; index < FLAGS_key.count(); index += 2) {
74 if (!strcmp("extra_config", FLAGS_key[index]) && !strcmp(config, FLAGS_k ey[index + 1])) { 133 if (!strcmp("extra_config", FLAGS_key[index]) && !strcmp(config, FLAGS_k ey[index + 1])) {
75 return config; 134 return config;
76 } 135 }
77 } 136 }
78 return ""; 137 return "";
79 } 138 }
80 139
81 const char* colortype_name(SkColorType ct) { 140 const char* colortype_name(SkColorType ct) {
(...skipping 14 matching lines...) Expand all
96 SkColor color_to_565(SkColor color) { 155 SkColor color_to_565(SkColor color) {
97 SkPMColor pmColor = SkPreMultiplyColor(color); 156 SkPMColor pmColor = SkPreMultiplyColor(color);
98 U16CPU color16 = SkPixel32ToPixel16(pmColor); 157 U16CPU color16 = SkPixel32ToPixel16(pmColor);
99 return SkPixel16ToColor(color16); 158 return SkPixel16ToColor(color16);
100 } 159 }
101 160
102 SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style) { 161 SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style) {
103 SkTypeface* face; 162 SkTypeface* face;
104 if (FLAGS_portableFonts) { 163 if (FLAGS_portableFonts) {
105 face = create_font(name, style); 164 face = create_font(name, style);
106 } else if (FLAGS_resourceFonts) {
107 face = resource_font(name, style);
108 } else { 165 } else {
109 face = SkTypeface::CreateFromName(name, style); 166 face = SkTypeface::CreateFromName(name, style);
110 } 167 }
111 return face; 168 return face;
112 } 169 }
113 170
114 SkTypeface* create_portable_typeface_always(const char* name, SkTypeface::Style style) { 171 SkTypeface* create_portable_typeface_always(const char* name, SkTypeface::Style style) {
115 return create_font(name, style); 172 return create_font(name, style);
116 } 173 }
117 174
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 paint.textToGlyphs(text, len, glyphs.begin()); 219 paint.textToGlyphs(text, len, glyphs.begin());
163 220
164 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 221 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
165 const SkTextBlobBuilder::RunBuffer& run = builder->allocRun(paint, glyphs.co unt(), x, y, 222 const SkTextBlobBuilder::RunBuffer& run = builder->allocRun(paint, glyphs.co unt(), x, y,
166 NULL); 223 NULL);
167 memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t)); 224 memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t));
168 } 225 }
169 226
170 227
171 } // namespace sk_tool_utils 228 } // namespace sk_tool_utils
OLDNEW
« no previous file with comments | « tools/sk_tool_utils.h ('k') | tools/sk_tool_utils_font.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698