blob: 51c56eaee1f804fa0e7b7fc8ac8c63b5b8ad0f13 [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 Wagner483c7722018-02-20 17:06:07 -05008// Running create_test_font generates ./tools/fonts/test_font_index.inc
9// and ./tools/fonts/test_font_<generic name>.inc which are read by
10// ./tools/fonts/sk_tool_utils_font.cpp
Cary Clark992c7b02014-07-31 08:58:44 -040011
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"));
Ben Wagner483c7722018-02-20 17:06:07 -050075 outPath = SkOSPath::Join(outPath.c_str(), "fonts");
caryclark83ca6282015-06-10 09:31:09 -070076 outPath = SkOSPath::Join(outPath.c_str(), "test_font_");
77 SkString fam(family);
78 do {
79 int dashIndex = fam.find("-");
80 if (dashIndex < 0) {
81 break;
82 }
83 fam.writable_str()[dashIndex] = '_';
84 } while (true);
85 outPath.append(fam);
Ben Wagner219f3622017-07-17 15:32:25 -040086 outPath.append(".inc");
Cary Clark992c7b02014-07-31 08:58:44 -040087 FILE* out = fopen(outPath.c_str(), "w");
caryclarkc7a84fa2015-01-29 09:59:53 -080088 fprintf(out, "%s%s\n\n", gHeader, SkOSPath::Basename(__FILE__).c_str());
Cary Clark992c7b02014-07-31 08:58:44 -040089 return out;
caryclark5fb6bd42014-06-23 11:25:00 -070090}
91
Cary Clark992c7b02014-07-31 08:58:44 -040092enum {
93 kMaxLineLength = 80,
94};
95
96static ptrdiff_t last_line_length(const SkString& str) {
97 const char* first = str.c_str();
98 const char* last = first + str.size();
99 const char* ptr = last;
100 while (ptr > first && *--ptr != '\n')
101 ;
102 return last - ptr - 1;
103}
104
105static void output_fixed(SkScalar num, int emSize, SkString* out) {
106 int hex = (int) (num * 65536 / emSize);
107 out->appendf("0x%08x,", hex);
108 *out += (int) last_line_length(*out) >= kMaxLineLength ? '\n' : ' ';
109}
110
111static void output_scalar(SkScalar num, int emSize, SkString* out) {
112 num /= emSize;
caryclark5fb6bd42014-06-23 11:25:00 -0700113 if (num == (int) num) {
Cary Clark992c7b02014-07-31 08:58:44 -0400114 out->appendS32((int) num);
caryclark5fb6bd42014-06-23 11:25:00 -0700115 } else {
116 SkString str;
117 str.printf("%1.6g", num);
118 int width = (int) str.size();
119 const char* cStr = str.c_str();
120 while (cStr[width - 1] == '0') {
121 --width;
122 }
Cary Clark992c7b02014-07-31 08:58:44 -0400123 str.remove(width, str.size() - width);
124 out->appendf("%sf", str.c_str());
125 }
126 *out += ',';
127 *out += (int) last_line_length(*out) >= kMaxLineLength ? '\n' : ' ';
128}
129
130static int output_points(const SkPoint* pts, int emSize, int count, SkString* ptsOut) {
131 for (int index = 0; index < count; ++index) {
132// SkASSERT(floor(pts[index].fX) == pts[index].fX);
133 output_scalar(pts[index].fX, emSize, ptsOut);
134// SkASSERT(floor(pts[index].fY) == pts[index].fY);
135 output_scalar(pts[index].fY, emSize, ptsOut);
136 }
137 return count;
138}
139
caryclark83ca6282015-06-10 09:31:09 -0700140static void output_path_data(const SkPaint& paint,
Cary Clark992c7b02014-07-31 08:58:44 -0400141 int emSize, SkString* ptsOut, SkTDArray<SkPath::Verb>* verbs,
142 SkTDArray<unsigned>* charCodes, SkTDArray<SkScalar>* widths) {
caryclark6d0d6cb2015-06-11 09:40:44 -0700143 for (int ch = 0x00; ch < 0x7f; ++ch) {
caryclark83ca6282015-06-10 09:31:09 -0700144 char str[1];
145 str[0] = ch;
146 const char* used = str;
Cary Clark992c7b02014-07-31 08:58:44 -0400147 SkUnichar index = SkUTF8_NextUnichar(&used);
148 SkPath path;
149 paint.getTextPath((const void*) &index, 2, 0, 0, &path);
150 SkPath::RawIter iter(path);
151 SkPath::Verb verb;
152 SkPoint pts[4];
153 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
154 *verbs->append() = verb;
155 switch (verb) {
156 case SkPath::kMove_Verb:
157 output_points(&pts[0], emSize, 1, ptsOut);
158 break;
159 case SkPath::kLine_Verb:
160 output_points(&pts[1], emSize, 1, ptsOut);
161 break;
162 case SkPath::kQuad_Verb:
163 output_points(&pts[1], emSize, 2, ptsOut);
164 break;
165 case SkPath::kCubic_Verb:
166 output_points(&pts[1], emSize, 3, ptsOut);
167 break;
168 case SkPath::kClose_Verb:
169 break;
170 default:
171 SkDEBUGFAIL("bad verb");
172 SkASSERT(0);
173 }
174 }
175 *verbs->append() = SkPath::kDone_Verb;
176 *charCodes->append() = index;
177 SkScalar width;
178 SkDEBUGCODE(int charCount =) paint.getTextWidths((const void*) &index, 2, &width);
179 SkASSERT(charCount == 1);
caryclark6d0d6cb2015-06-11 09:40:44 -0700180 // SkASSERT(floor(width) == width); // not true for Hiragino Maru Gothic Pro
Cary Clark992c7b02014-07-31 08:58:44 -0400181 *widths->append() = width;
caryclark6d0d6cb2015-06-11 09:40:44 -0700182 if (!ch) {
183 ch = 0x1f; // skip the rest of the control codes
184 }
caryclark5fb6bd42014-06-23 11:25:00 -0700185 }
186}
187
Cary Clark992c7b02014-07-31 08:58:44 -0400188static int offset_str_len(unsigned num) {
189 if (num == (unsigned) -1) {
190 return 10;
191 }
192 unsigned result = 1;
193 unsigned ref = 10;
194 while (ref <= num) {
195 ++result;
196 ref *= 10;
197 }
198 return result;
199}
200
201static SkString strip_spaces(const SkString& str) {
202 SkString result;
203 int count = (int) str.size();
caryclark5fb6bd42014-06-23 11:25:00 -0700204 for (int index = 0; index < count; ++index) {
Cary Clark992c7b02014-07-31 08:58:44 -0400205 char c = str[index];
206 if (c != ' ' && c != '-') {
207 result += c;
caryclark5fb6bd42014-06-23 11:25:00 -0700208 }
209 }
Cary Clark992c7b02014-07-31 08:58:44 -0400210 return result;
caryclark5fb6bd42014-06-23 11:25:00 -0700211}
212
Cary Clark992c7b02014-07-31 08:58:44 -0400213static SkString strip_final(const SkString& str) {
214 SkString result(str);
215 if (result.endsWith("\n")) {
216 result.remove(result.size() - 1, 1);
217 }
218 if (result.endsWith(" ")) {
219 result.remove(result.size() - 1, 1);
220 }
221 if (result.endsWith(",")) {
222 result.remove(result.size() - 1, 1);
223 }
224 return result;
225}
caryclark5fb6bd42014-06-23 11:25:00 -0700226
Ben Wagner219f3622017-07-17 15:32:25 -0400227static void output_font(sk_sp<SkTypeface> face, const char* name, NamedFontStyle style, FILE* out) {
Cary Clark992c7b02014-07-31 08:58:44 -0400228 int emSize = face->getUnitsPerEm() * 2;
caryclark5fb6bd42014-06-23 11:25:00 -0700229 SkPaint paint;
230 paint.setAntiAlias(true);
231 paint.setTextAlign(SkPaint::kLeft_Align);
232 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
Cary Clark992c7b02014-07-31 08:58:44 -0400233 paint.setTextSize(emSize);
Ben Wagner219f3622017-07-17 15:32:25 -0400234 paint.setTypeface(std::move(face));
Cary Clark992c7b02014-07-31 08:58:44 -0400235 SkTDArray<SkPath::Verb> verbs;
236 SkTDArray<unsigned> charCodes;
237 SkTDArray<SkScalar> widths;
238 SkString ptsOut;
caryclark83ca6282015-06-10 09:31:09 -0700239 output_path_data(paint, emSize, &ptsOut, &verbs, &charCodes, &widths);
Cary Clark992c7b02014-07-31 08:58:44 -0400240 SkString fontnameStr(name);
241 SkString strippedStr = strip_spaces(fontnameStr);
Ben Wagner219f3622017-07-17 15:32:25 -0400242 strippedStr.appendf("%s", style.fName);
Cary Clark992c7b02014-07-31 08:58:44 -0400243 const char* fontname = strippedStr.c_str();
244 fprintf(out, "const SkScalar %sPoints[] = {\n", fontname);
245 ptsOut = strip_final(ptsOut);
246 fprintf(out, "%s", ptsOut.c_str());
247 fprintf(out, "\n};\n\n");
248 fprintf(out, "const unsigned char %sVerbs[] = {\n", fontname);
249 int verbCount = verbs.count();
250 int outChCount = 0;
251 for (int index = 0; index < verbCount;) {
252 SkPath::Verb verb = verbs[index];
253 SkASSERT(verb >= SkPath::kMove_Verb && verb <= SkPath::kDone_Verb);
254 SkASSERT((unsigned) verb == (unsigned char) verb);
255 fprintf(out, "%u", verb);
256 if (++index < verbCount) {
257 outChCount += 3;
258 fprintf(out, "%c", ',');
259 if (outChCount >= kMaxLineLength) {
260 outChCount = 0;
261 fprintf(out, "%c", '\n');
262 } else {
263 fprintf(out, "%c", ' ');
caryclark5fb6bd42014-06-23 11:25:00 -0700264 }
265 }
caryclark5fb6bd42014-06-23 11:25:00 -0700266 }
Cary Clark992c7b02014-07-31 08:58:44 -0400267 fprintf(out, "\n};\n\n");
halcanary9d524f22016-03-29 09:03:52 -0700268
caryclark6d0d6cb2015-06-11 09:40:44 -0700269 // all fonts are now 0x00, 0x20 - 0xFE
270 // don't need to generate or output character codes?
Cary Clark992c7b02014-07-31 08:58:44 -0400271 fprintf(out, "const unsigned %sCharCodes[] = {\n", fontname);
272 int offsetCount = charCodes.count();
273 for (int index = 0; index < offsetCount;) {
274 unsigned offset = charCodes[index];
275 fprintf(out, "%u", offset);
276 if (++index < offsetCount) {
277 outChCount += offset_str_len(offset) + 2;
278 fprintf(out, "%c", ',');
279 if (outChCount >= kMaxLineLength) {
280 outChCount = 0;
281 fprintf(out, "%c", '\n');
282 } else {
283 fprintf(out, "%c", ' ');
284 }
285 }
286 }
287 fprintf(out, "\n};\n\n");
halcanary9d524f22016-03-29 09:03:52 -0700288
Cary Clark992c7b02014-07-31 08:58:44 -0400289 SkString widthsStr;
290 fprintf(out, "const SkFixed %sWidths[] = {\n", fontname);
291 for (int index = 0; index < offsetCount; ++index) {
292 output_fixed(widths[index], emSize, &widthsStr);
293 }
294 widthsStr = strip_final(widthsStr);
295 fprintf(out, "%s\n};\n\n", widthsStr.c_str());
halcanary9d524f22016-03-29 09:03:52 -0700296
Cary Clark992c7b02014-07-31 08:58:44 -0400297 fprintf(out, "const int %sCharCodesCount = (int) SK_ARRAY_COUNT(%sCharCodes);\n\n",
298 fontname, fontname);
299
caryclark5fb6bd42014-06-23 11:25:00 -0700300 SkPaint::FontMetrics metrics;
301 paint.getFontMetrics(&metrics);
Cary Clark992c7b02014-07-31 08:58:44 -0400302 fprintf(out, "const SkPaint::FontMetrics %sMetrics = {\n", fontname);
303 SkString metricsStr;
304 metricsStr.printf("0x%08x, ", metrics.fFlags);
305 output_scalar(metrics.fTop, emSize, &metricsStr);
306 output_scalar(metrics.fAscent, emSize, &metricsStr);
307 output_scalar(metrics.fDescent, emSize, &metricsStr);
308 output_scalar(metrics.fBottom, emSize, &metricsStr);
309 output_scalar(metrics.fLeading, emSize, &metricsStr);
310 output_scalar(metrics.fAvgCharWidth, emSize, &metricsStr);
311 output_scalar(metrics.fMaxCharWidth, emSize, &metricsStr);
312 output_scalar(metrics.fXMin, emSize, &metricsStr);
313 output_scalar(metrics.fXMax, emSize, &metricsStr);
314 output_scalar(metrics.fXHeight, emSize, &metricsStr);
315 output_scalar(metrics.fCapHeight, emSize, &metricsStr);
316 output_scalar(metrics.fUnderlineThickness, emSize, &metricsStr);
317 output_scalar(metrics.fUnderlinePosition, emSize, &metricsStr);
Ben Wagner219f3622017-07-17 15:32:25 -0400318 output_scalar(metrics.fStrikeoutThickness, emSize, &metricsStr);
319 output_scalar(metrics.fStrikeoutPosition, emSize, &metricsStr);
Cary Clark992c7b02014-07-31 08:58:44 -0400320 metricsStr = strip_final(metricsStr);
321 fprintf(out, "%s\n};\n\n", metricsStr.c_str());
322}
323
324struct FontWritten {
Ben Wagner219f3622017-07-17 15:32:25 -0400325 const char* fFontName;
326 NamedFontStyle fNamedStyle;
Cary Clark992c7b02014-07-31 08:58:44 -0400327};
328
329static SkTDArray<FontWritten> gWritten;
330
331static int written_index(const FontDesc& fontDesc) {
332 for (int index = 0; index < gWritten.count(); ++index) {
333 const FontWritten& writ = gWritten[index];
Ben Wagner219f3622017-07-17 15:32:25 -0400334 if (!strcmp(fontDesc.fFontName, writ.fFontName) &&
335 fontDesc.fNamedStyle.fStyle == writ.fNamedStyle.fStyle)
336 {
Cary Clark992c7b02014-07-31 08:58:44 -0400337 return index;
338 }
339 }
340 return -1;
341}
342
Ben Wagner219f3622017-07-17 15:32:25 -0400343static void generate_fonts(const char* basepath) {
halcanary96fcdcc2015-08-27 07:41:13 -0700344 FILE* out = nullptr;
Cary Clark992c7b02014-07-31 08:58:44 -0400345 for (int index = 0; index < gFontsCount; ++index) {
346 FontDesc& fontDesc = gFonts[index];
caryclark83ca6282015-06-10 09:31:09 -0700347 if ((index & 3) == 0) {
Ben Wagner219f3622017-07-17 15:32:25 -0400348 out = font_header(fontDesc.fGenericName);
caryclark83ca6282015-06-10 09:31:09 -0700349 }
Cary Clark992c7b02014-07-31 08:58:44 -0400350 int fontIndex = written_index(fontDesc);
351 if (fontIndex >= 0) {
352 fontDesc.fFontIndex = fontIndex;
353 continue;
354 }
Ben Wagner219f3622017-07-17 15:32:25 -0400355 SkString filepath(SkOSPath::Join(basepath, fontDesc.fFile));
356 SkASSERTF(sk_exists(filepath.c_str()), "The file %s does not exist.", filepath.c_str());
357 sk_sp<SkTypeface> resourceTypeface = SkTypeface::MakeFromFile(filepath.c_str());
358 SkASSERTF(resourceTypeface, "The file %s is not a font.", filepath.c_str());
359 output_font(std::move(resourceTypeface), fontDesc.fFontName, fontDesc.fNamedStyle, out);
Cary Clark992c7b02014-07-31 08:58:44 -0400360 fontDesc.fFontIndex = gWritten.count();
361 FontWritten* writ = gWritten.append();
Ben Wagner219f3622017-07-17 15:32:25 -0400362 writ->fFontName = fontDesc.fFontName;
363 writ->fNamedStyle = fontDesc.fNamedStyle;
caryclark83ca6282015-06-10 09:31:09 -0700364 if ((index & 3) == 3) {
365 fclose(out);
366 }
Cary Clark992c7b02014-07-31 08:58:44 -0400367 }
368}
369
Ben Wagner219f3622017-07-17 15:32:25 -0400370static const char* slant_to_string(SkFontStyle::Slant slant) {
371 switch (slant) {
372 case SkFontStyle::kUpright_Slant: return "SkFontStyle::kUpright_Slant";
373 case SkFontStyle::kItalic_Slant : return "SkFontStyle::kItalic_Slant" ;
374 case SkFontStyle::kOblique_Slant: return "SkFontStyle::kOblique_Slant";
375 default: SK_ABORT("Unknown slant"); return "";
caryclark83ca6282015-06-10 09:31:09 -0700376 }
Ben Wagner219f3622017-07-17 15:32:25 -0400377}
378
379static void generate_index(const char* defaultName) {
380 FILE* out = font_header("index");
caryclark83ca6282015-06-10 09:31:09 -0700381 fprintf(out, "static SkTestFontData gTestFonts[] = {\n");
Ben Wagner219f3622017-07-17 15:32:25 -0400382 for (const FontWritten& writ : gWritten) {
383 const char* name = writ.fFontName;
Cary Clark992c7b02014-07-31 08:58:44 -0400384 SkString strippedStr = strip_spaces(SkString(name));
Ben Wagner219f3622017-07-17 15:32:25 -0400385 strippedStr.appendf("%s", writ.fNamedStyle.fName);
Cary Clark992c7b02014-07-31 08:58:44 -0400386 const char* strip = strippedStr.c_str();
387 fprintf(out,
388 " { %sPoints, %sVerbs, %sCharCodes,\n"
389 " %sCharCodesCount, %sWidths,\n"
Ben Wagner219f3622017-07-17 15:32:25 -0400390 " %sMetrics, \"Toy %s\", SkFontStyle(%d,%d,%s), nullptr\n"
Cary Clark992c7b02014-07-31 08:58:44 -0400391 " },\n",
Ben Wagner219f3622017-07-17 15:32:25 -0400392 strip, strip, strip, strip, strip, strip, name,
393 writ.fNamedStyle.fStyle.weight(), writ.fNamedStyle.fStyle.width(),
394 slant_to_string(writ.fNamedStyle.fStyle.slant()));
Cary Clark992c7b02014-07-31 08:58:44 -0400395 }
396 fprintf(out, "};\n\n");
397 fprintf(out, "const int gTestFontsCount = (int) SK_ARRAY_COUNT(gTestFonts);\n\n");
398 fprintf(out,
399 "struct SubFont {\n"
400 " const char* fName;\n"
Ben Wagner219f3622017-07-17 15:32:25 -0400401 " SkFontStyle fStyle;\n"
Cary Clark992c7b02014-07-31 08:58:44 -0400402 " SkTestFontData& fFont;\n"
403 " const char* fFile;\n"
404 "};\n\n"
405 "const SubFont gSubFonts[] = {\n");
406 int defaultIndex = -1;
407 for (int subIndex = 0; subIndex < gFontsCount; subIndex++) {
408 const FontDesc& desc = gFonts[subIndex];
Ben Wagner219f3622017-07-17 15:32:25 -0400409 if (defaultIndex < 0 && !strcmp(defaultName, desc.fGenericName)) {
Cary Clark992c7b02014-07-31 08:58:44 -0400410 defaultIndex = subIndex;
411 }
412 fprintf(out,
Ben Wagner219f3622017-07-17 15:32:25 -0400413 " { \"%s\", SkFontStyle(%d,%d,%s), gTestFonts[%d], \"%s\" },\n",
414 desc.fGenericName,
415 desc.fNamedStyle.fStyle.weight(), desc.fNamedStyle.fStyle.width(),
416 slant_to_string(desc.fNamedStyle.fStyle.slant()), desc.fFontIndex, desc.fFile);
caryclark83ca6282015-06-10 09:31:09 -0700417 }
418 for (int subIndex = 0; subIndex < gFontsCount; subIndex++) {
419 const FontDesc& desc = gFonts[subIndex];
420 fprintf(out,
Ben Wagner219f3622017-07-17 15:32:25 -0400421 " { \"Toy %s\", SkFontStyle(%d,%d,%s), gTestFonts[%d], \"%s\" },\n",
422 desc.fFontName,
423 desc.fNamedStyle.fStyle.weight(), desc.fNamedStyle.fStyle.width(),
424 slant_to_string(desc.fNamedStyle.fStyle.slant()), desc.fFontIndex, desc.fFile);
Cary Clark992c7b02014-07-31 08:58:44 -0400425 }
426 fprintf(out, "};\n\n");
427 fprintf(out, "const int gSubFontsCount = (int) SK_ARRAY_COUNT(gSubFonts);\n\n");
428 SkASSERT(defaultIndex >= 0);
429 fprintf(out, "const int gDefaultFontIndex = %d;\n", defaultIndex);
caryclark83ca6282015-06-10 09:31:09 -0700430 fclose(out);
Cary Clark992c7b02014-07-31 08:58:44 -0400431}
432
433int main(int , char * const []) {
Ben Wagner5423f1f2018-02-20 09:57:58 -0500434 generate_fonts("/Library/Fonts/"); // or /usr/share/fonts/truetype/ttf-liberation/
caryclark83ca6282015-06-10 09:31:09 -0700435 generate_index(DEFAULT_FONT_NAME);
caryclark5fb6bd42014-06-23 11:25:00 -0700436 return 0;
437}