Today's gm include many differences caused by platform font implementations.

This experiment replaces the label used in the aaxfermodes gm with
aliased text generated from paths common to all platforms.

Since there is no way today to generate all dm output from trybots,
this will be checked in to confirm that this strategy provides simpler
output across devices.

This does not introduce a new public interface; instead, dm uses
a extern backdoor to install the SkTypeface::CreateFromName
handler.

Review URL: https://codereview.chromium.org/1163283002
This commit is contained in:
caryclark 2015-06-10 09:31:09 -07:00 committed by Commit bot
parent e21585eabf
commit 83ca628cb6
13 changed files with 15146 additions and 136 deletions

View File

@ -14,6 +14,7 @@
#include "SkBBHFactory.h"
#include "SkChecksum.h"
#include "SkCommonFlags.h"
#include "SkFontMgr.h"
#include "SkForceLinking.h"
#include "SkGraphics.h"
#include "SkInstCnt.h"
@ -24,6 +25,7 @@
#include "SkThreadUtils.h"
#include "Test.h"
#include "Timer.h"
#include "sk_tool_utils.h"
DEFINE_string(src, "tests gm skp image", "Source types to test.");
DEFINE_bool(nameByHash, false,
@ -707,6 +709,20 @@ static void start_keepalive() {
intentionallyLeaked->start();
}
#define PORTABLE_FONT_PREFIX "Toy Liberation "
static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
&& !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
return sk_tool_utils::create_portable_typeface_always(familyName, style);
}
return NULL;
}
#undef PORTABLE_FONT_PREFIX
extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
int dm_main();
int dm_main() {
SetupCrashHandler();
@ -715,6 +731,7 @@ int dm_main() {
if (FLAGS_leaks) {
SkInstCountPrintLeaksOnExit();
}
gCreateTypefaceDelegate = &create_from_name;
start_keepalive();

View File

@ -49,6 +49,12 @@ public:
AAXfermodesGM() {}
protected:
enum DrawingPass {
kCheckerboard_Pass,
kBackground_Pass,
kShape_Pass
};
SkString onShortName() override {
return SkString("aaxfermodes");
}
@ -61,8 +67,10 @@ protected:
}
void onOnceBeforeDraw() override {
#if 0
fLabelPaint.setAntiAlias(true);
sk_tool_utils::set_portable_typeface(&fLabelPaint);
#endif
sk_tool_utils::set_portable_typeface_always(&fLabelPaint);
fLabelPaint.setTextSize(5 * kShapeSize/8);
fLabelPaint.setSubpixelText(true);
@ -78,38 +86,29 @@ protected:
fPath.quadTo(pts[3], pts[0]);
}
void onDraw(SkCanvas* canvas) override {
sk_tool_utils::draw_checkerboard(canvas, 0xffffffff, 0xffc0c0c0, 10);
canvas->saveLayer(NULL, NULL);
canvas->drawColor(kBGColor, SkXfermode::kSrc_Mode);
canvas->translate(kMargin, kMargin);
SkPaint titlePaint(fLabelPaint);
titlePaint.setTextSize(9 * titlePaint.getTextSize() / 8);
titlePaint.setFakeBoldText(true);
titlePaint.setTextAlign(SkPaint::kCenter_Align);
canvas->drawText("Porter Duff", sizeof("Porter Duff") - 1,
kLabelSpacing + 3 * kShapeTypeSpacing,
kTitleSpacing / 2 + titlePaint.getTextSize() / 3, titlePaint);
canvas->drawText("Advanced", sizeof("Advanced") - 1,
kXfermodeTypeSpacing + kLabelSpacing + 3 * kShapeTypeSpacing,
kTitleSpacing / 2 + titlePaint.getTextSize() / 3, titlePaint);
void draw_pass(SkCanvas* canvas, DrawingPass drawingPass) {
SkRect clipRect =
{ -kShapeSize*11/16, -kShapeSize*11/16, kShapeSize*11/16, kShapeSize*11/16 };
canvas->save();
if (kCheckerboard_Pass == drawingPass) {
canvas->translate(kMargin, kMargin);
}
canvas->translate(0, kTitleSpacing);
for (size_t xfermodeSet = 0; xfermodeSet < 2; xfermodeSet++) {
size_t firstMode = (SkXfermode::kLastCoeffMode + 1) * xfermodeSet;
canvas->save();
fLabelPaint.setTextAlign(SkPaint::kCenter_Align);
canvas->drawText("Src Unknown", sizeof("Src Unknown") - 1,
kLabelSpacing + kShapeSpacing / 2 + kShapeTypeSpacing,
kSubtitleSpacing / 2 + fLabelPaint.getTextSize() / 3, fLabelPaint);
canvas->drawText("Src Opaque", sizeof("Src Opaque") - 1,
kLabelSpacing + kShapeSpacing / 2 + kShapeTypeSpacing + kPaintSpacing,
kSubtitleSpacing / 2 + fLabelPaint.getTextSize() / 3, fLabelPaint);
if (kShape_Pass == drawingPass) {
fLabelPaint.setTextAlign(SkPaint::kCenter_Align);
canvas->drawText("Src Unknown", sizeof("Src Unknown") - 1,
kLabelSpacing + kShapeSpacing / 2 + kShapeTypeSpacing,
kSubtitleSpacing / 2 + fLabelPaint.getTextSize() / 3, fLabelPaint);
canvas->drawText("Src Opaque", sizeof("Src Opaque") - 1,
kLabelSpacing + kShapeSpacing / 2 + kShapeTypeSpacing + kPaintSpacing,
kSubtitleSpacing / 2 + fLabelPaint.getTextSize() / 3, fLabelPaint);
}
canvas->translate(0, kSubtitleSpacing + kShapeSpacing/2);
@ -117,7 +116,9 @@ protected:
SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(firstMode + m);
canvas->save();
this->drawModeName(canvas, mode);
if (kShape_Pass == drawingPass) {
this->drawModeName(canvas, mode);
}
canvas->translate(kLabelSpacing + kShapeSpacing/2, 0);
for (size_t colorIdx = 0; colorIdx < SK_ARRAY_COUNT(kShapeColors); colorIdx++) {
@ -127,7 +128,20 @@ protected:
canvas->save();
for (size_t shapeIdx = 0; shapeIdx <= kLast_Shape; shapeIdx++) {
this->drawShape(canvas, static_cast<Shape>(shapeIdx), paint, mode);
if (kShape_Pass != drawingPass) {
canvas->save();
canvas->clipRect(clipRect);
if (kCheckerboard_Pass == drawingPass) {
sk_tool_utils::draw_checkerboard(canvas, 0xffffffff, 0xffc6c3c6,
10);
} else {
SkASSERT(kBackground_Pass == drawingPass);
canvas->drawColor(kBGColor, SkXfermode::kSrc_Mode);
}
canvas->restore();
} else {
this->drawShape(canvas, static_cast<Shape>(shapeIdx), paint, mode);
}
canvas->translate(kShapeTypeSpacing, 0);
}
@ -146,6 +160,28 @@ protected:
canvas->restore();
}
void onDraw(SkCanvas* canvas) override {
draw_pass(canvas, kCheckerboard_Pass);
canvas->saveLayer(NULL, NULL);
canvas->translate(kMargin, kMargin);
draw_pass(canvas, kBackground_Pass);
SkPaint titlePaint(fLabelPaint);
titlePaint.setTextSize(9 * titlePaint.getTextSize() / 8);
titlePaint.setFakeBoldText(true);
titlePaint.setTextAlign(SkPaint::kCenter_Align);
canvas->drawText("Porter Duff", sizeof("Porter Duff") - 1,
kLabelSpacing + 3 * kShapeTypeSpacing,
kTitleSpacing / 2 + titlePaint.getTextSize() / 3, titlePaint);
canvas->drawText("Advanced", sizeof("Advanced") - 1,
kXfermodeTypeSpacing + kLabelSpacing + 3 * kShapeTypeSpacing,
kTitleSpacing / 2 + titlePaint.getTextSize() / 3, titlePaint);
draw_pass(canvas, kShape_Pass);
canvas->restore();
}
void drawModeName(SkCanvas* canvas, SkXfermode::Mode mode) {
const char* modeName = mode <= SkXfermode::kLastMode ? SkXfermode::ModeName(mode)
: "Arithmetic";

View File

@ -19,6 +19,9 @@ SkTypeface::SkTypeface(const SkFontStyle& style, SkFontID fontID, bool isFixedPi
SkTypeface::~SkTypeface() { }
SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = NULL;
///////////////////////////////////////////////////////////////////////////////
class SkEmptyTypeface : public SkTypeface {
@ -110,6 +113,12 @@ bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) {
///////////////////////////////////////////////////////////////////////////////
SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) {
if (gCreateTypefaceDelegate) {
SkTypeface* result = (*gCreateTypefaceDelegate)(name, style);
if (result) {
return result;
}
}
if (NULL == name) {
return RefDefault(style);
}

View File

@ -137,7 +137,6 @@ void SkTestTypeface::getPath(const SkGlyph& glyph, SkPath* path) {
void SkTestTypeface::onFilterRec(SkScalerContextRec* rec) const {
rec->setHinting(SkPaint::kNo_Hinting);
rec->fMaskFormat = SkMask::kA8_Format;
}
SkAdvancedTypefaceMetrics* SkTestTypeface::onGetAdvancedTypefaceMetrics(
@ -243,7 +242,6 @@ protected:
glyph->fTop = ibounds.fTop;
glyph->fWidth = ibounds.width();
glyph->fHeight = ibounds.height();
glyph->fMaskFormat = SkMask::kARGB32_Format;
}
void generateImage(const SkGlyph& glyph) override {

View File

@ -19,104 +19,41 @@
#include "SkUtils.h"
#include <stdio.h>
// the folllowing include is generated by running dm with
// --portableFonts --reportUsedChars
#include "test_font_data_chars.cpp"
#define DEFAULT_FONT_NAME "Liberation Sans"
#define DEFAULT_FONT_NAME "sans-serif"
static struct FontDesc {
const char* fName;
SkTypeface::Style fStyle;
const char* fFont;
const char* fFile;
const char* fCharsUsed;
int fFontIndex;
} gFonts[] = {
{"Courier New", SkTypeface::kNormal, "Courier New", "Courier New.ttf",
gCourierNew, -1},
{"Courier New", SkTypeface::kBold, "Courier New", "Courier New Bold.ttf",
gCourierNew_Bold, -1},
{"Courier New", SkTypeface::kItalic, "Courier New", "Courier New Italic.ttf",
gCourierNew_Italic, -1},
{"Courier New", SkTypeface::kBoldItalic, "Courier New", "Courier New Bold Italic.ttf",
gCourierNew_BoldItalic, -1},
{"Helvetica", SkTypeface::kNormal, "Liberation Sans", "LiberationSans-Regular.ttf",
gLiberationSans, -1},
{"Helvetica", SkTypeface::kBold, "Liberation Sans", "LiberationSans-Bold.ttf",
gLiberationSans_Bold, -1},
{"Helvetica", SkTypeface::kItalic, "Liberation Sans", "LiberationSans-Italic.ttf",
gLiberationSans_Italic, -1},
{"Helvetica", SkTypeface::kBoldItalic, "Liberation Sans", "LiberationSans-BoldItalic.ttf",
gLiberationSans_BoldItalic, -1},
{"Hiragino Maru Gothic Pro", SkTypeface::kNormal, "Hiragino Maru Gothic Pro", "Pro W4.otf",
gHiraginoMaruGothicPro, -1},
{"Liberation Sans", SkTypeface::kNormal, "Liberation Sans", "LiberationSans-Regular.ttf",
gLiberationSans, -1},
{"Liberation Sans", SkTypeface::kBold, "Liberation Sans", "LiberationSans-Bold.ttf",
gLiberationSans_Bold, -1},
{"Liberation Sans", SkTypeface::kItalic, "Liberation Sans", "LiberationSans-Italic.ttf",
gLiberationSans_Italic, -1},
{"Liberation Sans", SkTypeface::kBoldItalic, "Liberation Sans", "LiberationSans-BoldItalic.ttf",
gLiberationSans_BoldItalic, -1},
{"monospace", SkTypeface::kNormal, "Courier New", "Courier New.ttf",
gCourierNew, -1},
{"monospace", SkTypeface::kBold, "Courier New", "Courier New Bold.ttf",
gCourierNew_Bold, -1},
{"monospace", SkTypeface::kItalic, "Courier New", "Courier New Italic.ttf",
gCourierNew_Italic, -1},
{"monospace", SkTypeface::kBoldItalic, "Courier New", "Courier New Bold Italic.ttf",
gCourierNew_BoldItalic, -1},
{"Papyrus", SkTypeface::kNormal, "Papyrus", "Papyrus.ttc",
gPapyrus, -1},
{"sans-serif", SkTypeface::kNormal, "Liberation Sans", "LiberationSans-Regular.ttf",
gLiberationSans, -1},
{"sans-serif", SkTypeface::kBold, "Liberation Sans", "LiberationSans-Bold.ttf",
gLiberationSans_Bold, -1},
{"sans-serif", SkTypeface::kItalic, "Liberation Sans", "LiberationSans-Italic.ttf",
gLiberationSans_Italic, -1},
{"sans-serif", SkTypeface::kBoldItalic, "Liberation Sans", "LiberationSans-BoldItalic.ttf",
gLiberationSans_BoldItalic, -1},
{"serif", SkTypeface::kNormal, "Times New Roman", "Times New Roman.ttf",
gTimesNewRoman, -1},
{"serif", SkTypeface::kBold, "Times New Roman", "Times New Roman Bold.ttf",
gTimesNewRoman_Bold, -1},
{"serif", SkTypeface::kItalic, "Times New Roman", "Times New Roman Italic.ttf",
gTimesNewRoman_Italic, -1},
{"serif", SkTypeface::kBoldItalic, "Times New Roman", "Times New Roman Bold Italic.ttf",
gTimesNewRoman_BoldItalic, -1},
{"Times", SkTypeface::kNormal, "Times New Roman", "Times New Roman.ttf",
gTimesNewRoman, -1},
{"Times", SkTypeface::kBold, "Times New Roman", "Times New Roman Bold.ttf",
gTimesNewRoman_Bold, -1},
{"Times", SkTypeface::kItalic, "Times New Roman", "Times New Roman Italic.ttf",
gTimesNewRoman_Italic, -1},
{"Times", SkTypeface::kBoldItalic, "Times New Roman", "Times New Roman Bold Italic.ttf",
gTimesNewRoman_BoldItalic, -1},
{"Times New Roman", SkTypeface::kNormal, "Times New Roman", "Times New Roman.ttf",
gTimesNewRoman, -1},
{"Times New Roman", SkTypeface::kBold, "Times New Roman", "Times New Roman Bold.ttf",
gTimesNewRoman_Bold, -1},
{"Times New Roman", SkTypeface::kItalic, "Times New Roman", "Times New Roman Italic.ttf",
gTimesNewRoman_Italic, -1},
{"Times New Roman", SkTypeface::kBoldItalic, "Times New Roman", "Times New Roman Bold Italic.ttf",
gTimesNewRoman_BoldItalic, -1},
{"Times Roman", SkTypeface::kNormal, "Liberation Sans", "LiberationSans-Regular.ttf",
gLiberationSans, -1},
{"monospace", SkTypeface::kNormal, "Liberation Mono", "LiberationMono-Regular.ttf", -1},
{"monospace", SkTypeface::kBold, "Liberation Mono", "LiberationMono-Bold.ttf", -1},
{"monospace", SkTypeface::kItalic, "Liberation Mono", "LiberationMono-Italic.ttf", -1},
{"monospace", SkTypeface::kBoldItalic, "Liberation Mono", "LiberationMono-BoldItalic.ttf", -1},
{"sans-serif", SkTypeface::kNormal, "Liberation Sans", "LiberationSans-Regular.ttf", -1},
{"sans-serif", SkTypeface::kBold, "Liberation Sans", "LiberationSans-Bold.ttf", -1},
{"sans-serif", SkTypeface::kItalic, "Liberation Sans", "LiberationSans-Italic.ttf", -1},
{"sans-serif", SkTypeface::kBoldItalic, "Liberation Sans", "LiberationSans-BoldItalic.ttf", -1},
{"serif", SkTypeface::kNormal, "Liberation Serif", "LiberationSerif-Regular.ttf", -1},
{"serif", SkTypeface::kBold, "Liberation Serif", "LiberationSerif-Bold.ttf", -1},
{"serif", SkTypeface::kItalic, "Liberation Serif", "LiberationSerif-Italic.ttf", -1},
{"serif", SkTypeface::kBoldItalic, "Liberation Serif", "LiberationSerif-BoldItalic.ttf", -1},
};
const int gFontsCount = (int) SK_ARRAY_COUNT(gFonts);
const char* gStyleName[] = {
"kNormal",
"kBold",
"kItalic",
"kBoldItalic",
"Normal",
"Bold",
"Italic",
"BoldItalic",
};
const char gHeader[] =
"/*\n"
" * Copyright 2014 Google Inc.\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"
@ -124,9 +61,19 @@ const char gHeader[] =
"\n"
"// Auto-generated by ";
static FILE* font_header() {
static FILE* font_header(const char* family) {
SkString outPath(SkOSPath::Join(".", "tools"));
outPath = SkOSPath::Join(outPath.c_str(), "test_font_data.cpp");
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);
outPath.append(".cpp");
FILE* out = fopen(outPath.c_str(), "w");
fprintf(out, "%s%s\n\n", gHeader, SkOSPath::Basename(__FILE__).c_str());
return out;
@ -180,10 +127,13 @@ static int output_points(const SkPoint* pts, int emSize, int count, SkString* pt
return count;
}
static void output_path_data(const SkPaint& paint, const char* used,
static void output_path_data(const SkPaint& paint,
int emSize, SkString* ptsOut, SkTDArray<SkPath::Verb>* verbs,
SkTDArray<unsigned>* charCodes, SkTDArray<SkScalar>* widths) {
while (*used) {
for (char ch = 0x20; ch < 0x7F; ++ch) {
char str[1];
str[0] = ch;
const char* used = str;
SkUnichar index = SkUTF8_NextUnichar(&used);
SkPath path;
paint.getTextPath((const void*) &index, 2, 0, 0, &path);
@ -261,8 +211,7 @@ static SkString strip_final(const SkString& str) {
return result;
}
static void output_font(SkTypeface* face, const char* name, SkTypeface::Style style,
const char* used, FILE* out) {
static void output_font(SkTypeface* face, const char* name, SkTypeface::Style style, FILE* out) {
int emSize = face->getUnitsPerEm() * 2;
SkPaint paint;
paint.setAntiAlias(true);
@ -274,7 +223,7 @@ static void output_font(SkTypeface* face, const char* name, SkTypeface::Style st
SkTDArray<unsigned> charCodes;
SkTDArray<SkScalar> widths;
SkString ptsOut;
output_path_data(paint, used, emSize, &ptsOut, &verbs, &charCodes, &widths);
output_path_data(paint, emSize, &ptsOut, &verbs, &charCodes, &widths);
SkString fontnameStr(name);
SkString strippedStr = strip_spaces(fontnameStr);
strippedStr.appendf("%s", gStyleName[style]);
@ -304,6 +253,8 @@ static void output_font(SkTypeface* face, const char* name, SkTypeface::Style st
}
fprintf(out, "\n};\n\n");
// FIXME: all fonts are now 0x20 - 0xFE
// don't need to generate or output character codes
fprintf(out, "const unsigned %sCharCodes[] = {\n", fontname);
int offsetCount = charCodes.count();
for (int index = 0; index < offsetCount;) {
@ -372,9 +323,13 @@ static int written_index(const FontDesc& fontDesc) {
return -1;
}
static void generate_fonts(FILE* out) {
static void generate_fonts() {
FILE* out = NULL;
for (int index = 0; index < gFontsCount; ++index) {
FontDesc& fontDesc = gFonts[index];
if ((index & 3) == 0) {
out = font_header(fontDesc.fName);
}
int fontIndex = written_index(fontDesc);
if (fontIndex >= 0) {
fontDesc.fFontIndex = fontIndex;
@ -382,23 +337,48 @@ static void generate_fonts(FILE* out) {
}
SkTypeface* systemTypeface = SkTypeface::CreateFromName(fontDesc.fFont, fontDesc.fStyle);
SkASSERT(systemTypeface);
SkString filepath(GetResourcePath(fontDesc.fFile));
SkString filepath("/Library/Fonts/");
filepath.append(fontDesc.fFile);
SkASSERT(sk_exists(filepath.c_str()));
SkTypeface* resourceTypeface = SkTypeface::CreateFromFile(filepath.c_str());
SkASSERT(resourceTypeface);
output_font(resourceTypeface, fontDesc.fFont, fontDesc.fStyle, fontDesc.fCharsUsed, out);
output_font(resourceTypeface, fontDesc.fFont, fontDesc.fStyle, out);
fontDesc.fFontIndex = gWritten.count();
FontWritten* writ = gWritten.append();
writ->fName = fontDesc.fFont;
writ->fStyle = fontDesc.fStyle;
if ((index & 3) == 3) {
fclose(out);
}
}
}
static void generate_index(const char* defaultName, FILE* out) {
static void generate_index(const char* defaultName) {
int fontCount = gWritten.count();
fprintf(out,
"static SkTestFontData gTestFonts[] = {\n");
FILE* out = font_header("index");
int fontIndex;
#if 0
// currently generated files are inlined one after the other.
// if the inlining is undesirable, generate externs using the code below
// (additional code required to add include files)
for (fontIndex = 0; fontIndex < fontCount; ++fontIndex) {
const FontWritten& writ = gWritten[fontIndex];
const char* name = writ.fName;
SkString strippedStr = strip_spaces(SkString(name));
strippedStr.appendf("%s", gStyleName[writ.fStyle]);
const char* strip = strippedStr.c_str();
fprintf(out,
"extern const SkScalar %sPoints[];\n"
"extern const unsigned char %sVerbs[];\n"
"extern const unsigned %sCharCodes[];\n"
"extern const int %sCharCodesCount;\n"
"extern const SkFixed %sWidths[];\n"
"extern const SkPaint::FontMetrics %sMetrics;\n",
strip, strip, strip, strip, strip, strip);
}
fprintf(out, "\n");
#endif
fprintf(out, "static SkTestFontData gTestFonts[] = {\n");
for (fontIndex = 0; fontIndex < fontCount; ++fontIndex) {
const FontWritten& writ = gWritten[fontIndex];
const char* name = writ.fName;
@ -408,7 +388,7 @@ static void generate_index(const char* defaultName, FILE* out) {
fprintf(out,
" { %sPoints, %sVerbs, %sCharCodes,\n"
" %sCharCodesCount, %sWidths,\n"
" %sMetrics, \"%s\", SkTypeface::%s, NULL\n"
" %sMetrics, \"Toy %s\", SkTypeface::k%s, NULL\n"
" },\n",
strip, strip, strip, strip, strip, strip, name, gStyleName[writ.fStyle]);
}
@ -425,26 +405,31 @@ static void generate_index(const char* defaultName, FILE* out) {
int defaultIndex = -1;
for (int subIndex = 0; subIndex < gFontsCount; subIndex++) {
const FontDesc& desc = gFonts[subIndex];
if (!strcmp(defaultName, desc.fName)) {
if (defaultIndex < 0 && !strcmp(defaultName, desc.fName)) {
defaultIndex = subIndex;
}
fprintf(out,
" { \"%s\", SkTypeface::%s, gTestFonts[%d], \"%s\"},\n", desc.fName,
" { \"%s\", SkTypeface::k%s, gTestFonts[%d], \"%s\" },\n", desc.fName,
gStyleName[desc.fStyle], desc.fFontIndex, desc.fFile);
}
for (int subIndex = 0; subIndex < gFontsCount; subIndex++) {
const FontDesc& desc = gFonts[subIndex];
fprintf(out,
" { \"Toy %s\", SkTypeface::k%s, gTestFonts[%d], \"%s\" },\n", desc.fFont,
gStyleName[desc.fStyle], desc.fFontIndex, desc.fFile);
}
fprintf(out, "};\n\n");
fprintf(out, "const int gSubFontsCount = (int) SK_ARRAY_COUNT(gSubFonts);\n\n");
SkASSERT(defaultIndex >= 0);
fprintf(out, "const int gDefaultFontIndex = %d;\n", defaultIndex);
fclose(out);
}
int main(int , char * const []) {
#ifndef SK_BUILD_FOR_MAC
#error "use fonts installed on Mac"
#endif
FILE* out = font_header();
generate_fonts(out);
generate_index(DEFAULT_FONT_NAME, out);
fclose(out);
generate_fonts();
generate_index(DEFAULT_FONT_NAME);
return 0;
}

View File

@ -312,8 +312,9 @@ void SkCommandLineFlags::Parse(int argc, char** argv) {
}
if (!flagMatched) {
#if SK_BUILD_FOR_MAC
if (SkStrStartsWith(argv[i], "NSDocumentRevisions")) {
i++; // skip YES
if (SkStrStartsWith(argv[i], "NSDocumentRevisions")
|| SkStrStartsWith(argv[i], "-NSDocumentRevisions")) {
i++; // skip YES
} else
#endif
if (FLAGS_undefok) {

View File

@ -46,11 +46,20 @@ SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style)
return face;
}
SkTypeface* create_portable_typeface_always(const char* name, SkTypeface::Style style) {
return create_font(name, style);
}
void set_portable_typeface(SkPaint* paint, const char* name, SkTypeface::Style style) {
SkTypeface* face = create_portable_typeface(name, style);
SkSafeUnref(paint->setTypeface(face));
}
void set_portable_typeface_always(SkPaint* paint, const char* name, SkTypeface::Style style) {
SkTypeface* face = create_font(name, style);
SkSafeUnref(paint->setTypeface(face));
}
void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y,
SkColorType colorType, SkAlphaType alphaType) {
SkBitmap tmp(bitmap);

View File

@ -26,11 +26,15 @@ namespace sk_tool_utils {
const char* colortype_name(SkColorType);
/**
* Sets the paint to use a platform-independent text renderer.
* Sets the paint to use a platform-independent text renderer if FLAGS_portableFonts is set.
* FIXME: will become obsolete as GMs migrate to set portable typeface always.
*/
void set_portable_typeface(SkPaint* paint, const char* name = NULL,
SkTypeface::Style style = SkTypeface::kNormal);
void set_portable_typeface_always(SkPaint* paint, const char* name = NULL,
SkTypeface::Style style = SkTypeface::kNormal);
SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style);
SkTypeface* create_portable_typeface_always(const char* name, SkTypeface::Style style);
void report_used_chars();
/**

View File

@ -6,6 +6,7 @@
*/
#include "Resources.h"
#include "SkFontMgr.h"
#include "SkOSFile.h"
#include "SkTestScalerContext.h"
#include "SkThread.h"
@ -14,7 +15,10 @@
namespace sk_tool_utils {
#include "test_font_data.cpp"
#include "test_font_monospace.cpp"
#include "test_font_sans_serif.cpp"
#include "test_font_serif.cpp"
#include "test_font_index.cpp"
static void release_portable_typefaces() {
// We'll clean this up in our own tests, but disable for clients.
@ -43,8 +47,13 @@ SkTypeface* create_font(const char* name, SkTypeface::Style style) {
}
}
if (!fontData) {
// Once all legacy callers to portable fonts are converted, replace this with
// SK_CRASH();
SkDebugf("missing %s %d\n", name, style);
return SkTypeface::CreateFromName(name, style);
// If we called SkTypeface::CreateFromName() here we'd recurse infinitely,
// so we reimplement its core logic here inline without the recursive aspect.
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
return fm->legacyCreateTypeface(name, style);
}
} else {
sub = &gSubFonts[gDefaultFontIndex];

99
tools/test_font_index.cpp Normal file
View File

@ -0,0 +1,99 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// Auto-generated by create_test_font.cpp
static SkTestFontData gTestFonts[] = {
{ LiberationMonoNormalPoints, LiberationMonoNormalVerbs, LiberationMonoNormalCharCodes,
LiberationMonoNormalCharCodesCount, LiberationMonoNormalWidths,
LiberationMonoNormalMetrics, "Toy Liberation Mono", SkTypeface::kNormal, NULL
},
{ LiberationMonoBoldPoints, LiberationMonoBoldVerbs, LiberationMonoBoldCharCodes,
LiberationMonoBoldCharCodesCount, LiberationMonoBoldWidths,
LiberationMonoBoldMetrics, "Toy Liberation Mono", SkTypeface::kBold, NULL
},
{ LiberationMonoItalicPoints, LiberationMonoItalicVerbs, LiberationMonoItalicCharCodes,
LiberationMonoItalicCharCodesCount, LiberationMonoItalicWidths,
LiberationMonoItalicMetrics, "Toy Liberation Mono", SkTypeface::kItalic, NULL
},
{ LiberationMonoBoldItalicPoints, LiberationMonoBoldItalicVerbs, LiberationMonoBoldItalicCharCodes,
LiberationMonoBoldItalicCharCodesCount, LiberationMonoBoldItalicWidths,
LiberationMonoBoldItalicMetrics, "Toy Liberation Mono", SkTypeface::kBoldItalic, NULL
},
{ LiberationSansNormalPoints, LiberationSansNormalVerbs, LiberationSansNormalCharCodes,
LiberationSansNormalCharCodesCount, LiberationSansNormalWidths,
LiberationSansNormalMetrics, "Toy Liberation Sans", SkTypeface::kNormal, NULL
},
{ LiberationSansBoldPoints, LiberationSansBoldVerbs, LiberationSansBoldCharCodes,
LiberationSansBoldCharCodesCount, LiberationSansBoldWidths,
LiberationSansBoldMetrics, "Toy Liberation Sans", SkTypeface::kBold, NULL
},
{ LiberationSansItalicPoints, LiberationSansItalicVerbs, LiberationSansItalicCharCodes,
LiberationSansItalicCharCodesCount, LiberationSansItalicWidths,
LiberationSansItalicMetrics, "Toy Liberation Sans", SkTypeface::kItalic, NULL
},
{ LiberationSansBoldItalicPoints, LiberationSansBoldItalicVerbs, LiberationSansBoldItalicCharCodes,
LiberationSansBoldItalicCharCodesCount, LiberationSansBoldItalicWidths,
LiberationSansBoldItalicMetrics, "Toy Liberation Sans", SkTypeface::kBoldItalic, NULL
},
{ LiberationSerifNormalPoints, LiberationSerifNormalVerbs, LiberationSerifNormalCharCodes,
LiberationSerifNormalCharCodesCount, LiberationSerifNormalWidths,
LiberationSerifNormalMetrics, "Toy Liberation Serif", SkTypeface::kNormal, NULL
},
{ LiberationSerifBoldPoints, LiberationSerifBoldVerbs, LiberationSerifBoldCharCodes,
LiberationSerifBoldCharCodesCount, LiberationSerifBoldWidths,
LiberationSerifBoldMetrics, "Toy Liberation Serif", SkTypeface::kBold, NULL
},
{ LiberationSerifItalicPoints, LiberationSerifItalicVerbs, LiberationSerifItalicCharCodes,
LiberationSerifItalicCharCodesCount, LiberationSerifItalicWidths,
LiberationSerifItalicMetrics, "Toy Liberation Serif", SkTypeface::kItalic, NULL
},
{ LiberationSerifBoldItalicPoints, LiberationSerifBoldItalicVerbs, LiberationSerifBoldItalicCharCodes,
LiberationSerifBoldItalicCharCodesCount, LiberationSerifBoldItalicWidths,
LiberationSerifBoldItalicMetrics, "Toy Liberation Serif", SkTypeface::kBoldItalic, NULL
},
};
const int gTestFontsCount = (int) SK_ARRAY_COUNT(gTestFonts);
struct SubFont {
const char* fName;
SkTypeface::Style fStyle;
SkTestFontData& fFont;
const char* fFile;
};
const SubFont gSubFonts[] = {
{ "monospace", SkTypeface::kNormal, gTestFonts[0], "LiberationMono-Regular.ttf" },
{ "monospace", SkTypeface::kBold, gTestFonts[1], "LiberationMono-Bold.ttf" },
{ "monospace", SkTypeface::kItalic, gTestFonts[2], "LiberationMono-Italic.ttf" },
{ "monospace", SkTypeface::kBoldItalic, gTestFonts[3], "LiberationMono-BoldItalic.ttf" },
{ "sans-serif", SkTypeface::kNormal, gTestFonts[4], "LiberationSans-Regular.ttf" },
{ "sans-serif", SkTypeface::kBold, gTestFonts[5], "LiberationSans-Bold.ttf" },
{ "sans-serif", SkTypeface::kItalic, gTestFonts[6], "LiberationSans-Italic.ttf" },
{ "sans-serif", SkTypeface::kBoldItalic, gTestFonts[7], "LiberationSans-BoldItalic.ttf" },
{ "serif", SkTypeface::kNormal, gTestFonts[8], "LiberationSerif-Regular.ttf" },
{ "serif", SkTypeface::kBold, gTestFonts[9], "LiberationSerif-Bold.ttf" },
{ "serif", SkTypeface::kItalic, gTestFonts[10], "LiberationSerif-Italic.ttf" },
{ "serif", SkTypeface::kBoldItalic, gTestFonts[11], "LiberationSerif-BoldItalic.ttf" },
{ "Toy Liberation Mono", SkTypeface::kNormal, gTestFonts[0], "LiberationMono-Regular.ttf" },
{ "Toy Liberation Mono", SkTypeface::kBold, gTestFonts[1], "LiberationMono-Bold.ttf" },
{ "Toy Liberation Mono", SkTypeface::kItalic, gTestFonts[2], "LiberationMono-Italic.ttf" },
{ "Toy Liberation Mono", SkTypeface::kBoldItalic, gTestFonts[3], "LiberationMono-BoldItalic.ttf" },
{ "Toy Liberation Sans", SkTypeface::kNormal, gTestFonts[4], "LiberationSans-Regular.ttf" },
{ "Toy Liberation Sans", SkTypeface::kBold, gTestFonts[5], "LiberationSans-Bold.ttf" },
{ "Toy Liberation Sans", SkTypeface::kItalic, gTestFonts[6], "LiberationSans-Italic.ttf" },
{ "Toy Liberation Sans", SkTypeface::kBoldItalic, gTestFonts[7], "LiberationSans-BoldItalic.ttf" },
{ "Toy Liberation Serif", SkTypeface::kNormal, gTestFonts[8], "LiberationSerif-Regular.ttf" },
{ "Toy Liberation Serif", SkTypeface::kBold, gTestFonts[9], "LiberationSerif-Bold.ttf" },
{ "Toy Liberation Serif", SkTypeface::kItalic, gTestFonts[10], "LiberationSerif-Italic.ttf" },
{ "Toy Liberation Serif", SkTypeface::kBoldItalic, gTestFonts[11], "LiberationSerif-BoldItalic.ttf" },
};
const int gSubFontsCount = (int) SK_ARRAY_COUNT(gSubFonts);
const int gDefaultFontIndex = 4;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

5150
tools/test_font_serif.cpp Normal file

File diff suppressed because it is too large Load Diff