blob: 4fd8dbbdbb0f75ffa64f184d2ab36d57e4034a1a [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"
Ben Wagner71319502017-07-27 10:45:29 -040012#include "SkFontStyle.h"
Cary Clark992c7b02014-07-31 08:58:44 -040013#include "SkOSFile.h"
Ben Wagner219f3622017-07-17 15:32:25 -040014#include "SkOSPath.h"
caryclark5fb6bd42014-06-23 11:25:00 -070015#include "SkPaint.h"
16#include "SkPath.h"
17#include "SkStream.h"
18#include "SkTArray.h"
19#include "SkTSort.h"
20#include "SkTypeface.h"
Cary Clark992c7b02014-07-31 08:58:44 -040021#include "SkUtils.h"
caryclark5fb6bd42014-06-23 11:25:00 -070022#include <stdio.h>
23
caryclark83ca6282015-06-10 09:31:09 -070024#define DEFAULT_FONT_NAME "sans-serif"
Cary Clark992c7b02014-07-31 08:58:44 -040025
Ben Wagner219f3622017-07-17 15:32:25 -040026namespace {
27
28struct NamedFontStyle {
Cary Clark992c7b02014-07-31 08:58:44 -040029 const char* fName;
Ben Wagner219f3622017-07-17 15:32:25 -040030 SkFontStyle fStyle;
31};
Ben Wagner71319502017-07-27 10:45:29 -040032constexpr NamedFontStyle normal = {"Normal", SkFontStyle::Normal() };
33constexpr NamedFontStyle bold = {"Bold", SkFontStyle::Bold() };
34constexpr NamedFontStyle italic = {"Italic", SkFontStyle::Italic() };
35constexpr NamedFontStyle bolditalic = {"BoldItalic", SkFontStyle::BoldItalic()};
Ben Wagner219f3622017-07-17 15:32:25 -040036
37struct FontDesc {
Ben Wagner71319502017-07-27 10:45:29 -040038 char const * const fGenericName;
39 NamedFontStyle const fNamedStyle;
40 char const * const fFontName;
41 char const * const fFile;
42 // fFontIndex is mutable and will be set later.
Cary Clark992c7b02014-07-31 08:58:44 -040043 int fFontIndex;
44} gFonts[] = {
Ben Wagner219f3622017-07-17 15:32:25 -040045 {"monospace", normal, "Liberation Mono", "LiberationMono-Regular.ttf", -1},
46 {"monospace", bold, "Liberation Mono", "LiberationMono-Bold.ttf", -1},
47 {"monospace", italic, "Liberation Mono", "LiberationMono-Italic.ttf", -1},
48 {"monospace", bolditalic, "Liberation Mono", "LiberationMono-BoldItalic.ttf", -1},
49 {"sans-serif", normal, "Liberation Sans", "LiberationSans-Regular.ttf", -1},
50 {"sans-serif", bold, "Liberation Sans", "LiberationSans-Bold.ttf", -1},
51 {"sans-serif", italic, "Liberation Sans", "LiberationSans-Italic.ttf", -1},
52 {"sans-serif", bolditalic, "Liberation Sans", "LiberationSans-BoldItalic.ttf", -1},
53 {"serif", normal, "Liberation Serif", "LiberationSerif-Regular.ttf", -1},
54 {"serif", bold, "Liberation Serif", "LiberationSerif-Bold.ttf", -1},
55 {"serif", italic, "Liberation Serif", "LiberationSerif-Italic.ttf", -1},
56 {"serif", bolditalic, "Liberation Serif", "LiberationSerif-BoldItalic.ttf", -1},
caryclark5fb6bd42014-06-23 11:25:00 -070057};
58
Cary Clark992c7b02014-07-31 08:58:44 -040059const int gFontsCount = (int) SK_ARRAY_COUNT(gFonts);
60
Cary Clark992c7b02014-07-31 08:58:44 -040061const char gHeader[] =
62"/*\n"
caryclark83ca6282015-06-10 09:31:09 -070063" * Copyright 2015 Google Inc.\n"
Cary Clark992c7b02014-07-31 08:58:44 -040064" *\n"
65" * Use of this source code is governed by a BSD-style license that can be\n"
66" * found in the LICENSE file.\n"
67" */\n"
68"\n"
69"// Auto-generated by ";
70
Ben Wagner219f3622017-07-17 15:32:25 -040071} // namespace
72
caryclark83ca6282015-06-10 09:31:09 -070073static FILE* font_header(const char* family) {
caryclarkc7a84fa2015-01-29 09:59:53 -080074 SkString outPath(SkOSPath::Join(".", "tools"));
caryclark83ca6282015-06-10 09:31:09 -070075 outPath = SkOSPath::Join(outPath.c_str(), "test_font_");
76 SkString fam(family);
77 do {
78 int dashIndex = fam.find("-");
79 if (dashIndex < 0) {
80 break;
81 }
82 fam.writable_str()[dashIndex] = '_';
83 } while (true);
84 outPath.append(fam);
Ben Wagner219f3622017-07-17 15:32:25 -040085 outPath.append(".inc");
Cary Clark992c7b02014-07-31 08:58:44 -040086 FILE* out = fopen(outPath.c_str(), "w");
caryclarkc7a84fa2015-01-29 09:59:53 -080087 fprintf(out, "%s%s\n\n", gHeader, SkOSPath::Basename(__FILE__).c_str());
Cary Clark992c7b02014-07-31 08:58:44 -040088 return out;
caryclark5fb6bd42014-06-23 11:25:00 -070089}
90
Cary Clark992c7b02014-07-31 08:58:44 -040091enum {
92 kMaxLineLength = 80,
93};
94
95static ptrdiff_t last_line_length(const SkString& str) {
96 const char* first = str.c_str();
97 const char* last = first + str.size();
98 const char* ptr = last;
99 while (ptr > first && *--ptr != '\n')
100 ;
101 return last - ptr - 1;
102}
103
104static void output_fixed(SkScalar num, int emSize, SkString* out) {
105 int hex = (int) (num * 65536 / emSize);
106 out->appendf("0x%08x,", hex);
107 *out += (int) last_line_length(*out) >= kMaxLineLength ? '\n' : ' ';
108}
109
110static void output_scalar(SkScalar num, int emSize, SkString* out) {
111 num /= emSize;
caryclark5fb6bd42014-06-23 11:25:00 -0700112 if (num == (int) num) {
Cary Clark992c7b02014-07-31 08:58:44 -0400113 out->appendS32((int) num);
caryclark5fb6bd42014-06-23 11:25:00 -0700114 } else {
115 SkString str;
116 str.printf("%1.6g", num);
117 int width = (int) str.size();
118 const char* cStr = str.c_str();
119 while (cStr[width - 1] == '0') {
120 --width;
121 }
Cary Clark992c7b02014-07-31 08:58:44 -0400122 str.remove(width, str.size() - width);
123 out->appendf("%sf", str.c_str());
124 }
125 *out += ',';
126 *out += (int) last_line_length(*out) >= kMaxLineLength ? '\n' : ' ';
127}
128
129static int output_points(const SkPoint* pts, int emSize, int count, SkString* ptsOut) {
130 for (int index = 0; index < count; ++index) {
131// SkASSERT(floor(pts[index].fX) == pts[index].fX);
132 output_scalar(pts[index].fX, emSize, ptsOut);
133// SkASSERT(floor(pts[index].fY) == pts[index].fY);
134 output_scalar(pts[index].fY, emSize, ptsOut);
135 }
136 return count;
137}
138
caryclark83ca6282015-06-10 09:31:09 -0700139static void output_path_data(const SkPaint& paint,
Cary Clark992c7b02014-07-31 08:58:44 -0400140 int emSize, SkString* ptsOut, SkTDArray<SkPath::Verb>* verbs,
141 SkTDArray<unsigned>* charCodes, SkTDArray<SkScalar>* widths) {
caryclark6d0d6cb2015-06-11 09:40:44 -0700142 for (int ch = 0x00; ch < 0x7f; ++ch) {
caryclark83ca6282015-06-10 09:31:09 -0700143 char str[1];
144 str[0] = ch;
145 const char* used = str;
Cary Clark992c7b02014-07-31 08:58:44 -0400146 SkUnichar index = SkUTF8_NextUnichar(&used);
147 SkPath path;
148 paint.getTextPath((const void*) &index, 2, 0, 0, &path);
149 SkPath::RawIter iter(path);
150 SkPath::Verb verb;
151 SkPoint pts[4];
152 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
153 *verbs->append() = verb;
154 switch (verb) {
155 case SkPath::kMove_Verb:
156 output_points(&pts[0], emSize, 1, ptsOut);
157 break;
158 case SkPath::kLine_Verb:
159 output_points(&pts[1], emSize, 1, ptsOut);
160 break;
161 case SkPath::kQuad_Verb:
162 output_points(&pts[1], emSize, 2, ptsOut);
163 break;
164 case SkPath::kCubic_Verb:
165 output_points(&pts[1], emSize, 3, ptsOut);
166 break;
167 case SkPath::kClose_Verb:
168 break;
169 default:
170 SkDEBUGFAIL("bad verb");
171 SkASSERT(0);
172 }
173 }
174 *verbs->append() = SkPath::kDone_Verb;
175 *charCodes->append() = index;
176 SkScalar width;
177 SkDEBUGCODE(int charCount =) paint.getTextWidths((const void*) &index, 2, &width);
178 SkASSERT(charCount == 1);
caryclark6d0d6cb2015-06-11 09:40:44 -0700179 // SkASSERT(floor(width) == width); // not true for Hiragino Maru Gothic Pro
Cary Clark992c7b02014-07-31 08:58:44 -0400180 *widths->append() = width;
caryclark6d0d6cb2015-06-11 09:40:44 -0700181 if (!ch) {
182 ch = 0x1f; // skip the rest of the control codes
183 }
caryclark5fb6bd42014-06-23 11:25:00 -0700184 }
185}
186
Cary Clark992c7b02014-07-31 08:58:44 -0400187static int offset_str_len(unsigned num) {
188 if (num == (unsigned) -1) {
189 return 10;
190 }
191 unsigned result = 1;
192 unsigned ref = 10;
193 while (ref <= num) {
194 ++result;
195 ref *= 10;
196 }
197 return result;
198}
199
200static SkString strip_spaces(const SkString& str) {
201 SkString result;
202 int count = (int) str.size();
caryclark5fb6bd42014-06-23 11:25:00 -0700203 for (int index = 0; index < count; ++index) {
Cary Clark992c7b02014-07-31 08:58:44 -0400204 char c = str[index];
205 if (c != ' ' && c != '-') {
206 result += c;
caryclark5fb6bd42014-06-23 11:25:00 -0700207 }
208 }
Cary Clark992c7b02014-07-31 08:58:44 -0400209 return result;
caryclark5fb6bd42014-06-23 11:25:00 -0700210}
211
Cary Clark992c7b02014-07-31 08:58:44 -0400212static SkString strip_final(const SkString& str) {
213 SkString result(str);
214 if (result.endsWith("\n")) {
215 result.remove(result.size() - 1, 1);
216 }
217 if (result.endsWith(" ")) {
218 result.remove(result.size() - 1, 1);
219 }
220 if (result.endsWith(",")) {
221 result.remove(result.size() - 1, 1);
222 }
223 return result;
224}
caryclark5fb6bd42014-06-23 11:25:00 -0700225
Ben Wagner219f3622017-07-17 15:32:25 -0400226static void output_font(sk_sp<SkTypeface> face, const char* name, NamedFontStyle style, FILE* out) {
Cary Clark992c7b02014-07-31 08:58:44 -0400227 int emSize = face->getUnitsPerEm() * 2;
caryclark5fb6bd42014-06-23 11:25:00 -0700228 SkPaint paint;
229 paint.setAntiAlias(true);
230 paint.setTextAlign(SkPaint::kLeft_Align);
231 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
Cary Clark992c7b02014-07-31 08:58:44 -0400232 paint.setTextSize(emSize);
Ben Wagner219f3622017-07-17 15:32:25 -0400233 paint.setTypeface(std::move(face));
Cary Clark992c7b02014-07-31 08:58:44 -0400234 SkTDArray<SkPath::Verb> verbs;
235 SkTDArray<unsigned> charCodes;
236 SkTDArray<SkScalar> widths;
237 SkString ptsOut;
caryclark83ca6282015-06-10 09:31:09 -0700238 output_path_data(paint, emSize, &ptsOut, &verbs, &charCodes, &widths);
Cary Clark992c7b02014-07-31 08:58:44 -0400239 SkString fontnameStr(name);
240 SkString strippedStr = strip_spaces(fontnameStr);
Ben Wagner219f3622017-07-17 15:32:25 -0400241 strippedStr.appendf("%s", style.fName);
Cary Clark992c7b02014-07-31 08:58:44 -0400242 const char* fontname = strippedStr.c_str();
243 fprintf(out, "const SkScalar %sPoints[] = {\n", fontname);
244 ptsOut = strip_final(ptsOut);
245 fprintf(out, "%s", ptsOut.c_str());
246 fprintf(out, "\n};\n\n");
247 fprintf(out, "const unsigned char %sVerbs[] = {\n", fontname);
248 int verbCount = verbs.count();
249 int outChCount = 0;
250 for (int index = 0; index < verbCount;) {
251 SkPath::Verb verb = verbs[index];
252 SkASSERT(verb >= SkPath::kMove_Verb && verb <= SkPath::kDone_Verb);
253 SkASSERT((unsigned) verb == (unsigned char) verb);
254 fprintf(out, "%u", verb);
255 if (++index < verbCount) {
256 outChCount += 3;
257 fprintf(out, "%c", ',');
258 if (outChCount >= kMaxLineLength) {
259 outChCount = 0;
260 fprintf(out, "%c", '\n');
261 } else {
262 fprintf(out, "%c", ' ');
caryclark5fb6bd42014-06-23 11:25:00 -0700263 }
264 }
caryclark5fb6bd42014-06-23 11:25:00 -0700265 }
Cary Clark992c7b02014-07-31 08:58:44 -0400266 fprintf(out, "\n};\n\n");
halcanary9d524f22016-03-29 09:03:52 -0700267
caryclark6d0d6cb2015-06-11 09:40:44 -0700268 // all fonts are now 0x00, 0x20 - 0xFE
269 // don't need to generate or output character codes?
Cary Clark992c7b02014-07-31 08:58:44 -0400270 fprintf(out, "const unsigned %sCharCodes[] = {\n", fontname);
271 int offsetCount = charCodes.count();
272 for (int index = 0; index < offsetCount;) {
273 unsigned offset = charCodes[index];
274 fprintf(out, "%u", offset);
275 if (++index < offsetCount) {
276 outChCount += offset_str_len(offset) + 2;
277 fprintf(out, "%c", ',');
278 if (outChCount >= kMaxLineLength) {
279 outChCount = 0;
280 fprintf(out, "%c", '\n');
281 } else {
282 fprintf(out, "%c", ' ');
283 }
284 }
285 }
286 fprintf(out, "\n};\n\n");
halcanary9d524f22016-03-29 09:03:52 -0700287
Cary Clark992c7b02014-07-31 08:58:44 -0400288 SkString widthsStr;
289 fprintf(out, "const SkFixed %sWidths[] = {\n", fontname);
290 for (int index = 0; index < offsetCount; ++index) {
291 output_fixed(widths[index], emSize, &widthsStr);
292 }
293 widthsStr = strip_final(widthsStr);
294 fprintf(out, "%s\n};\n\n", widthsStr.c_str());
halcanary9d524f22016-03-29 09:03:52 -0700295
Cary Clark992c7b02014-07-31 08:58:44 -0400296 fprintf(out, "const int %sCharCodesCount = (int) SK_ARRAY_COUNT(%sCharCodes);\n\n",
297 fontname, fontname);
298
caryclark5fb6bd42014-06-23 11:25:00 -0700299 SkPaint::FontMetrics metrics;
300 paint.getFontMetrics(&metrics);
Cary Clark992c7b02014-07-31 08:58:44 -0400301 fprintf(out, "const SkPaint::FontMetrics %sMetrics = {\n", fontname);
302 SkString metricsStr;
303 metricsStr.printf("0x%08x, ", metrics.fFlags);
304 output_scalar(metrics.fTop, emSize, &metricsStr);
305 output_scalar(metrics.fAscent, emSize, &metricsStr);
306 output_scalar(metrics.fDescent, emSize, &metricsStr);
307 output_scalar(metrics.fBottom, emSize, &metricsStr);
308 output_scalar(metrics.fLeading, emSize, &metricsStr);
309 output_scalar(metrics.fAvgCharWidth, emSize, &metricsStr);
310 output_scalar(metrics.fMaxCharWidth, emSize, &metricsStr);
311 output_scalar(metrics.fXMin, emSize, &metricsStr);
312 output_scalar(metrics.fXMax, emSize, &metricsStr);
313 output_scalar(metrics.fXHeight, emSize, &metricsStr);
314 output_scalar(metrics.fCapHeight, emSize, &metricsStr);
315 output_scalar(metrics.fUnderlineThickness, emSize, &metricsStr);
316 output_scalar(metrics.fUnderlinePosition, emSize, &metricsStr);
Ben Wagner219f3622017-07-17 15:32:25 -0400317 output_scalar(metrics.fStrikeoutThickness, emSize, &metricsStr);
318 output_scalar(metrics.fStrikeoutPosition, emSize, &metricsStr);
Cary Clark992c7b02014-07-31 08:58:44 -0400319 metricsStr = strip_final(metricsStr);
320 fprintf(out, "%s\n};\n\n", metricsStr.c_str());
321}
322
323struct FontWritten {
Ben Wagner219f3622017-07-17 15:32:25 -0400324 const char* fFontName;
325 NamedFontStyle fNamedStyle;
Cary Clark992c7b02014-07-31 08:58:44 -0400326};
327
328static SkTDArray<FontWritten> gWritten;
329
330static int written_index(const FontDesc& fontDesc) {
331 for (int index = 0; index < gWritten.count(); ++index) {
332 const FontWritten& writ = gWritten[index];
Ben Wagner219f3622017-07-17 15:32:25 -0400333 if (!strcmp(fontDesc.fFontName, writ.fFontName) &&
334 fontDesc.fNamedStyle.fStyle == writ.fNamedStyle.fStyle)
335 {
Cary Clark992c7b02014-07-31 08:58:44 -0400336 return index;
337 }
338 }
339 return -1;
340}
341
Ben Wagner219f3622017-07-17 15:32:25 -0400342static void generate_fonts(const char* basepath) {
halcanary96fcdcc2015-08-27 07:41:13 -0700343 FILE* out = nullptr;
Cary Clark992c7b02014-07-31 08:58:44 -0400344 for (int index = 0; index < gFontsCount; ++index) {
345 FontDesc& fontDesc = gFonts[index];
caryclark83ca6282015-06-10 09:31:09 -0700346 if ((index & 3) == 0) {
Ben Wagner219f3622017-07-17 15:32:25 -0400347 out = font_header(fontDesc.fGenericName);
caryclark83ca6282015-06-10 09:31:09 -0700348 }
Cary Clark992c7b02014-07-31 08:58:44 -0400349 int fontIndex = written_index(fontDesc);
350 if (fontIndex >= 0) {
351 fontDesc.fFontIndex = fontIndex;
352 continue;
353 }
Ben Wagner219f3622017-07-17 15:32:25 -0400354 SkString filepath(SkOSPath::Join(basepath, fontDesc.fFile));
355 SkASSERTF(sk_exists(filepath.c_str()), "The file %s does not exist.", filepath.c_str());
356 sk_sp<SkTypeface> resourceTypeface = SkTypeface::MakeFromFile(filepath.c_str());
357 SkASSERTF(resourceTypeface, "The file %s is not a font.", filepath.c_str());
358 output_font(std::move(resourceTypeface), fontDesc.fFontName, fontDesc.fNamedStyle, out);
Cary Clark992c7b02014-07-31 08:58:44 -0400359 fontDesc.fFontIndex = gWritten.count();
360 FontWritten* writ = gWritten.append();
Ben Wagner219f3622017-07-17 15:32:25 -0400361 writ->fFontName = fontDesc.fFontName;
362 writ->fNamedStyle = fontDesc.fNamedStyle;
caryclark83ca6282015-06-10 09:31:09 -0700363 if ((index & 3) == 3) {
364 fclose(out);
365 }
Cary Clark992c7b02014-07-31 08:58:44 -0400366 }
367}
368
Ben Wagner219f3622017-07-17 15:32:25 -0400369static const char* slant_to_string(SkFontStyle::Slant slant) {
370 switch (slant) {
371 case SkFontStyle::kUpright_Slant: return "SkFontStyle::kUpright_Slant";
372 case SkFontStyle::kItalic_Slant : return "SkFontStyle::kItalic_Slant" ;
373 case SkFontStyle::kOblique_Slant: return "SkFontStyle::kOblique_Slant";
374 default: SK_ABORT("Unknown slant"); return "";
caryclark83ca6282015-06-10 09:31:09 -0700375 }
Ben Wagner219f3622017-07-17 15:32:25 -0400376}
377
378static void generate_index(const char* defaultName) {
379 FILE* out = font_header("index");
caryclark83ca6282015-06-10 09:31:09 -0700380 fprintf(out, "static SkTestFontData gTestFonts[] = {\n");
Ben Wagner219f3622017-07-17 15:32:25 -0400381 for (const FontWritten& writ : gWritten) {
382 const char* name = writ.fFontName;
Cary Clark992c7b02014-07-31 08:58:44 -0400383 SkString strippedStr = strip_spaces(SkString(name));
Ben Wagner219f3622017-07-17 15:32:25 -0400384 strippedStr.appendf("%s", writ.fNamedStyle.fName);
Cary Clark992c7b02014-07-31 08:58:44 -0400385 const char* strip = strippedStr.c_str();
386 fprintf(out,
387 " { %sPoints, %sVerbs, %sCharCodes,\n"
388 " %sCharCodesCount, %sWidths,\n"
Ben Wagner219f3622017-07-17 15:32:25 -0400389 " %sMetrics, \"Toy %s\", SkFontStyle(%d,%d,%s), nullptr\n"
Cary Clark992c7b02014-07-31 08:58:44 -0400390 " },\n",
Ben Wagner219f3622017-07-17 15:32:25 -0400391 strip, strip, strip, strip, strip, strip, name,
392 writ.fNamedStyle.fStyle.weight(), writ.fNamedStyle.fStyle.width(),
393 slant_to_string(writ.fNamedStyle.fStyle.slant()));
Cary Clark992c7b02014-07-31 08:58:44 -0400394 }
395 fprintf(out, "};\n\n");
396 fprintf(out, "const int gTestFontsCount = (int) SK_ARRAY_COUNT(gTestFonts);\n\n");
397 fprintf(out,
398 "struct SubFont {\n"
399 " const char* fName;\n"
Ben Wagner219f3622017-07-17 15:32:25 -0400400 " SkFontStyle fStyle;\n"
Cary Clark992c7b02014-07-31 08:58:44 -0400401 " SkTestFontData& fFont;\n"
402 " const char* fFile;\n"
403 "};\n\n"
404 "const SubFont gSubFonts[] = {\n");
405 int defaultIndex = -1;
406 for (int subIndex = 0; subIndex < gFontsCount; subIndex++) {
407 const FontDesc& desc = gFonts[subIndex];
Ben Wagner219f3622017-07-17 15:32:25 -0400408 if (defaultIndex < 0 && !strcmp(defaultName, desc.fGenericName)) {
Cary Clark992c7b02014-07-31 08:58:44 -0400409 defaultIndex = subIndex;
410 }
411 fprintf(out,
Ben Wagner219f3622017-07-17 15:32:25 -0400412 " { \"%s\", SkFontStyle(%d,%d,%s), gTestFonts[%d], \"%s\" },\n",
413 desc.fGenericName,
414 desc.fNamedStyle.fStyle.weight(), desc.fNamedStyle.fStyle.width(),
415 slant_to_string(desc.fNamedStyle.fStyle.slant()), desc.fFontIndex, desc.fFile);
caryclark83ca6282015-06-10 09:31:09 -0700416 }
417 for (int subIndex = 0; subIndex < gFontsCount; subIndex++) {
418 const FontDesc& desc = gFonts[subIndex];
419 fprintf(out,
Ben Wagner219f3622017-07-17 15:32:25 -0400420 " { \"Toy %s\", SkFontStyle(%d,%d,%s), gTestFonts[%d], \"%s\" },\n",
421 desc.fFontName,
422 desc.fNamedStyle.fStyle.weight(), desc.fNamedStyle.fStyle.width(),
423 slant_to_string(desc.fNamedStyle.fStyle.slant()), desc.fFontIndex, desc.fFile);
Cary Clark992c7b02014-07-31 08:58:44 -0400424 }
425 fprintf(out, "};\n\n");
426 fprintf(out, "const int gSubFontsCount = (int) SK_ARRAY_COUNT(gSubFonts);\n\n");
427 SkASSERT(defaultIndex >= 0);
428 fprintf(out, "const int gDefaultFontIndex = %d;\n", defaultIndex);
caryclark83ca6282015-06-10 09:31:09 -0700429 fclose(out);
Cary Clark992c7b02014-07-31 08:58:44 -0400430}
431
432int main(int , char * const []) {
Ben Wagner219f3622017-07-17 15:32:25 -0400433 generate_fonts("/Library/Fonts/");
caryclark83ca6282015-06-10 09:31:09 -0700434 generate_index(DEFAULT_FONT_NAME);
caryclark5fb6bd42014-06-23 11:25:00 -0700435 return 0;
436}