29#if defined(SK_FONTMGR_CORETEXT_AVAILABLE)
33#if defined(SK_FONTMGR_FONTCONFIG_AVAILABLE)
37#if defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE)
43struct NamedFontStyle {
44 char const *
const fName;
45 char const *
const fIdentifierName;
50 NamedFontStyle
const fNamedStyle;
51 char const *
const fFile;
54struct FontFamilyDesc {
55 char const *
const fGenericName;
56 char const *
const fFamilyName;
57 char const *
const fIdentifierName;
69 int dashIndex = fam.
find(
"-");
73 fam.
data()[dashIndex] =
'_';
77 FILE*
out = fopen(outPath.
c_str(),
"w");
79 static const char kHeader[] =
81 " * Copyright 2015 Google Inc.\n"
83 " * Use of this source code is governed by a BSD-style license that can be\n"
84 " * found in the LICENSE file.\n"
87 "// Auto-generated by ";
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')
102 return last - ptr - 1;
106 uint32_t hex = (uint32_t)(num * 65536 / emSize);
107 out->appendf(
"0x%08x,", hex);
113 if (num == (
int) num) {
114 out->appendS32((
int) num);
119 const char* cStr = str.
c_str();
120 while (cStr[
width - 1] ==
'0') {
131 for (
int index = 0; index <
count; ++index) {
141 for (
SkUnichar index = 0x00; index < 0x7f; ++index) {
142 uint16_t glyphID =
font.unicharToGlyph(index);
168 *charCodes->
append() = index;
180 if (num == (
unsigned) -1) {
194 if (
result.endsWith(
"\n")) {
197 if (
result.endsWith(
" ")) {
200 if (
result.endsWith(
",")) {
210 font.setSize(emSize);
211 font.setTypeface(std::move(face));
221 fprintf(
out,
"\n};\n\n");
222 fprintf(
out,
"const unsigned char %sVerbs[] = {\n",
identifier);
223 int verbCount = verbs.
size();
225 for (
int index = 0; index < verbCount;) {
229 fprintf(
out,
"%u", verb);
230 if (++index < verbCount) {
232 fprintf(
out,
"%c",
',');
235 fprintf(
out,
"%c",
'\n');
237 fprintf(
out,
"%c",
' ');
241 fprintf(
out,
"\n};\n\n");
245 fprintf(
out,
"const SkUnichar %sCharCodes[] = {\n",
identifier);
246 int offsetCount = charCodes.
size();
247 for (
int index = 0; index < offsetCount;) {
248 unsigned offset = charCodes[index];
250 if (++index < offsetCount) {
252 fprintf(
out,
"%c",
',');
255 fprintf(
out,
"%c",
'\n');
257 fprintf(
out,
"%c",
' ');
261 fprintf(
out,
"\n};\n\n");
265 for (
int index = 0; index < offsetCount; ++index) {
269 fprintf(
out,
"%s\n};\n\n", widthsStr.
c_str());
271 fprintf(
out,
"const size_t %sCharCodesCount = std::size(%sCharCodes);\n\n",
275 font.getMetrics(&metrics);
276 fprintf(
out,
"const SkFontMetrics %sMetrics = {\n",
identifier);
295 fprintf(
out,
"%s\n};\n\n", metricsStr.
c_str());
300 id.append(
font.fNamedStyle.fIdentifierName);
309 for (
const FontFamilyDesc& family : families) {
311 for (
const FontDesc&
font : family.fFonts) {
315 SkASSERTF(resourceTypeface,
"The file %s is not a font.", filepath.
c_str());
332 const FontDesc* defaultFont)
335 fprintf(
out,
"static SkTestFontData gTestFonts[] = {\n");
336 for (
const FontFamilyDesc& family : families) {
337 for (
const FontDesc&
font : family.fFonts) {
342 " { %sPoints, %sVerbs,\n"
343 " %sCharCodes, %sCharCodesCount, %sWidths,\n"
344 " %sMetrics, \"Toy %s\", SkFontStyle(%d,%d,%s)\n"
352 fprintf(
out,
"};\n\n");
355 " const char* fFamilyName;\n"
356 " const char* fStyleName;\n"
357 " SkFontStyle fStyle;\n"
358 " SkTestFontData& fFont;\n"
359 " const char* fFile;\n"
361 "const SubFont gSubFonts[] = {\n");
362 int defaultIndex = -1;
363 int testFontsIndex = 0;
364 for (
const FontFamilyDesc& family : families) {
365 for (
const FontDesc&
font : family.fFonts) {
366 if (&
font == defaultFont) {
367 defaultIndex = testFontsIndex;
371 " { \"%s\", \"%s\", SkFontStyle(%d,%d,%s), gTestFonts[%d], \"%s\" },\n",
372 family.fGenericName,
font.fNamedStyle.fName,
374 testFontsIndex,
font.fFile);
379 for (
const FontFamilyDesc& family : families) {
380 for (
const FontDesc&
font : family.fFonts) {
382 " { \"Toy %s\", \"%s\", SkFontStyle(%d,%d,%s), gTestFonts[%d], \"%s\" },\n",
383 family.fFamilyName,
font.fNamedStyle.fName,
384 font.fNamedStyle.fStyle.weight(),
font.fNamedStyle.fStyle.width(),
389 fprintf(
out,
"};\n\n");
391 fprintf(
out,
"const size_t gDefaultFontIndex = %d;\n", defaultIndex);
395int main(
int ,
char *
const []) {
401 static constexpr FontDesc kMonoFonts[] = {
402 {normal,
"LiberationMono-Regular.ttf"},
403 {bold,
"LiberationMono-Bold.ttf"},
404 {italic,
"LiberationMono-Italic.ttf"},
405 {bolditalic,
"LiberationMono-BoldItalic.ttf"},
408 static constexpr FontDesc kSansFonts[] = {
409 {normal,
"LiberationSans-Regular.ttf"},
410 {bold,
"LiberationSans-Bold.ttf"},
411 {italic,
"LiberationSans-Italic.ttf"},
412 {bolditalic,
"LiberationSans-BoldItalic.ttf"},
415 static constexpr FontDesc kSerifFonts[] = {
416 {normal,
"LiberationSerif-Regular.ttf"},
417 {bold,
"LiberationSerif-Bold.ttf"},
418 {italic,
"LiberationSerif-Italic.ttf"},
419 {bolditalic,
"LiberationSerif-BoldItalic.ttf"},
422 static constexpr FontFamilyDesc kFamiliesData[] = {
423 {
"monospace",
"Liberation Mono",
"LiberationMono", kMonoFonts},
424 {
"sans-serif",
"Liberation Sans",
"LiberationSans", kSansFonts},
425 {
"serif",
"Liberation Serif",
"LiberationSerif", kSerifFonts},
431#if defined(SK_FONTMGR_FONTCONFIG_AVAILABLE)
433#elif defined(SK_FONTMGR_CORETEXT_AVAILABLE)
435#elif defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE)
441#if defined(SK_BUILD_FOR_UNIX)
442#define SK_FONT_FOLDER "/usr/share/fonts/truetype/liberation/"
443#elif defined(SK_BUILD_FOR_MAC)
444#define SK_FONT_FOLDER "/Library/Fonts/"
446#error "Unsupported OS"
SkStrokeRec::Style fStyle
#define SkDEBUGFAIL(message)
#define SK_ABORT(message,...)
#define SkASSERT_RELEASE(cond)
#define SkASSERTF(cond, fmt,...)
SK_API sk_sp< SkFontMgr > SkFontMgr_New_Custom_Empty()
SK_API sk_sp< SkFontMgr > SkFontMgr_New_FontConfig(FcConfig *fc)
SK_API sk_sp< SkFontMgr > SkFontMgr_New_CoreText(CTFontCollectionRef)
bool sk_exists(const char *path, SkFILE_Flags=(SkFILE_Flags) 0)
@ kClose
SkPath::RawIter returns 0 points.
@ kCubic
SkPath::RawIter returns 4 points.
@ kQuad
SkPath::RawIter returns 3 points.
@ kMove
SkPath::RawIter returns 1 point.
@ kLine
SkPath::RawIter returns 2 points.
sk_sp< SkTypeface > makeFromFile(const char path[], int ttcIndex=0) const
static constexpr SkFontStyle Italic()
static constexpr SkFontStyle BoldItalic()
static constexpr SkFontStyle Bold()
static constexpr SkFontStyle Normal()
@ kAntiAlias
may have transparent pixels on glyph edges
static SkString Join(const char *rootPath, const char *relativePath)
static SkString Basename(const char *fullPath)
void printf(const char format[],...) SK_PRINTF_LIKE(2
void void void void void void void remove(size_t offset, size_t length)
const char * data() const
int find(const char substring[]) const
void append(const char text[])
const char * c_str() const
int getUnitsPerEm() const
static SkString identifier(const FontFamilyDesc &family, const FontDesc &font)
static void generate_index(const SkSpan< const FontFamilyDesc > &families, const FontDesc *defaultFont)
static FILE * font_header(const char *family)
static const char * slant_to_string(SkFontStyle::Slant slant)
static void output_scalar(SkScalar num, int emSize, SkString *out)
static int offset_str_len(unsigned num)
static void output_path_data(const SkFont &font, int emSize, SkString *ptsOut, SkTDArray< SkPath::Verb > *verbs, SkTDArray< unsigned > *charCodes, SkTDArray< SkScalar > *widths)
static int output_points(const SkPoint *pts, int emSize, int count, SkString *ptsOut)
static SkString strip_final(const SkString &str)
static ptrdiff_t last_line_length(const SkString &str)
static void output_font(sk_sp< SkTypeface > face, const char *identifier, FILE *out)
static void output_fixed(SkScalar num, int emSize, SkString *out)
int main(int, char *const [])
static void generate_fonts(const char *basepath, const SkSpan< const FontFamilyDesc > &families, sk_sp< const SkFontMgr > mgr)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
font
Font Metadata and Metrics.
SkScalar fTop
greatest extent above origin of any glyph bounding box, typically negative; deprecated with variable ...
SkScalar fLeading
distance to add between lines, typically positive or zero
SkScalar fAvgCharWidth
average character width, zero if unknown
SkScalar fStrikeoutPosition
distance from baseline to bottom of stroke, typically negative
SkScalar fStrikeoutThickness
strikeout thickness
SkScalar fMaxCharWidth
maximum character width, zero if unknown
SkScalar fBottom
greatest extent below origin of any glyph bounding box, typically positive; deprecated with variable ...
uint32_t fFlags
FontMetricsFlags indicating which metrics are valid.
SkScalar fAscent
distance to reserve above baseline, typically negative
SkScalar fXHeight
height of lower-case 'x', zero if unknown, typically negative
SkScalar fUnderlineThickness
underline thickness
SkScalar fDescent
distance to reserve below baseline, typically positive
SkScalar fCapHeight
height of an upper-case letter, zero if unknown, typically negative
SkScalar fXMin
greatest extent to left of origin of any glyph bounding box, typically negative; deprecated with vari...
SkScalar fUnderlinePosition
distance from baseline to top of stroke, typically positive
SkScalar fXMax
greatest extent to right of origin of any glyph bounding box, typically positive; deprecated with var...