blob: 721e16b5674503f4811491b5c0a869750bece14f [file] [log] [blame]
caryclark5fb6bd42014-06-23 11:25:00 -07001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Ben Wagner219f3622017-07-17 15:32:25 -04008// running create_test_font generates ./tools/test_font_index.inc
9// and ./tools/test_font_<generic name>.inc which are read by ./tools/sk_tool_utils_font.cpp
Cary Clark992c7b02014-07-31 08:58:44 -040010
11#include "Resources.h"
12#include "SkOSFile.h"
Ben Wagner219f3622017-07-17 15:32:25 -040013#include "SkOSPath.h"
caryclark5fb6bd42014-06-23 11:25:00 -070014#include "SkPaint.h"
15#include "SkPath.h"
16#include "SkStream.h"
17#include "SkTArray.h"
18#include "SkTSort.h"
19#include "SkTypeface.h"
Cary Clark992c7b02014-07-31 08:58:44 -040020#include "SkUtils.h"
caryclark5fb6bd42014-06-23 11:25:00 -070021#include <stdio.h>
22
caryclark83ca6282015-06-10 09:31:09 -070023#define DEFAULT_FONT_NAME "sans-serif"
Cary Clark992c7b02014-07-31 08:58:44 -040024
Ben Wagner219f3622017-07-17 15:32:25 -040025namespace {
26
27struct NamedFontStyle {
Cary Clark992c7b02014-07-31 08:58:44 -040028 const char* fName;
Ben Wagner219f3622017-07-17 15:32:25 -040029 SkFontStyle fStyle;
30};
31NamedFontStyle normal = {"Normal", SkFontStyle(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant)};
32NamedFontStyle bold = {"Bold", SkFontStyle(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant)};
33NamedFontStyle italic = {"Italic", SkFontStyle(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kItalic_Slant )};
34NamedFontStyle bolditalic = {"BoldItalic", SkFontStyle(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kItalic_Slant )};
35
36struct FontDesc {
37 const char* fGenericName;
38 NamedFontStyle fNamedStyle;
39 const char* fFontName;
Cary Clark992c7b02014-07-31 08:58:44 -040040 const char* fFile;
Cary Clark992c7b02014-07-31 08:58:44 -040041 int fFontIndex;
42} gFonts[] = {
Ben Wagner219f3622017-07-17 15:32:25 -040043 {"monospace", normal, "Liberation Mono", "LiberationMono-Regular.ttf", -1},
44 {"monospace", bold, "Liberation Mono", "LiberationMono-Bold.ttf", -1},
45 {"monospace", italic, "Liberation Mono", "LiberationMono-Italic.ttf", -1},
46 {"monospace", bolditalic, "Liberation Mono", "LiberationMono-BoldItalic.ttf", -1},
47 {"sans-serif", normal, "Liberation Sans", "LiberationSans-Regular.ttf", -1},
48 {"sans-serif", bold, "Liberation Sans", "LiberationSans-Bold.ttf", -1},
49 {"sans-serif", italic, "Liberation Sans", "LiberationSans-Italic.ttf", -1},
50 {"sans-serif", bolditalic, "Liberation Sans", "LiberationSans-BoldItalic.ttf", -1},
51 {"serif", normal, "Liberation Serif", "LiberationSerif-Regular.ttf", -1},
52 {"serif", bold, "Liberation Serif", "LiberationSerif-Bold.ttf", -1},
53 {"serif", italic, "Liberation Serif", "LiberationSerif-Italic.ttf", -1},
54 {"serif", bolditalic, "Liberation Serif", "LiberationSerif-BoldItalic.ttf", -1},
caryclark5fb6bd42014-06-23 11:25:00 -070055};
56
Cary Clark992c7b02014-07-31 08:58:44 -040057const int gFontsCount = (int) SK_ARRAY_COUNT(gFonts);
58
Cary Clark992c7b02014-07-31 08:58:44 -040059const char gHeader[] =
60"/*\n"
caryclark83ca6282015-06-10 09:31:09 -070061" * Copyright 2015 Google Inc.\n"
Cary Clark992c7b02014-07-31 08:58:44 -040062" *\n"
63" * Use of this source code is governed by a BSD-style license that can be\n"
64" * found in the LICENSE file.\n"
65" */\n"
66"\n"
67"// Auto-generated by ";
68
Ben Wagner219f3622017-07-17 15:32:25 -040069} // namespace
70
caryclark83ca6282015-06-10 09:31:09 -070071static FILE* font_header(const char* family) {
caryclarkc7a84fa2015-01-29 09:59:53 -080072 SkString outPath(SkOSPath::Join(".", "tools"));
caryclark83ca6282015-06-10 09:31:09 -070073 outPath = SkOSPath::Join(outPath.c_str(), "test_font_");
74 SkString fam(family);
75 do {
76 int dashIndex = fam.find("-");
77 if (dashIndex < 0) {
78 break;
79 }
80 fam.writable_str()[dashIndex] = '_';
81 } while (true);
82 outPath.append(fam);
Ben Wagner219f3622017-07-17 15:32:25 -040083 outPath.append(".inc");
Cary Clark992c7b02014-07-31 08:58:44 -040084 FILE* out = fopen(outPath.c_str(), "w");
caryclarkc7a84fa2015-01-29 09:59:53 -080085 fprintf(out, "%s%s\n\n", gHeader, SkOSPath::Basename(__FILE__).c_str());
Cary Clark992c7b02014-07-31 08:58:44 -040086 return out;
caryclark5fb6bd42014-06-23 11:25:00 -070087}
88
Cary Clark992c7b02014-07-31 08:58:44 -040089enum {
90 kMaxLineLength = 80,
91};
92
93static ptrdiff_t last_line_length(const SkString& str) {
94 const char* first = str.c_str();
95 const char* last = first + str.size();
96 const char* ptr = last;
97 while (ptr > first && *--ptr != '\n')
98 ;
99 return last - ptr - 1;
100}
101
102static void output_fixed(SkScalar num, int emSize, SkString* out) {
103 int hex = (int) (num * 65536 / emSize);
104 out->appendf("0x%08x,", hex);
105 *out += (int) last_line_length(*out) >= kMaxLineLength ? '\n' : ' ';
106}
107
108static void output_scalar(SkScalar num, int emSize, SkString* out) {
109 num /= emSize;
caryclark5fb6bd42014-06-23 11:25:00 -0700110 if (num == (int) num) {
Cary Clark992c7b02014-07-31 08:58:44 -0400111 out->appendS32((int) num);
caryclark5fb6bd42014-06-23 11:25:00 -0700112 } else {
113 SkString str;
114 str.printf("%1.6g", num);
115 int width = (int) str.size();
116 const char* cStr = str.c_str();
117 while (cStr[width - 1] == '0') {
118 --width;
119 }
Cary Clark992c7b02014-07-31 08:58:44 -0400120 str.remove(width, str.size() - width);
121 out->appendf("%sf", str.c_str());
122 }
123 *out += ',';
124 *out += (int) last_line_length(*out) >= kMaxLineLength ? '\n' : ' ';
125}
126
127static int output_points(const SkPoint* pts, int emSize, int count, SkString* ptsOut) {
128 for (int index = 0; index < count; ++index) {
129// SkASSERT(floor(pts[index].fX) == pts[index].fX);
130 output_scalar(pts[index].fX, emSize, ptsOut);
131// SkASSERT(floor(pts[index].fY) == pts[index].fY);
132 output_scalar(pts[index].fY, emSize, ptsOut);
133 }
134 return count;
135}
136
caryclark83ca6282015-06-10 09:31:09 -0700137static void output_path_data(const SkPaint& paint,
Cary Clark992c7b02014-07-31 08:58:44 -0400138 int emSize, SkString* ptsOut, SkTDArray<SkPath::Verb>* verbs,
139 SkTDArray<unsigned>* charCodes, SkTDArray<SkScalar>* widths) {
caryclark6d0d6cb2015-06-11 09:40:44 -0700140 for (int ch = 0x00; ch < 0x7f; ++ch) {
caryclark83ca6282015-06-10 09:31:09 -0700141 char str[1];
142 str[0] = ch;
143 const char* used = str;
Cary Clark992c7b02014-07-31 08:58:44 -0400144 SkUnichar index = SkUTF8_NextUnichar(&used);
145 SkPath path;
146 paint.getTextPath((const void*) &index, 2, 0, 0, &path);
147 SkPath::RawIter iter(path);
148 SkPath::Verb verb;
149 SkPoint pts[4];
150 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
151 *verbs->append() = verb;
152 switch (verb) {
153 case SkPath::kMove_Verb:
154 output_points(&pts[0], emSize, 1, ptsOut);
155 break;
156 case SkPath::kLine_Verb:
157 output_points(&pts[1], emSize, 1, ptsOut);
158 break;
159 case SkPath::kQuad_Verb:
160 output_points(&pts[1], emSize, 2, ptsOut);
161 break;
162 case SkPath::kCubic_Verb:
163 output_points(&pts[1], emSize, 3, ptsOut);
164 break;
165 case SkPath::kClose_Verb:
166 break;
167 default:
168 SkDEBUGFAIL("bad verb");
169 SkASSERT(0);
170 }
171 }
172 *verbs->append() = SkPath::kDone_Verb;
173 *charCodes->append() = index;
174 SkScalar width;
175 SkDEBUGCODE(int charCount =) paint.getTextWidths((const void*) &index, 2, &width);
176 SkASSERT(charCount == 1);
caryclark6d0d6cb2015-06-11 09:40:44 -0700177 // SkASSERT(floor(width) == width); // not true for Hiragino Maru Gothic Pro
Cary Clark992c7b02014-07-31 08:58:44 -0400178 *widths->append() = width;
caryclark6d0d6cb2015-06-11 09:40:44 -0700179 if (!ch) {
180 ch = 0x1f; // skip the rest of the control codes
181 }
caryclark5fb6bd42014-06-23 11:25:00 -0700182 }
183}
184
Cary Clark992c7b02014-07-31 08:58:44 -0400185static int offset_str_len(unsigned num) {
186 if (num == (unsigned) -1) {
187 return 10;
188 }
189 unsigned result = 1;
190 unsigned ref = 10;
191 while (ref <= num) {
192 ++result;
193 ref *= 10;
194 }
195 return result;
196}
197
198static SkString strip_spaces(const SkString& str) {
199 SkString result;
200 int count = (int) str.size();
caryclark5fb6bd42014-06-23 11:25:00 -0700201 for (int index = 0; index < count; ++index) {
Cary Clark992c7b02014-07-31 08:58:44 -0400202 char c = str[index];
203 if (c != ' ' && c != '-') {
204 result += c;
caryclark5fb6bd42014-06-23 11:25:00 -0700205 }
206 }
Cary Clark992c7b02014-07-31 08:58:44 -0400207 return result;
caryclark5fb6bd42014-06-23 11:25:00 -0700208}
209
Cary Clark992c7b02014-07-31 08:58:44 -0400210static SkString strip_final(const SkString& str) {
211 SkString result(str);
212 if (result.endsWith("\n")) {
213 result.remove(result.size() - 1, 1);
214 }
215 if (result.endsWith(" ")) {
216 result.remove(result.size() - 1, 1);
217 }
218 if (result.endsWith(",")) {
219 result.remove(result.size() - 1, 1);
220 }
221 return result;
222}
caryclark5fb6bd42014-06-23 11:25:00 -0700223
Ben Wagner219f3622017-07-17 15:32:25 -0400224static void output_font(sk_sp<SkTypeface> face, const char* name, NamedFontStyle style, FILE* out) {
Cary Clark992c7b02014-07-31 08:58:44 -0400225 int emSize = face->getUnitsPerEm() * 2;
caryclark5fb6bd42014-06-23 11:25:00 -0700226 SkPaint paint;
227 paint.setAntiAlias(true);
228 paint.setTextAlign(SkPaint::kLeft_Align);
229 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
Cary Clark992c7b02014-07-31 08:58:44 -0400230 paint.setTextSize(emSize);
Ben Wagner219f3622017-07-17 15:32:25 -0400231 paint.setTypeface(std::move(face));
Cary Clark992c7b02014-07-31 08:58:44 -0400232 SkTDArray<SkPath::Verb> verbs;
233 SkTDArray<unsigned> charCodes;
234 SkTDArray<SkScalar> widths;
235 SkString ptsOut;
caryclark83ca6282015-06-10 09:31:09 -0700236 output_path_data(paint, emSize, &ptsOut, &verbs, &charCodes, &widths);
Cary Clark992c7b02014-07-31 08:58:44 -0400237 SkString fontnameStr(name);
238 SkString strippedStr = strip_spaces(fontnameStr);
Ben Wagner219f3622017-07-17 15:32:25 -0400239 strippedStr.appendf("%s", style.fName);
Cary Clark992c7b02014-07-31 08:58:44 -0400240 const char* fontname = strippedStr.c_str();
241 fprintf(out, "const SkScalar %sPoints[] = {\n", fontname);
242 ptsOut = strip_final(ptsOut);
243 fprintf(out, "%s", ptsOut.c_str());
244 fprintf(out, "\n};\n\n");
245 fprintf(out, "const unsigned char %sVerbs[] = {\n", fontname);
246 int verbCount = verbs.count();
247 int outChCount = 0;
248 for (int index = 0; index < verbCount;) {
249 SkPath::Verb verb = verbs[index];
250 SkASSERT(verb >= SkPath::kMove_Verb && verb <= SkPath::kDone_Verb);
251 SkASSERT((unsigned) verb == (unsigned char) verb);
252 fprintf(out, "%u", verb);
253 if (++index < verbCount) {
254 outChCount += 3;
255 fprintf(out, "%c", ',');
256 if (outChCount >= kMaxLineLength) {
257 outChCount = 0;
258 fprintf(out, "%c", '\n');
259 } else {
260 fprintf(out, "%c", ' ');
caryclark5fb6bd42014-06-23 11:25:00 -0700261 }
262 }
caryclark5fb6bd42014-06-23 11:25:00 -0700263 }
Cary Clark992c7b02014-07-31 08:58:44 -0400264 fprintf(out, "\n};\n\n");
halcanary9d524f22016-03-29 09:03:52 -0700265
caryclark6d0d6cb2015-06-11 09:40:44 -0700266 // all fonts are now 0x00, 0x20 - 0xFE
267 // don't need to generate or output character codes?
Cary Clark992c7b02014-07-31 08:58:44 -0400268 fprintf(out, "const unsigned %sCharCodes[] = {\n", fontname);
269 int offsetCount = charCodes.count();
270 for (int index = 0; index < offsetCount;) {
271 unsigned offset = charCodes[index];
272 fprintf(out, "%u", offset);
273 if (++index < offsetCount) {
274 outChCount += offset_str_len(offset) + 2;
275 fprintf(out, "%c", ',');
276 if (outChCount >= kMaxLineLength) {
277 outChCount = 0;
278 fprintf(out, "%c", '\n');
279 } else {
280 fprintf(out, "%c", ' ');
281 }
282 }
283 }
284 fprintf(out, "\n};\n\n");
halcanary9d524f22016-03-29 09:03:52 -0700285
Cary Clark992c7b02014-07-31 08:58:44 -0400286 SkString widthsStr;
287 fprintf(out, "const SkFixed %sWidths[] = {\n", fontname);
288 for (int index = 0; index < offsetCount; ++index) {
289 output_fixed(widths[index], emSize, &widthsStr);
290 }
291 widthsStr = strip_final(widthsStr);
292 fprintf(out, "%s\n};\n\n", widthsStr.c_str());
halcanary9d524f22016-03-29 09:03:52 -0700293
Cary Clark992c7b02014-07-31 08:58:44 -0400294 fprintf(out, "const int %sCharCodesCount = (int) SK_ARRAY_COUNT(%sCharCodes);\n\n",
295 fontname, fontname);
296
caryclark5fb6bd42014-06-23 11:25:00 -0700297 SkPaint::FontMetrics metrics;
298 paint.getFontMetrics(&metrics);
Cary Clark992c7b02014-07-31 08:58:44 -0400299 fprintf(out, "const SkPaint::FontMetrics %sMetrics = {\n", fontname);
300 SkString metricsStr;
301 metricsStr.printf("0x%08x, ", metrics.fFlags);
302 output_scalar(metrics.fTop, emSize, &metricsStr);
303 output_scalar(metrics.fAscent, emSize, &metricsStr);
304 output_scalar(metrics.fDescent, emSize, &metricsStr);
305 output_scalar(metrics.fBottom, emSize, &metricsStr);
306 output_scalar(metrics.fLeading, emSize, &metricsStr);
307 output_scalar(metrics.fAvgCharWidth, emSize, &metricsStr);
308 output_scalar(metrics.fMaxCharWidth, emSize, &metricsStr);
309 output_scalar(metrics.fXMin, emSize, &metricsStr);
310 output_scalar(metrics.fXMax, emSize, &metricsStr);
311 output_scalar(metrics.fXHeight, emSize, &metricsStr);
312 output_scalar(metrics.fCapHeight, emSize, &metricsStr);
313 output_scalar(metrics.fUnderlineThickness, emSize, &metricsStr);
314 output_scalar(metrics.fUnderlinePosition, emSize, &metricsStr);
Ben Wagner219f3622017-07-17 15:32:25 -0400315 output_scalar(metrics.fStrikeoutThickness, emSize, &metricsStr);
316 output_scalar(metrics.fStrikeoutPosition, emSize, &metricsStr);
Cary Clark992c7b02014-07-31 08:58:44 -0400317 metricsStr = strip_final(metricsStr);
318 fprintf(out, "%s\n};\n\n", metricsStr.c_str());
319}
320
321struct FontWritten {
Ben Wagner219f3622017-07-17 15:32:25 -0400322 const char* fFontName;
323 NamedFontStyle fNamedStyle;
Cary Clark992c7b02014-07-31 08:58:44 -0400324};
325
326static SkTDArray<FontWritten> gWritten;
327
328static int written_index(const FontDesc& fontDesc) {
329 for (int index = 0; index < gWritten.count(); ++index) {
330 const FontWritten& writ = gWritten[index];
Ben Wagner219f3622017-07-17 15:32:25 -0400331 if (!strcmp(fontDesc.fFontName, writ.fFontName) &&
332 fontDesc.fNamedStyle.fStyle == writ.fNamedStyle.fStyle)
333 {
Cary Clark992c7b02014-07-31 08:58:44 -0400334 return index;
335 }
336 }
337 return -1;
338}
339
Ben Wagner219f3622017-07-17 15:32:25 -0400340static void generate_fonts(const char* basepath) {
halcanary96fcdcc2015-08-27 07:41:13 -0700341 FILE* out = nullptr;
Cary Clark992c7b02014-07-31 08:58:44 -0400342 for (int index = 0; index < gFontsCount; ++index) {
343 FontDesc& fontDesc = gFonts[index];
caryclark83ca6282015-06-10 09:31:09 -0700344 if ((index & 3) == 0) {
Ben Wagner219f3622017-07-17 15:32:25 -0400345 out = font_header(fontDesc.fGenericName);
caryclark83ca6282015-06-10 09:31:09 -0700346 }
Cary Clark992c7b02014-07-31 08:58:44 -0400347 int fontIndex = written_index(fontDesc);
348 if (fontIndex >= 0) {
349 fontDesc.fFontIndex = fontIndex;
350 continue;
351 }
Ben Wagner219f3622017-07-17 15:32:25 -0400352 SkString filepath(SkOSPath::Join(basepath, fontDesc.fFile));
353 SkASSERTF(sk_exists(filepath.c_str()), "The file %s does not exist.", filepath.c_str());
354 sk_sp<SkTypeface> resourceTypeface = SkTypeface::MakeFromFile(filepath.c_str());
355 SkASSERTF(resourceTypeface, "The file %s is not a font.", filepath.c_str());
356 output_font(std::move(resourceTypeface), fontDesc.fFontName, fontDesc.fNamedStyle, out);
Cary Clark992c7b02014-07-31 08:58:44 -0400357 fontDesc.fFontIndex = gWritten.count();
358 FontWritten* writ = gWritten.append();
Ben Wagner219f3622017-07-17 15:32:25 -0400359 writ->fFontName = fontDesc.fFontName;
360 writ->fNamedStyle = fontDesc.fNamedStyle;
caryclark83ca6282015-06-10 09:31:09 -0700361 if ((index & 3) == 3) {
362 fclose(out);
363 }
Cary Clark992c7b02014-07-31 08:58:44 -0400364 }
365}
366
Ben Wagner219f3622017-07-17 15:32:25 -0400367static const char* slant_to_string(SkFontStyle::Slant slant) {
368 switch (slant) {
369 case SkFontStyle::kUpright_Slant: return "SkFontStyle::kUpright_Slant";
370 case SkFontStyle::kItalic_Slant : return "SkFontStyle::kItalic_Slant" ;
371 case SkFontStyle::kOblique_Slant: return "SkFontStyle::kOblique_Slant";
372 default: SK_ABORT("Unknown slant"); return "";
caryclark83ca6282015-06-10 09:31:09 -0700373 }
Ben Wagner219f3622017-07-17 15:32:25 -0400374}
375
376static void generate_index(const char* defaultName) {
377 FILE* out = font_header("index");
caryclark83ca6282015-06-10 09:31:09 -0700378 fprintf(out, "static SkTestFontData gTestFonts[] = {\n");
Ben Wagner219f3622017-07-17 15:32:25 -0400379 for (const FontWritten& writ : gWritten) {
380 const char* name = writ.fFontName;
Cary Clark992c7b02014-07-31 08:58:44 -0400381 SkString strippedStr = strip_spaces(SkString(name));
Ben Wagner219f3622017-07-17 15:32:25 -0400382 strippedStr.appendf("%s", writ.fNamedStyle.fName);
Cary Clark992c7b02014-07-31 08:58:44 -0400383 const char* strip = strippedStr.c_str();
384 fprintf(out,
385 " { %sPoints, %sVerbs, %sCharCodes,\n"
386 " %sCharCodesCount, %sWidths,\n"
Ben Wagner219f3622017-07-17 15:32:25 -0400387 " %sMetrics, \"Toy %s\", SkFontStyle(%d,%d,%s), nullptr\n"
Cary Clark992c7b02014-07-31 08:58:44 -0400388 " },\n",
Ben Wagner219f3622017-07-17 15:32:25 -0400389 strip, strip, strip, strip, strip, strip, name,
390 writ.fNamedStyle.fStyle.weight(), writ.fNamedStyle.fStyle.width(),
391 slant_to_string(writ.fNamedStyle.fStyle.slant()));
Cary Clark992c7b02014-07-31 08:58:44 -0400392 }
393 fprintf(out, "};\n\n");
394 fprintf(out, "const int gTestFontsCount = (int) SK_ARRAY_COUNT(gTestFonts);\n\n");
395 fprintf(out,
396 "struct SubFont {\n"
397 " const char* fName;\n"
Ben Wagner219f3622017-07-17 15:32:25 -0400398 " SkFontStyle fStyle;\n"
Cary Clark992c7b02014-07-31 08:58:44 -0400399 " SkTestFontData& fFont;\n"
400 " const char* fFile;\n"
401 "};\n\n"
402 "const SubFont gSubFonts[] = {\n");
403 int defaultIndex = -1;
404 for (int subIndex = 0; subIndex < gFontsCount; subIndex++) {
405 const FontDesc& desc = gFonts[subIndex];
Ben Wagner219f3622017-07-17 15:32:25 -0400406 if (defaultIndex < 0 && !strcmp(defaultName, desc.fGenericName)) {
Cary Clark992c7b02014-07-31 08:58:44 -0400407 defaultIndex = subIndex;
408 }
409 fprintf(out,
Ben Wagner219f3622017-07-17 15:32:25 -0400410 " { \"%s\", SkFontStyle(%d,%d,%s), gTestFonts[%d], \"%s\" },\n",
411 desc.fGenericName,
412 desc.fNamedStyle.fStyle.weight(), desc.fNamedStyle.fStyle.width(),
413 slant_to_string(desc.fNamedStyle.fStyle.slant()), desc.fFontIndex, desc.fFile);
caryclark83ca6282015-06-10 09:31:09 -0700414 }
415 for (int subIndex = 0; subIndex < gFontsCount; subIndex++) {
416 const FontDesc& desc = gFonts[subIndex];
417 fprintf(out,
Ben Wagner219f3622017-07-17 15:32:25 -0400418 " { \"Toy %s\", SkFontStyle(%d,%d,%s), gTestFonts[%d], \"%s\" },\n",
419 desc.fFontName,
420 desc.fNamedStyle.fStyle.weight(), desc.fNamedStyle.fStyle.width(),
421 slant_to_string(desc.fNamedStyle.fStyle.slant()), desc.fFontIndex, desc.fFile);
Cary Clark992c7b02014-07-31 08:58:44 -0400422 }
423 fprintf(out, "};\n\n");
424 fprintf(out, "const int gSubFontsCount = (int) SK_ARRAY_COUNT(gSubFonts);\n\n");
425 SkASSERT(defaultIndex >= 0);
426 fprintf(out, "const int gDefaultFontIndex = %d;\n", defaultIndex);
caryclark83ca6282015-06-10 09:31:09 -0700427 fclose(out);
Cary Clark992c7b02014-07-31 08:58:44 -0400428}
429
430int main(int , char * const []) {
Ben Wagner219f3622017-07-17 15:32:25 -0400431 generate_fonts("/Library/Fonts/");
caryclark83ca6282015-06-10 09:31:09 -0700432 generate_index(DEFAULT_FONT_NAME);
caryclark5fb6bd42014-06-23 11:25:00 -0700433 return 0;
434}