992c7b03ef
Allow GM results to be compared across machines and platforms by standardizing the fonts used by all tests. This adds runtime flags to DM to use either the system font context (the default), the fonts in the resources directory ( --resourceFonts ) or a set of canonical paths generated from the fonts ( --portableFonts ). This CL should leave the current DM results unchanged by default. If the portable font data or resource font is missing when DM is run, it falls back to using the system font context. The create_test_font tool generates the paths and metrics read by DM with the --portableFonts flag set, and generates the font substitution tables read by DM with the --resourceFonts flag set. If DM is run in SkDebug mode with the --reportUsedChars flag set, it generates the corresponding data compiled into the create_test_font tool. All GM tests set their typeface information by calling either sk_tool_utils::set_portable_typeface or sk_tool_utils::portable_typeface . (The former takes the paint, the latter returns a SkTypeface.) These calls can be removed in the future when the Font Manager can be superceded. BUG=skia:2687 R=mtklein@google.com Review URL: https://codereview.chromium.org/407183003
94 lines
2.9 KiB
C++
94 lines
2.9 KiB
C++
/*
|
|
* Copyright 2011 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "gm.h"
|
|
#include "SkCanvas.h"
|
|
#include "SkPath.h"
|
|
#include "SkTypeface.h"
|
|
|
|
namespace skiagm {
|
|
|
|
class StrokeFillGM : public GM {
|
|
public:
|
|
StrokeFillGM() {
|
|
|
|
}
|
|
|
|
protected:
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
return kSkipTiled_Flag;
|
|
}
|
|
|
|
virtual SkString onShortName() {
|
|
return SkString("stroke-fill");
|
|
}
|
|
|
|
virtual SkISize onISize() {
|
|
return SkISize::Make(640, 480);
|
|
}
|
|
|
|
static void show_bold(SkCanvas* canvas, const void* text, int len,
|
|
SkScalar x, SkScalar y, const SkPaint& paint) {
|
|
SkPaint p(paint);
|
|
canvas->drawText(text, len, x, y, p);
|
|
p.setFakeBoldText(true);
|
|
canvas->drawText(text, len, x, y + SkIntToScalar(120), p);
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
SkScalar x = SkIntToScalar(100);
|
|
SkScalar y = SkIntToScalar(88);
|
|
|
|
SkPaint paint;
|
|
paint.setAntiAlias(true);
|
|
paint.setTextSize(SkIntToScalar(100));
|
|
paint.setStrokeWidth(SkIntToScalar(5));
|
|
|
|
sk_tool_utils::set_portable_typeface(&paint, "Papyrus");
|
|
show_bold(canvas, "Hello", 5, x, y, paint);
|
|
|
|
sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro");
|
|
const unsigned char hyphen[] = { 0xE3, 0x83, 0xBC };
|
|
show_bold(canvas, hyphen, SK_ARRAY_COUNT(hyphen), x + SkIntToScalar(300), y, paint);
|
|
|
|
paint.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
SkPath path;
|
|
path.setFillType(SkPath::kWinding_FillType);
|
|
path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
|
|
path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCCW_Direction);
|
|
canvas->drawPath(path, paint);
|
|
|
|
SkPath path2;
|
|
path2.setFillType(SkPath::kWinding_FillType);
|
|
path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
|
|
path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCW_Direction);
|
|
canvas->drawPath(path2, paint);
|
|
|
|
path2.reset();
|
|
path2.addCircle(x + SkIntToScalar(240), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
|
|
canvas->drawPath(path2, paint);
|
|
SkASSERT(path2.cheapIsDirection(SkPath::kCCW_Direction));
|
|
|
|
path2.reset();
|
|
SkASSERT(!path2.cheapComputeDirection(NULL));
|
|
path2.addCircle(x + SkIntToScalar(360), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
|
|
SkASSERT(path2.cheapIsDirection(SkPath::kCW_Direction));
|
|
canvas->drawPath(path2, paint);
|
|
}
|
|
|
|
private:
|
|
typedef GM INHERITED;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
static GM* MyFactory(void*) { return new StrokeFillGM; }
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
}
|