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

Side by Side Diff: tools/create_test_font.cpp

Issue 1163283002: update portable fonts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rewrite aaxfermodes.cpp to reduce test area Created 5 years, 6 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 | « src/fonts/SkTestScalerContext.cpp ('k') | tools/flags/SkCommandLineFlags.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 // running create_test_font generates ./tools/test_font_data.cpp 8 // running create_test_font generates ./tools/test_font_data.cpp
9 // which is read by ./tools/sk_tool_utils_font.cpp 9 // which is read by ./tools/sk_tool_utils_font.cpp
10 10
11 #include "Resources.h" 11 #include "Resources.h"
12 #include "SkOSFile.h" 12 #include "SkOSFile.h"
13 #include "SkPaint.h" 13 #include "SkPaint.h"
14 #include "SkPath.h" 14 #include "SkPath.h"
15 #include "SkStream.h" 15 #include "SkStream.h"
16 #include "SkTArray.h" 16 #include "SkTArray.h"
17 #include "SkTSort.h" 17 #include "SkTSort.h"
18 #include "SkTypeface.h" 18 #include "SkTypeface.h"
19 #include "SkUtils.h" 19 #include "SkUtils.h"
20 #include <stdio.h> 20 #include <stdio.h>
21 21
22 // the folllowing include is generated by running dm with 22 #define DEFAULT_FONT_NAME "sans-serif"
23 // --portableFonts --reportUsedChars
24 #include "test_font_data_chars.cpp"
25
26 #define DEFAULT_FONT_NAME "Liberation Sans"
27 23
28 static struct FontDesc { 24 static struct FontDesc {
29 const char* fName; 25 const char* fName;
30 SkTypeface::Style fStyle; 26 SkTypeface::Style fStyle;
31 const char* fFont; 27 const char* fFont;
32 const char* fFile; 28 const char* fFile;
33 const char* fCharsUsed;
34 int fFontIndex; 29 int fFontIndex;
35 } gFonts[] = { 30 } gFonts[] = {
36 {"Courier New", SkTypeface::kNormal, "Courier New", "Courier New.ttf", 31 {"monospace", SkTypeface::kNormal, "Liberation Mono", "LiberationMono -Regular.ttf", -1},
37 gCourierNew, -1}, 32 {"monospace", SkTypeface::kBold, "Liberation Mono", "LiberationMono -Bold.ttf", -1},
38 {"Courier New", SkTypeface::kBold, "Courier New", "Courier New Bold.tt f", 33 {"monospace", SkTypeface::kItalic, "Liberation Mono", "LiberationMono -Italic.ttf", -1},
39 gCourierNew_Bold, -1}, 34 {"monospace", SkTypeface::kBoldItalic, "Liberation Mono", "LiberationMono-B oldItalic.ttf", -1},
40 {"Courier New", SkTypeface::kItalic, "Courier New", "Courier New Italic. ttf", 35 {"sans-serif", SkTypeface::kNormal, "Liberation Sans", "LiberationSans -Regular.ttf", -1},
41 gCourierNew_Italic, -1}, 36 {"sans-serif", SkTypeface::kBold, "Liberation Sans", "LiberationSans -Bold.ttf", -1},
42 {"Courier New", SkTypeface::kBoldItalic, "Courier New", "Courier New Bold It alic.ttf", 37 {"sans-serif", SkTypeface::kItalic, "Liberation Sans", "LiberationSans -Italic.ttf", -1},
43 gCourierNew_BoldItalic, -1}, 38 {"sans-serif", SkTypeface::kBoldItalic, "Liberation Sans", "LiberationSans-B oldItalic.ttf", -1},
44 {"Helvetica", SkTypeface::kNormal, "Liberation Sans", "LiberationSans-Regu lar.ttf", 39 {"serif", SkTypeface::kNormal, "Liberation Serif", "LiberationSeri f-Regular.ttf", -1},
45 gLiberationSans, -1}, 40 {"serif", SkTypeface::kBold, "Liberation Serif", "LiberationSeri f-Bold.ttf", -1},
46 {"Helvetica", SkTypeface::kBold, "Liberation Sans", "LiberationSans-Bold .ttf", 41 {"serif", SkTypeface::kItalic, "Liberation Serif", "LiberationSeri f-Italic.ttf", -1},
47 gLiberationSans_Bold, -1}, 42 {"serif", SkTypeface::kBoldItalic, "Liberation Serif", "LiberationSerif-B oldItalic.ttf", -1},
48 {"Helvetica", SkTypeface::kItalic, "Liberation Sans", "LiberationSans-Ital ic.ttf",
49 gLiberationSans_Italic, -1},
50 {"Helvetica", SkTypeface::kBoldItalic, "Liberation Sans", "LiberationSans-B oldItalic.ttf",
51 gLiberationSans_BoldItalic, -1},
52 {"Hiragino Maru Gothic Pro", SkTypeface::kNormal, "Hiragino Maru Gothic Pro" , "Pro W4.otf",
53 gHiraginoMaruGothicPro, -1},
54 {"Liberation Sans", SkTypeface::kNormal, "Liberation Sans", "LiberationSans- Regular.ttf",
55 gLiberationSans, -1},
56 {"Liberation Sans", SkTypeface::kBold, "Liberation Sans", "LiberationSans- Bold.ttf",
57 gLiberationSans_Bold, -1},
58 {"Liberation Sans", SkTypeface::kItalic, "Liberation Sans", "LiberationSans- Italic.ttf",
59 gLiberationSans_Italic, -1},
60 {"Liberation Sans", SkTypeface::kBoldItalic, "Liberation Sans", "LiberationS ans-BoldItalic.ttf",
61 gLiberationSans_BoldItalic, -1},
62 {"monospace", SkTypeface::kNormal, "Courier New", "Courier New.ttf",
63 gCourierNew, -1},
64 {"monospace", SkTypeface::kBold, "Courier New", "Courier New Bold.tt f",
65 gCourierNew_Bold, -1},
66 {"monospace", SkTypeface::kItalic, "Courier New", "Courier New Italic. ttf",
67 gCourierNew_Italic, -1},
68 {"monospace", SkTypeface::kBoldItalic, "Courier New", "Courier New Bold It alic.ttf",
69 gCourierNew_BoldItalic, -1},
70 {"Papyrus", SkTypeface::kNormal, "Papyrus", "Papyrus.ttc",
71 gPapyrus, -1},
72 {"sans-serif", SkTypeface::kNormal, "Liberation Sans", "LiberationSans-Regu lar.ttf",
73 gLiberationSans, -1},
74 {"sans-serif", SkTypeface::kBold, "Liberation Sans", "LiberationSans-Bold .ttf",
75 gLiberationSans_Bold, -1},
76 {"sans-serif", SkTypeface::kItalic, "Liberation Sans", "LiberationSans-Ital ic.ttf",
77 gLiberationSans_Italic, -1},
78 {"sans-serif", SkTypeface::kBoldItalic, "Liberation Sans", "LiberationSans-B oldItalic.ttf",
79 gLiberationSans_BoldItalic, -1},
80 {"serif", SkTypeface::kNormal, "Times New Roman", "Times New Roman.ttf ",
81 gTimesNewRoman, -1},
82 {"serif", SkTypeface::kBold, "Times New Roman", "Times New Roman Bol d.ttf",
83 gTimesNewRoman_Bold, -1},
84 {"serif", SkTypeface::kItalic, "Times New Roman", "Times New Roman Ita lic.ttf",
85 gTimesNewRoman_Italic, -1},
86 {"serif", SkTypeface::kBoldItalic, "Times New Roman", "Times New Roman Bol d Italic.ttf",
87 gTimesNewRoman_BoldItalic, -1},
88 {"Times", SkTypeface::kNormal, "Times New Roman", "Times New Roman.ttf ",
89 gTimesNewRoman, -1},
90 {"Times", SkTypeface::kBold, "Times New Roman", "Times New Roman Bol d.ttf",
91 gTimesNewRoman_Bold, -1},
92 {"Times", SkTypeface::kItalic, "Times New Roman", "Times New Roman Ita lic.ttf",
93 gTimesNewRoman_Italic, -1},
94 {"Times", SkTypeface::kBoldItalic, "Times New Roman", "Times New Roman Bol d Italic.ttf",
95 gTimesNewRoman_BoldItalic, -1},
96 {"Times New Roman", SkTypeface::kNormal, "Times New Roman", "Times New Roman .ttf",
97 gTimesNewRoman, -1},
98 {"Times New Roman", SkTypeface::kBold, "Times New Roman", "Times New Roman Bold.ttf",
99 gTimesNewRoman_Bold, -1},
100 {"Times New Roman", SkTypeface::kItalic, "Times New Roman", "Times New Roman Italic.ttf",
101 gTimesNewRoman_Italic, -1},
102 {"Times New Roman", SkTypeface::kBoldItalic, "Times New Roman", "Times New R oman Bold Italic.ttf",
103 gTimesNewRoman_BoldItalic, -1},
104 {"Times Roman", SkTypeface::kNormal, "Liberation Sans", "LiberationSans-Regu lar.ttf",
105 gLiberationSans, -1},
106 }; 43 };
107 44
108 const int gFontsCount = (int) SK_ARRAY_COUNT(gFonts); 45 const int gFontsCount = (int) SK_ARRAY_COUNT(gFonts);
109 46
110 const char* gStyleName[] = { 47 const char* gStyleName[] = {
111 "kNormal", 48 "Normal",
112 "kBold", 49 "Bold",
113 "kItalic", 50 "Italic",
114 "kBoldItalic", 51 "BoldItalic",
115 }; 52 };
116 53
117 const char gHeader[] = 54 const char gHeader[] =
118 "/*\n" 55 "/*\n"
119 " * Copyright 2014 Google Inc.\n" 56 " * Copyright 2015 Google Inc.\n"
120 " *\n" 57 " *\n"
121 " * Use of this source code is governed by a BSD-style license that can be\n" 58 " * Use of this source code is governed by a BSD-style license that can be\n"
122 " * found in the LICENSE file.\n" 59 " * found in the LICENSE file.\n"
123 " */\n" 60 " */\n"
124 "\n" 61 "\n"
125 "// Auto-generated by "; 62 "// Auto-generated by ";
126 63
127 static FILE* font_header() { 64 static FILE* font_header(const char* family) {
128 SkString outPath(SkOSPath::Join(".", "tools")); 65 SkString outPath(SkOSPath::Join(".", "tools"));
129 outPath = SkOSPath::Join(outPath.c_str(), "test_font_data.cpp"); 66 outPath = SkOSPath::Join(outPath.c_str(), "test_font_");
67 SkString fam(family);
68 do {
69 int dashIndex = fam.find("-");
70 if (dashIndex < 0) {
71 break;
72 }
73 fam.writable_str()[dashIndex] = '_';
74 } while (true);
75 outPath.append(fam);
76 outPath.append(".cpp");
130 FILE* out = fopen(outPath.c_str(), "w"); 77 FILE* out = fopen(outPath.c_str(), "w");
131 fprintf(out, "%s%s\n\n", gHeader, SkOSPath::Basename(__FILE__).c_str()); 78 fprintf(out, "%s%s\n\n", gHeader, SkOSPath::Basename(__FILE__).c_str());
132 return out; 79 return out;
133 } 80 }
134 81
135 enum { 82 enum {
136 kMaxLineLength = 80, 83 kMaxLineLength = 80,
137 }; 84 };
138 85
139 static ptrdiff_t last_line_length(const SkString& str) { 86 static ptrdiff_t last_line_length(const SkString& str) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 static int output_points(const SkPoint* pts, int emSize, int count, SkString* pt sOut) { 120 static int output_points(const SkPoint* pts, int emSize, int count, SkString* pt sOut) {
174 for (int index = 0; index < count; ++index) { 121 for (int index = 0; index < count; ++index) {
175 // SkASSERT(floor(pts[index].fX) == pts[index].fX); 122 // SkASSERT(floor(pts[index].fX) == pts[index].fX);
176 output_scalar(pts[index].fX, emSize, ptsOut); 123 output_scalar(pts[index].fX, emSize, ptsOut);
177 // SkASSERT(floor(pts[index].fY) == pts[index].fY); 124 // SkASSERT(floor(pts[index].fY) == pts[index].fY);
178 output_scalar(pts[index].fY, emSize, ptsOut); 125 output_scalar(pts[index].fY, emSize, ptsOut);
179 } 126 }
180 return count; 127 return count;
181 } 128 }
182 129
183 static void output_path_data(const SkPaint& paint, const char* used, 130 static void output_path_data(const SkPaint& paint,
184 int emSize, SkString* ptsOut, SkTDArray<SkPath::Verb>* verbs, 131 int emSize, SkString* ptsOut, SkTDArray<SkPath::Verb>* verbs,
185 SkTDArray<unsigned>* charCodes, SkTDArray<SkScalar>* widths) { 132 SkTDArray<unsigned>* charCodes, SkTDArray<SkScalar>* widths) {
186 while (*used) { 133 for (char ch = 0x20; ch < 0x7F; ++ch) {
134 char str[1];
135 str[0] = ch;
136 const char* used = str;
187 SkUnichar index = SkUTF8_NextUnichar(&used); 137 SkUnichar index = SkUTF8_NextUnichar(&used);
188 SkPath path; 138 SkPath path;
189 paint.getTextPath((const void*) &index, 2, 0, 0, &path); 139 paint.getTextPath((const void*) &index, 2, 0, 0, &path);
190 SkPath::RawIter iter(path); 140 SkPath::RawIter iter(path);
191 SkPath::Verb verb; 141 SkPath::Verb verb;
192 SkPoint pts[4]; 142 SkPoint pts[4];
193 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { 143 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
194 *verbs->append() = verb; 144 *verbs->append() = verb;
195 switch (verb) { 145 switch (verb) {
196 case SkPath::kMove_Verb: 146 case SkPath::kMove_Verb:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 204 }
255 if (result.endsWith(" ")) { 205 if (result.endsWith(" ")) {
256 result.remove(result.size() - 1, 1); 206 result.remove(result.size() - 1, 1);
257 } 207 }
258 if (result.endsWith(",")) { 208 if (result.endsWith(",")) {
259 result.remove(result.size() - 1, 1); 209 result.remove(result.size() - 1, 1);
260 } 210 }
261 return result; 211 return result;
262 } 212 }
263 213
264 static void output_font(SkTypeface* face, const char* name, SkTypeface::Style st yle, 214 static void output_font(SkTypeface* face, const char* name, SkTypeface::Style st yle, FILE* out) {
265 const char* used, FILE* out) {
266 int emSize = face->getUnitsPerEm() * 2; 215 int emSize = face->getUnitsPerEm() * 2;
267 SkPaint paint; 216 SkPaint paint;
268 paint.setAntiAlias(true); 217 paint.setAntiAlias(true);
269 paint.setTextAlign(SkPaint::kLeft_Align); 218 paint.setTextAlign(SkPaint::kLeft_Align);
270 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); 219 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
271 paint.setTextSize(emSize); 220 paint.setTextSize(emSize);
272 SkSafeUnref(paint.setTypeface(face)); 221 SkSafeUnref(paint.setTypeface(face));
273 SkTDArray<SkPath::Verb> verbs; 222 SkTDArray<SkPath::Verb> verbs;
274 SkTDArray<unsigned> charCodes; 223 SkTDArray<unsigned> charCodes;
275 SkTDArray<SkScalar> widths; 224 SkTDArray<SkScalar> widths;
276 SkString ptsOut; 225 SkString ptsOut;
277 output_path_data(paint, used, emSize, &ptsOut, &verbs, &charCodes, &widths); 226 output_path_data(paint, emSize, &ptsOut, &verbs, &charCodes, &widths);
278 SkString fontnameStr(name); 227 SkString fontnameStr(name);
279 SkString strippedStr = strip_spaces(fontnameStr); 228 SkString strippedStr = strip_spaces(fontnameStr);
280 strippedStr.appendf("%s", gStyleName[style]); 229 strippedStr.appendf("%s", gStyleName[style]);
281 const char* fontname = strippedStr.c_str(); 230 const char* fontname = strippedStr.c_str();
282 fprintf(out, "const SkScalar %sPoints[] = {\n", fontname); 231 fprintf(out, "const SkScalar %sPoints[] = {\n", fontname);
283 ptsOut = strip_final(ptsOut); 232 ptsOut = strip_final(ptsOut);
284 fprintf(out, "%s", ptsOut.c_str()); 233 fprintf(out, "%s", ptsOut.c_str());
285 fprintf(out, "\n};\n\n"); 234 fprintf(out, "\n};\n\n");
286 fprintf(out, "const unsigned char %sVerbs[] = {\n", fontname); 235 fprintf(out, "const unsigned char %sVerbs[] = {\n", fontname);
287 int verbCount = verbs.count(); 236 int verbCount = verbs.count();
288 int outChCount = 0; 237 int outChCount = 0;
289 for (int index = 0; index < verbCount;) { 238 for (int index = 0; index < verbCount;) {
290 SkPath::Verb verb = verbs[index]; 239 SkPath::Verb verb = verbs[index];
291 SkASSERT(verb >= SkPath::kMove_Verb && verb <= SkPath::kDone_Verb); 240 SkASSERT(verb >= SkPath::kMove_Verb && verb <= SkPath::kDone_Verb);
292 SkASSERT((unsigned) verb == (unsigned char) verb); 241 SkASSERT((unsigned) verb == (unsigned char) verb);
293 fprintf(out, "%u", verb); 242 fprintf(out, "%u", verb);
294 if (++index < verbCount) { 243 if (++index < verbCount) {
295 outChCount += 3; 244 outChCount += 3;
296 fprintf(out, "%c", ','); 245 fprintf(out, "%c", ',');
297 if (outChCount >= kMaxLineLength) { 246 if (outChCount >= kMaxLineLength) {
298 outChCount = 0; 247 outChCount = 0;
299 fprintf(out, "%c", '\n'); 248 fprintf(out, "%c", '\n');
300 } else { 249 } else {
301 fprintf(out, "%c", ' '); 250 fprintf(out, "%c", ' ');
302 } 251 }
303 } 252 }
304 } 253 }
305 fprintf(out, "\n};\n\n"); 254 fprintf(out, "\n};\n\n");
306 255
256 // FIXME: all fonts are now 0x20 - 0xFE
257 // don't need to generate or output character codes
307 fprintf(out, "const unsigned %sCharCodes[] = {\n", fontname); 258 fprintf(out, "const unsigned %sCharCodes[] = {\n", fontname);
308 int offsetCount = charCodes.count(); 259 int offsetCount = charCodes.count();
309 for (int index = 0; index < offsetCount;) { 260 for (int index = 0; index < offsetCount;) {
310 unsigned offset = charCodes[index]; 261 unsigned offset = charCodes[index];
311 fprintf(out, "%u", offset); 262 fprintf(out, "%u", offset);
312 if (++index < offsetCount) { 263 if (++index < offsetCount) {
313 outChCount += offset_str_len(offset) + 2; 264 outChCount += offset_str_len(offset) + 2;
314 fprintf(out, "%c", ','); 265 fprintf(out, "%c", ',');
315 if (outChCount >= kMaxLineLength) { 266 if (outChCount >= kMaxLineLength) {
316 outChCount = 0; 267 outChCount = 0;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 static int written_index(const FontDesc& fontDesc) { 316 static int written_index(const FontDesc& fontDesc) {
366 for (int index = 0; index < gWritten.count(); ++index) { 317 for (int index = 0; index < gWritten.count(); ++index) {
367 const FontWritten& writ = gWritten[index]; 318 const FontWritten& writ = gWritten[index];
368 if (!strcmp(fontDesc.fFont, writ.fName) && fontDesc.fStyle == writ.fStyl e) { 319 if (!strcmp(fontDesc.fFont, writ.fName) && fontDesc.fStyle == writ.fStyl e) {
369 return index; 320 return index;
370 } 321 }
371 } 322 }
372 return -1; 323 return -1;
373 } 324 }
374 325
375 static void generate_fonts(FILE* out) { 326 static void generate_fonts() {
327 FILE* out = NULL;
376 for (int index = 0; index < gFontsCount; ++index) { 328 for (int index = 0; index < gFontsCount; ++index) {
377 FontDesc& fontDesc = gFonts[index]; 329 FontDesc& fontDesc = gFonts[index];
330 if ((index & 3) == 0) {
331 out = font_header(fontDesc.fName);
332 }
378 int fontIndex = written_index(fontDesc); 333 int fontIndex = written_index(fontDesc);
379 if (fontIndex >= 0) { 334 if (fontIndex >= 0) {
380 fontDesc.fFontIndex = fontIndex; 335 fontDesc.fFontIndex = fontIndex;
381 continue; 336 continue;
382 } 337 }
383 SkTypeface* systemTypeface = SkTypeface::CreateFromName(fontDesc.fFont, fontDesc.fStyle); 338 SkTypeface* systemTypeface = SkTypeface::CreateFromName(fontDesc.fFont, fontDesc.fStyle);
384 SkASSERT(systemTypeface); 339 SkASSERT(systemTypeface);
385 SkString filepath(GetResourcePath(fontDesc.fFile)); 340 SkString filepath("/Library/Fonts/");
341 filepath.append(fontDesc.fFile);
386 SkASSERT(sk_exists(filepath.c_str())); 342 SkASSERT(sk_exists(filepath.c_str()));
387 SkTypeface* resourceTypeface = SkTypeface::CreateFromFile(filepath.c_str ()); 343 SkTypeface* resourceTypeface = SkTypeface::CreateFromFile(filepath.c_str ());
388 SkASSERT(resourceTypeface); 344 SkASSERT(resourceTypeface);
389 output_font(resourceTypeface, fontDesc.fFont, fontDesc.fStyle, fontDesc. fCharsUsed, out); 345 output_font(resourceTypeface, fontDesc.fFont, fontDesc.fStyle, out);
390 fontDesc.fFontIndex = gWritten.count(); 346 fontDesc.fFontIndex = gWritten.count();
391 FontWritten* writ = gWritten.append(); 347 FontWritten* writ = gWritten.append();
392 writ->fName = fontDesc.fFont; 348 writ->fName = fontDesc.fFont;
393 writ->fStyle = fontDesc.fStyle; 349 writ->fStyle = fontDesc.fStyle;
350 if ((index & 3) == 3) {
351 fclose(out);
352 }
394 } 353 }
395 } 354 }
396 355
397 static void generate_index(const char* defaultName, FILE* out) { 356 static void generate_index(const char* defaultName) {
398 int fontCount = gWritten.count(); 357 int fontCount = gWritten.count();
399 fprintf(out, 358 FILE* out = font_header("index");
400 "static SkTestFontData gTestFonts[] = {\n");
401 int fontIndex; 359 int fontIndex;
360 #if 0
361 // currently generated files are inlined one after the other.
362 // if the inlining is undesirable, generate externs using the code below
363 // (additional code required to add include files)
402 for (fontIndex = 0; fontIndex < fontCount; ++fontIndex) { 364 for (fontIndex = 0; fontIndex < fontCount; ++fontIndex) {
403 const FontWritten& writ = gWritten[fontIndex]; 365 const FontWritten& writ = gWritten[fontIndex];
404 const char* name = writ.fName; 366 const char* name = writ.fName;
367 SkString strippedStr = strip_spaces(SkString(name));
368 strippedStr.appendf("%s", gStyleName[writ.fStyle]);
369 const char* strip = strippedStr.c_str();
370 fprintf(out,
371 "extern const SkScalar %sPoints[];\n"
372 "extern const unsigned char %sVerbs[];\n"
373 "extern const unsigned %sCharCodes[];\n"
374 "extern const int %sCharCodesCount;\n"
375 "extern const SkFixed %sWidths[];\n"
376 "extern const SkPaint::FontMetrics %sMetrics;\n",
377 strip, strip, strip, strip, strip, strip);
378 }
379 fprintf(out, "\n");
380 #endif
381 fprintf(out, "static SkTestFontData gTestFonts[] = {\n");
382 for (fontIndex = 0; fontIndex < fontCount; ++fontIndex) {
383 const FontWritten& writ = gWritten[fontIndex];
384 const char* name = writ.fName;
405 SkString strippedStr = strip_spaces(SkString(name)); 385 SkString strippedStr = strip_spaces(SkString(name));
406 strippedStr.appendf("%s", gStyleName[writ.fStyle]); 386 strippedStr.appendf("%s", gStyleName[writ.fStyle]);
407 const char* strip = strippedStr.c_str(); 387 const char* strip = strippedStr.c_str();
408 fprintf(out, 388 fprintf(out,
409 " { %sPoints, %sVerbs, %sCharCodes,\n" 389 " { %sPoints, %sVerbs, %sCharCodes,\n"
410 " %sCharCodesCount, %sWidths,\n" 390 " %sCharCodesCount, %sWidths,\n"
411 " %sMetrics, \"%s\", SkTypeface::%s, NULL\n" 391 " %sMetrics, \"Toy %s\", SkTypeface::k%s, NULL\n"
412 " },\n", 392 " },\n",
413 strip, strip, strip, strip, strip, strip, name, gStyleName[writ. fStyle]); 393 strip, strip, strip, strip, strip, strip, name, gStyleName[writ. fStyle]);
414 } 394 }
415 fprintf(out, "};\n\n"); 395 fprintf(out, "};\n\n");
416 fprintf(out, "const int gTestFontsCount = (int) SK_ARRAY_COUNT(gTestFonts);\ n\n"); 396 fprintf(out, "const int gTestFontsCount = (int) SK_ARRAY_COUNT(gTestFonts);\ n\n");
417 fprintf(out, 397 fprintf(out,
418 "struct SubFont {\n" 398 "struct SubFont {\n"
419 " const char* fName;\n" 399 " const char* fName;\n"
420 " SkTypeface::Style fStyle;\n" 400 " SkTypeface::Style fStyle;\n"
421 " SkTestFontData& fFont;\n" 401 " SkTestFontData& fFont;\n"
422 " const char* fFile;\n" 402 " const char* fFile;\n"
423 "};\n\n" 403 "};\n\n"
424 "const SubFont gSubFonts[] = {\n"); 404 "const SubFont gSubFonts[] = {\n");
425 int defaultIndex = -1; 405 int defaultIndex = -1;
426 for (int subIndex = 0; subIndex < gFontsCount; subIndex++) { 406 for (int subIndex = 0; subIndex < gFontsCount; subIndex++) {
427 const FontDesc& desc = gFonts[subIndex]; 407 const FontDesc& desc = gFonts[subIndex];
428 if (!strcmp(defaultName, desc.fName)) { 408 if (defaultIndex < 0 && !strcmp(defaultName, desc.fName)) {
429 defaultIndex = subIndex; 409 defaultIndex = subIndex;
430 } 410 }
431 fprintf(out, 411 fprintf(out,
432 " { \"%s\", SkTypeface::%s, gTestFonts[%d], \"%s\"},\n", desc .fName, 412 " { \"%s\", SkTypeface::k%s, gTestFonts[%d], \"%s\" },\n", de sc.fName,
413 gStyleName[desc.fStyle], desc.fFontIndex, desc.fFile);
414 }
415 for (int subIndex = 0; subIndex < gFontsCount; subIndex++) {
416 const FontDesc& desc = gFonts[subIndex];
417 fprintf(out,
418 " { \"Toy %s\", SkTypeface::k%s, gTestFonts[%d], \"%s\" },\n" , desc.fFont,
433 gStyleName[desc.fStyle], desc.fFontIndex, desc.fFile); 419 gStyleName[desc.fStyle], desc.fFontIndex, desc.fFile);
434 } 420 }
435 fprintf(out, "};\n\n"); 421 fprintf(out, "};\n\n");
436 fprintf(out, "const int gSubFontsCount = (int) SK_ARRAY_COUNT(gSubFonts);\n\ n"); 422 fprintf(out, "const int gSubFontsCount = (int) SK_ARRAY_COUNT(gSubFonts);\n\ n");
437 SkASSERT(defaultIndex >= 0); 423 SkASSERT(defaultIndex >= 0);
438 fprintf(out, "const int gDefaultFontIndex = %d;\n", defaultIndex); 424 fprintf(out, "const int gDefaultFontIndex = %d;\n", defaultIndex);
425 fclose(out);
439 } 426 }
440 427
441 int main(int , char * const []) { 428 int main(int , char * const []) {
442 #ifndef SK_BUILD_FOR_MAC 429 #ifndef SK_BUILD_FOR_MAC
443 #error "use fonts installed on Mac" 430 #error "use fonts installed on Mac"
444 #endif 431 #endif
445 FILE* out = font_header(); 432 generate_fonts();
446 generate_fonts(out); 433 generate_index(DEFAULT_FONT_NAME);
447 generate_index(DEFAULT_FONT_NAME, out);
448 fclose(out);
449 return 0; 434 return 0;
450 } 435 }
OLDNEW
« no previous file with comments | « src/fonts/SkTestScalerContext.cpp ('k') | tools/flags/SkCommandLineFlags.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698