2014-06-23 18:25:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2018-02-20 22:06:07 +00:00
|
|
|
// Running create_test_font generates ./tools/fonts/test_font_index.inc
|
|
|
|
// and ./tools/fonts/test_font_<generic name>.inc which are read by
|
2019-03-20 16:08:46 +00:00
|
|
|
// ./tools/fonts/TestFontMgr.cpp
|
2014-07-31 12:58:44 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkFontMetrics.h"
|
|
|
|
#include "include/core/SkFontStyle.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/private/SkTArray.h"
|
|
|
|
#include "src/core/SkOSFile.h"
|
|
|
|
#include "src/core/SkSpan.h"
|
|
|
|
#include "src/core/SkTSort.h"
|
|
|
|
#include "src/utils/SkOSPath.h"
|
|
|
|
#include "src/utils/SkUTF.h"
|
2018-09-19 15:31:27 +00:00
|
|
|
|
2014-06-23 18:25:00 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-07-17 19:32:25 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct NamedFontStyle {
|
2018-05-08 01:08:02 +00:00
|
|
|
char const * const fName;
|
|
|
|
char const * const fIdentifierName;
|
|
|
|
SkFontStyle const fStyle;
|
2017-07-17 19:32:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct FontDesc {
|
2017-07-27 14:45:29 +00:00
|
|
|
NamedFontStyle const fNamedStyle;
|
|
|
|
char const * const fFile;
|
2014-07-31 12:58:44 +00:00
|
|
|
};
|
|
|
|
|
2018-05-08 01:08:02 +00:00
|
|
|
struct FontFamilyDesc {
|
|
|
|
char const * const fGenericName;
|
|
|
|
char const * const fFamilyName;
|
|
|
|
char const * const fIdentifierName;
|
|
|
|
SkSpan<const FontDesc> const fFonts;
|
|
|
|
};
|
2014-07-31 12:58:44 +00:00
|
|
|
|
2017-07-17 19:32:25 +00:00
|
|
|
} // namespace
|
|
|
|
|
2015-06-10 16:31:09 +00:00
|
|
|
static FILE* font_header(const char* family) {
|
2015-01-29 17:59:53 +00:00
|
|
|
SkString outPath(SkOSPath::Join(".", "tools"));
|
2018-02-20 22:06:07 +00:00
|
|
|
outPath = SkOSPath::Join(outPath.c_str(), "fonts");
|
2015-06-10 16:31:09 +00:00
|
|
|
outPath = SkOSPath::Join(outPath.c_str(), "test_font_");
|
|
|
|
SkString fam(family);
|
|
|
|
do {
|
|
|
|
int dashIndex = fam.find("-");
|
|
|
|
if (dashIndex < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fam.writable_str()[dashIndex] = '_';
|
|
|
|
} while (true);
|
|
|
|
outPath.append(fam);
|
2017-07-17 19:32:25 +00:00
|
|
|
outPath.append(".inc");
|
2014-07-31 12:58:44 +00:00
|
|
|
FILE* out = fopen(outPath.c_str(), "w");
|
2018-05-08 01:08:02 +00:00
|
|
|
|
|
|
|
static const char kHeader[] =
|
|
|
|
"/*\n"
|
|
|
|
" * Copyright 2015 Google Inc.\n"
|
|
|
|
" *\n"
|
|
|
|
" * Use of this source code is governed by a BSD-style license that can be\n"
|
|
|
|
" * found in the LICENSE file.\n"
|
|
|
|
" */\n"
|
|
|
|
"\n"
|
|
|
|
"// Auto-generated by ";
|
|
|
|
fprintf(out, "%s%s\n\n", kHeader, SkOSPath::Basename(__FILE__).c_str());
|
2014-07-31 12:58:44 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2014-06-23 18:25:00 +00:00
|
|
|
enum {
|
2014-07-31 12:58:44 +00:00
|
|
|
kMaxLineLength = 80,
|
2014-06-23 18:25:00 +00:00
|
|
|
};
|
|
|
|
|
2014-07-31 12:58:44 +00:00
|
|
|
static ptrdiff_t last_line_length(const SkString& str) {
|
|
|
|
const char* first = str.c_str();
|
|
|
|
const char* last = first + str.size();
|
|
|
|
const char* ptr = last;
|
|
|
|
while (ptr > first && *--ptr != '\n')
|
|
|
|
;
|
|
|
|
return last - ptr - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void output_fixed(SkScalar num, int emSize, SkString* out) {
|
|
|
|
int hex = (int) (num * 65536 / emSize);
|
|
|
|
out->appendf("0x%08x,", hex);
|
|
|
|
*out += (int) last_line_length(*out) >= kMaxLineLength ? '\n' : ' ';
|
2014-06-23 18:25:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-31 12:58:44 +00:00
|
|
|
static void output_scalar(SkScalar num, int emSize, SkString* out) {
|
|
|
|
num /= emSize;
|
2014-06-23 18:25:00 +00:00
|
|
|
if (num == (int) num) {
|
2014-07-31 12:58:44 +00:00
|
|
|
out->appendS32((int) num);
|
2014-06-23 18:25:00 +00:00
|
|
|
} else {
|
|
|
|
SkString str;
|
|
|
|
str.printf("%1.6g", num);
|
|
|
|
int width = (int) str.size();
|
|
|
|
const char* cStr = str.c_str();
|
|
|
|
while (cStr[width - 1] == '0') {
|
|
|
|
--width;
|
|
|
|
}
|
2014-07-31 12:58:44 +00:00
|
|
|
str.remove(width, str.size() - width);
|
|
|
|
out->appendf("%sf", str.c_str());
|
2014-06-23 18:25:00 +00:00
|
|
|
}
|
2014-07-31 12:58:44 +00:00
|
|
|
*out += ',';
|
|
|
|
*out += (int) last_line_length(*out) >= kMaxLineLength ? '\n' : ' ';
|
2014-06-23 18:25:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-31 12:58:44 +00:00
|
|
|
static int output_points(const SkPoint* pts, int emSize, int count, SkString* ptsOut) {
|
2014-06-23 18:25:00 +00:00
|
|
|
for (int index = 0; index < count; ++index) {
|
2014-07-31 12:58:44 +00:00
|
|
|
output_scalar(pts[index].fX, emSize, ptsOut);
|
|
|
|
output_scalar(pts[index].fY, emSize, ptsOut);
|
2014-06-23 18:25:00 +00:00
|
|
|
}
|
2014-07-31 12:58:44 +00:00
|
|
|
return count;
|
2014-06-23 18:25:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-02 21:04:27 +00:00
|
|
|
static void output_path_data(const SkFont& font,
|
2014-07-31 12:58:44 +00:00
|
|
|
int emSize, SkString* ptsOut, SkTDArray<SkPath::Verb>* verbs,
|
|
|
|
SkTDArray<unsigned>* charCodes, SkTDArray<SkScalar>* widths) {
|
2018-07-25 20:52:48 +00:00
|
|
|
for (SkUnichar index = 0x00; index < 0x7f; ++index) {
|
2018-12-02 21:04:27 +00:00
|
|
|
uint16_t glyphID = font.unicharToGlyph(index);
|
2014-06-23 18:25:00 +00:00
|
|
|
SkPath path;
|
2018-12-02 21:04:27 +00:00
|
|
|
font.getPath(glyphID, &path);
|
2014-06-23 18:25:00 +00:00
|
|
|
SkPath::RawIter iter(path);
|
2014-07-31 12:58:44 +00:00
|
|
|
SkPath::Verb verb;
|
2014-06-23 18:25:00 +00:00
|
|
|
SkPoint pts[4];
|
|
|
|
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
|
2014-07-31 12:58:44 +00:00
|
|
|
*verbs->append() = verb;
|
2014-06-23 18:25:00 +00:00
|
|
|
switch (verb) {
|
|
|
|
case SkPath::kMove_Verb:
|
2014-07-31 12:58:44 +00:00
|
|
|
output_points(&pts[0], emSize, 1, ptsOut);
|
|
|
|
break;
|
2014-06-23 18:25:00 +00:00
|
|
|
case SkPath::kLine_Verb:
|
2014-07-31 12:58:44 +00:00
|
|
|
output_points(&pts[1], emSize, 1, ptsOut);
|
2014-06-23 18:25:00 +00:00
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
2014-07-31 12:58:44 +00:00
|
|
|
output_points(&pts[1], emSize, 2, ptsOut);
|
2014-06-23 18:25:00 +00:00
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
2014-07-31 12:58:44 +00:00
|
|
|
output_points(&pts[1], emSize, 3, ptsOut);
|
2014-06-23 18:25:00 +00:00
|
|
|
break;
|
|
|
|
case SkPath::kClose_Verb:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkDEBUGFAIL("bad verb");
|
2014-07-31 12:58:44 +00:00
|
|
|
SkASSERT(0);
|
2014-06-23 18:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-31 12:58:44 +00:00
|
|
|
*verbs->append() = SkPath::kDone_Verb;
|
|
|
|
*charCodes->append() = index;
|
2014-06-23 18:25:00 +00:00
|
|
|
SkScalar width;
|
2018-12-02 21:04:27 +00:00
|
|
|
font.getWidths(&glyphID, 1, &width);
|
2015-06-11 16:40:44 +00:00
|
|
|
// SkASSERT(floor(width) == width); // not true for Hiragino Maru Gothic Pro
|
2014-07-31 12:58:44 +00:00
|
|
|
*widths->append() = width;
|
2018-07-25 20:52:48 +00:00
|
|
|
if (0 == index) {
|
|
|
|
index = 0x1f; // skip the rest of the control codes
|
2015-06-11 16:40:44 +00:00
|
|
|
}
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int offset_str_len(unsigned num) {
|
|
|
|
if (num == (unsigned) -1) {
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
unsigned result = 1;
|
|
|
|
unsigned ref = 10;
|
|
|
|
while (ref <= num) {
|
|
|
|
++result;
|
|
|
|
ref *= 10;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkString strip_final(const SkString& str) {
|
|
|
|
SkString result(str);
|
|
|
|
if (result.endsWith("\n")) {
|
|
|
|
result.remove(result.size() - 1, 1);
|
|
|
|
}
|
|
|
|
if (result.endsWith(" ")) {
|
|
|
|
result.remove(result.size() - 1, 1);
|
|
|
|
}
|
|
|
|
if (result.endsWith(",")) {
|
|
|
|
result.remove(result.size() - 1, 1);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-05-08 01:08:02 +00:00
|
|
|
static void output_font(sk_sp<SkTypeface> face, const char* identifier, FILE* out) {
|
2018-12-02 21:04:27 +00:00
|
|
|
const int emSize = face->getUnitsPerEm() * 2;
|
|
|
|
SkFont font;
|
|
|
|
font.setEdging(SkFont::Edging::kAntiAlias);
|
|
|
|
font.setSize(emSize);
|
|
|
|
font.setTypeface(std::move(face));
|
|
|
|
|
2014-07-31 12:58:44 +00:00
|
|
|
SkTDArray<SkPath::Verb> verbs;
|
|
|
|
SkTDArray<unsigned> charCodes;
|
|
|
|
SkTDArray<SkScalar> widths;
|
|
|
|
SkString ptsOut;
|
2018-12-02 21:04:27 +00:00
|
|
|
output_path_data(font, emSize, &ptsOut, &verbs, &charCodes, &widths);
|
2018-05-08 01:08:02 +00:00
|
|
|
fprintf(out, "const SkScalar %sPoints[] = {\n", identifier);
|
2014-07-31 12:58:44 +00:00
|
|
|
ptsOut = strip_final(ptsOut);
|
|
|
|
fprintf(out, "%s", ptsOut.c_str());
|
|
|
|
fprintf(out, "\n};\n\n");
|
2018-05-08 01:08:02 +00:00
|
|
|
fprintf(out, "const unsigned char %sVerbs[] = {\n", identifier);
|
2014-07-31 12:58:44 +00:00
|
|
|
int verbCount = verbs.count();
|
|
|
|
int outChCount = 0;
|
|
|
|
for (int index = 0; index < verbCount;) {
|
|
|
|
SkPath::Verb verb = verbs[index];
|
|
|
|
SkASSERT(verb >= SkPath::kMove_Verb && verb <= SkPath::kDone_Verb);
|
2018-05-08 01:08:02 +00:00
|
|
|
SkASSERT(SkTFitsIn<uint8_t>(verb));
|
2014-07-31 12:58:44 +00:00
|
|
|
fprintf(out, "%u", verb);
|
|
|
|
if (++index < verbCount) {
|
|
|
|
outChCount += 3;
|
|
|
|
fprintf(out, "%c", ',');
|
|
|
|
if (outChCount >= kMaxLineLength) {
|
|
|
|
outChCount = 0;
|
|
|
|
fprintf(out, "%c", '\n');
|
|
|
|
} else {
|
|
|
|
fprintf(out, "%c", ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(out, "\n};\n\n");
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2015-06-11 16:40:44 +00:00
|
|
|
// all fonts are now 0x00, 0x20 - 0xFE
|
|
|
|
// don't need to generate or output character codes?
|
2018-05-08 01:08:02 +00:00
|
|
|
fprintf(out, "const SkUnichar %sCharCodes[] = {\n", identifier);
|
2014-07-31 12:58:44 +00:00
|
|
|
int offsetCount = charCodes.count();
|
|
|
|
for (int index = 0; index < offsetCount;) {
|
|
|
|
unsigned offset = charCodes[index];
|
|
|
|
fprintf(out, "%u", offset);
|
|
|
|
if (++index < offsetCount) {
|
|
|
|
outChCount += offset_str_len(offset) + 2;
|
|
|
|
fprintf(out, "%c", ',');
|
|
|
|
if (outChCount >= kMaxLineLength) {
|
|
|
|
outChCount = 0;
|
|
|
|
fprintf(out, "%c", '\n');
|
|
|
|
} else {
|
|
|
|
fprintf(out, "%c", ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(out, "\n};\n\n");
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2014-07-31 12:58:44 +00:00
|
|
|
SkString widthsStr;
|
2018-05-08 01:08:02 +00:00
|
|
|
fprintf(out, "const SkFixed %sWidths[] = {\n", identifier);
|
2014-07-31 12:58:44 +00:00
|
|
|
for (int index = 0; index < offsetCount; ++index) {
|
|
|
|
output_fixed(widths[index], emSize, &widthsStr);
|
2014-06-23 18:25:00 +00:00
|
|
|
}
|
2014-07-31 12:58:44 +00:00
|
|
|
widthsStr = strip_final(widthsStr);
|
|
|
|
fprintf(out, "%s\n};\n\n", widthsStr.c_str());
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2018-05-08 01:08:02 +00:00
|
|
|
fprintf(out, "const size_t %sCharCodesCount = SK_ARRAY_COUNT(%sCharCodes);\n\n",
|
|
|
|
identifier, identifier);
|
2014-07-31 12:58:44 +00:00
|
|
|
|
2018-11-12 14:35:15 +00:00
|
|
|
SkFontMetrics metrics;
|
2018-12-02 21:04:27 +00:00
|
|
|
font.getMetrics(&metrics);
|
2018-11-12 14:35:15 +00:00
|
|
|
fprintf(out, "const SkFontMetrics %sMetrics = {\n", identifier);
|
2014-07-31 12:58:44 +00:00
|
|
|
SkString metricsStr;
|
|
|
|
metricsStr.printf("0x%08x, ", metrics.fFlags);
|
|
|
|
output_scalar(metrics.fTop, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fAscent, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fDescent, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fBottom, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fLeading, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fAvgCharWidth, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fMaxCharWidth, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fXMin, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fXMax, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fXHeight, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fCapHeight, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fUnderlineThickness, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fUnderlinePosition, emSize, &metricsStr);
|
2017-07-17 19:32:25 +00:00
|
|
|
output_scalar(metrics.fStrikeoutThickness, emSize, &metricsStr);
|
|
|
|
output_scalar(metrics.fStrikeoutPosition, emSize, &metricsStr);
|
2014-07-31 12:58:44 +00:00
|
|
|
metricsStr = strip_final(metricsStr);
|
|
|
|
fprintf(out, "%s\n};\n\n", metricsStr.c_str());
|
2014-06-23 18:25:00 +00:00
|
|
|
}
|
|
|
|
|
2018-05-08 01:08:02 +00:00
|
|
|
static SkString identifier(const FontFamilyDesc& family, const FontDesc& font) {
|
|
|
|
SkString id(family.fIdentifierName);
|
|
|
|
id.append(font.fNamedStyle.fIdentifierName);
|
|
|
|
return id;
|
2014-06-23 18:25:00 +00:00
|
|
|
}
|
2014-07-31 12:58:44 +00:00
|
|
|
|
2018-05-08 01:08:02 +00:00
|
|
|
static void generate_fonts(const char* basepath, const SkSpan<const FontFamilyDesc>& families) {
|
2015-08-27 14:41:13 +00:00
|
|
|
FILE* out = nullptr;
|
2018-05-08 01:08:02 +00:00
|
|
|
for (const FontFamilyDesc& family : families) {
|
|
|
|
out = font_header(family.fGenericName);
|
|
|
|
for (const FontDesc& font : family.fFonts) {
|
|
|
|
SkString filepath(SkOSPath::Join(basepath, font.fFile));
|
|
|
|
SkASSERTF(sk_exists(filepath.c_str()), "The file %s does not exist.", filepath.c_str());
|
|
|
|
sk_sp<SkTypeface> resourceTypeface = SkTypeface::MakeFromFile(filepath.c_str());
|
|
|
|
SkASSERTF(resourceTypeface, "The file %s is not a font.", filepath.c_str());
|
|
|
|
output_font(std::move(resourceTypeface), identifier(family, font).c_str(), out);
|
2015-06-10 16:31:09 +00:00
|
|
|
}
|
2018-05-08 01:08:02 +00:00
|
|
|
fclose(out);
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-17 19:32:25 +00:00
|
|
|
static const char* slant_to_string(SkFontStyle::Slant slant) {
|
|
|
|
switch (slant) {
|
|
|
|
case SkFontStyle::kUpright_Slant: return "SkFontStyle::kUpright_Slant";
|
|
|
|
case SkFontStyle::kItalic_Slant : return "SkFontStyle::kItalic_Slant" ;
|
|
|
|
case SkFontStyle::kOblique_Slant: return "SkFontStyle::kOblique_Slant";
|
|
|
|
default: SK_ABORT("Unknown slant"); return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-08 01:08:02 +00:00
|
|
|
static void generate_index(const SkSpan<const FontFamilyDesc>& families,
|
|
|
|
const FontDesc* defaultFont)
|
|
|
|
{
|
2015-06-10 16:31:09 +00:00
|
|
|
FILE* out = font_header("index");
|
|
|
|
fprintf(out, "static SkTestFontData gTestFonts[] = {\n");
|
2018-05-08 01:08:02 +00:00
|
|
|
for (const FontFamilyDesc& family : families) {
|
|
|
|
for (const FontDesc& font : family.fFonts) {
|
|
|
|
SkString identifierStr = identifier(family, font);
|
|
|
|
const char* identifier = identifierStr.c_str();
|
|
|
|
const SkFontStyle& style = font.fNamedStyle.fStyle;
|
|
|
|
fprintf(out,
|
|
|
|
" { %sPoints, %sVerbs,\n"
|
|
|
|
" %sCharCodes, %sCharCodesCount, %sWidths,\n"
|
|
|
|
" %sMetrics, \"Toy %s\", SkFontStyle(%d,%d,%s)\n"
|
|
|
|
" },\n",
|
|
|
|
identifier, identifier,
|
|
|
|
identifier, identifier, identifier,
|
|
|
|
identifier, family.fFamilyName,
|
|
|
|
style.weight(), style.width(), slant_to_string(style.slant()));
|
|
|
|
}
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
|
|
|
fprintf(out, "};\n\n");
|
|
|
|
fprintf(out,
|
2018-05-08 01:08:02 +00:00
|
|
|
"struct SubFont {\n"
|
|
|
|
" const char* fFamilyName;\n"
|
|
|
|
" const char* fStyleName;\n"
|
|
|
|
" SkFontStyle fStyle;\n"
|
|
|
|
" SkTestFontData& fFont;\n"
|
|
|
|
" const char* fFile;\n"
|
|
|
|
"};\n\n"
|
|
|
|
"const SubFont gSubFonts[] = {\n");
|
2014-07-31 12:58:44 +00:00
|
|
|
int defaultIndex = -1;
|
2018-05-08 01:08:02 +00:00
|
|
|
int testFontsIndex = 0;
|
|
|
|
for (const FontFamilyDesc& family : families) {
|
|
|
|
for (const FontDesc& font : family.fFonts) {
|
|
|
|
if (&font == defaultFont) {
|
|
|
|
defaultIndex = testFontsIndex;
|
|
|
|
}
|
|
|
|
const SkFontStyle& style = font.fNamedStyle.fStyle;
|
|
|
|
fprintf(out,
|
|
|
|
" { \"%s\", \"%s\", SkFontStyle(%d,%d,%s), gTestFonts[%d], \"%s\" },\n",
|
|
|
|
family.fGenericName, font.fNamedStyle.fName,
|
|
|
|
style.weight(), style.width(), slant_to_string(style.slant()),
|
|
|
|
testFontsIndex, font.fFile);
|
|
|
|
testFontsIndex++;
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
2015-06-10 16:31:09 +00:00
|
|
|
}
|
2018-05-08 01:08:02 +00:00
|
|
|
testFontsIndex = 0;
|
|
|
|
for (const FontFamilyDesc& family : families) {
|
|
|
|
for (const FontDesc& font : family.fFonts) {
|
|
|
|
fprintf(out,
|
|
|
|
" { \"Toy %s\", \"%s\", SkFontStyle(%d,%d,%s), gTestFonts[%d], \"%s\" },\n",
|
|
|
|
family.fFamilyName, font.fNamedStyle.fName,
|
|
|
|
font.fNamedStyle.fStyle.weight(), font.fNamedStyle.fStyle.width(),
|
|
|
|
slant_to_string(font.fNamedStyle.fStyle.slant()), testFontsIndex, font.fFile);
|
|
|
|
testFontsIndex++;
|
|
|
|
}
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
|
|
|
fprintf(out, "};\n\n");
|
|
|
|
SkASSERT(defaultIndex >= 0);
|
2018-05-08 01:08:02 +00:00
|
|
|
fprintf(out, "const size_t gDefaultFontIndex = %d;\n", defaultIndex);
|
2015-06-10 16:31:09 +00:00
|
|
|
fclose(out);
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int , char * const []) {
|
2018-05-08 01:08:02 +00:00
|
|
|
constexpr NamedFontStyle normal = {"Normal", "Normal", SkFontStyle::Normal() };
|
|
|
|
constexpr NamedFontStyle bold = {"Bold", "Bold", SkFontStyle::Bold() };
|
|
|
|
constexpr NamedFontStyle italic = {"Italic", "Italic", SkFontStyle::Italic() };
|
|
|
|
constexpr NamedFontStyle bolditalic = {"Bold Italic", "BoldItalic", SkFontStyle::BoldItalic()};
|
|
|
|
|
|
|
|
static constexpr FontDesc kMonoFonts[] = {
|
|
|
|
{normal, "LiberationMono-Regular.ttf"},
|
|
|
|
{bold, "LiberationMono-Bold.ttf"},
|
|
|
|
{italic, "LiberationMono-Italic.ttf"},
|
|
|
|
{bolditalic, "LiberationMono-BoldItalic.ttf"},
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr FontDesc kSansFonts[] = {
|
|
|
|
{normal, "LiberationSans-Regular.ttf"},
|
|
|
|
{bold, "LiberationSans-Bold.ttf"},
|
|
|
|
{italic, "LiberationSans-Italic.ttf"},
|
|
|
|
{bolditalic, "LiberationSans-BoldItalic.ttf"},
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr FontDesc kSerifFonts[] = {
|
|
|
|
{normal, "LiberationSerif-Regular.ttf"},
|
|
|
|
{bold, "LiberationSerif-Bold.ttf"},
|
|
|
|
{italic, "LiberationSerif-Italic.ttf"},
|
|
|
|
{bolditalic, "LiberationSerif-BoldItalic.ttf"},
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr FontFamilyDesc kFamiliesData[] = {
|
2019-07-02 20:06:00 +00:00
|
|
|
{"monospace", "Liberation Mono", "LiberationMono", SkMakeSpan(kMonoFonts)},
|
|
|
|
{"sans-serif", "Liberation Sans", "LiberationSans", SkMakeSpan(kSansFonts)},
|
|
|
|
{"serif", "Liberation Serif", "LiberationSerif", SkMakeSpan(kSerifFonts)},
|
2018-05-08 01:08:02 +00:00
|
|
|
};
|
|
|
|
|
2019-07-02 20:06:00 +00:00
|
|
|
static constexpr SkSpan<const FontFamilyDesc> kFamilies(SkMakeSpan(kFamiliesData));
|
2018-05-08 01:08:02 +00:00
|
|
|
|
2018-07-25 20:52:48 +00:00
|
|
|
#ifdef SK_BUILD_FOR_UNIX
|
2018-05-08 01:08:02 +00:00
|
|
|
generate_fonts("/usr/share/fonts/truetype/liberation/", kFamilies);
|
2018-07-25 20:52:48 +00:00
|
|
|
#else
|
2018-05-08 01:08:02 +00:00
|
|
|
generate_fonts("/Library/Fonts/", kFamilies);
|
2018-07-25 20:52:48 +00:00
|
|
|
#endif
|
2018-05-08 01:08:02 +00:00
|
|
|
generate_index(kFamilies, &kFamilies[1].fFonts[0]);
|
2014-07-31 12:58:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|