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
122 lines
2.8 KiB
C++
122 lines
2.8 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"
|
|
|
|
static void test_path(SkCanvas* canvas, const SkPath& path) {
|
|
SkPaint paint;
|
|
paint.setAntiAlias(true);
|
|
canvas->drawPath(path, paint);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
paint.setColor(SK_ColorRED);
|
|
canvas->drawPath(path, paint);
|
|
}
|
|
|
|
static void test_rev(SkCanvas* canvas, const SkPath& path) {
|
|
test_path(canvas, path);
|
|
|
|
SkPath rev;
|
|
rev.reverseAddPath(path);
|
|
canvas->save();
|
|
canvas->translate(150, 0);
|
|
test_path(canvas, rev);
|
|
canvas->restore();
|
|
}
|
|
|
|
static void test_rev(SkCanvas* canvas) {
|
|
SkRect r = { 10, 10, 100, 60 };
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(r); test_rev(canvas, path);
|
|
|
|
canvas->translate(0, 100);
|
|
path.offset(20, 20);
|
|
path.addRect(r); test_rev(canvas, path);
|
|
|
|
canvas->translate(0, 100);
|
|
path.reset();
|
|
path.moveTo(10, 10); path.lineTo(30, 30);
|
|
path.addOval(r);
|
|
r.offset(50, 20);
|
|
path.addOval(r);
|
|
test_rev(canvas, path);
|
|
|
|
SkPaint paint;
|
|
paint.setTextSize(SkIntToScalar(100));
|
|
sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro");
|
|
path.reset();
|
|
paint.getTextPath("e", 1, 50, 50, &path);
|
|
canvas->translate(0, 100);
|
|
test_rev(canvas, path);
|
|
}
|
|
|
|
namespace skiagm {
|
|
|
|
class PathReverseGM : public GM {
|
|
public:
|
|
PathReverseGM() {
|
|
|
|
}
|
|
|
|
protected:
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
return kSkipTiled_Flag;
|
|
}
|
|
|
|
virtual SkString onShortName() {
|
|
return SkString("path-reverse");
|
|
}
|
|
|
|
virtual SkISize onISize() {
|
|
return SkISize::Make(640, 480);
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
if (false) test_rev(canvas); // avoid bit rot, suppress warning
|
|
SkRect r = { 10, 10, 100, 60 };
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(r); test_rev(canvas, path);
|
|
|
|
canvas->translate(0, 100);
|
|
path.offset(20, 20);
|
|
path.addRect(r); test_rev(canvas, path);
|
|
|
|
canvas->translate(0, 100);
|
|
path.reset();
|
|
path.moveTo(10, 10); path.lineTo(30, 30);
|
|
path.addOval(r);
|
|
r.offset(50, 20);
|
|
path.addOval(r);
|
|
test_rev(canvas, path);
|
|
|
|
SkPaint paint;
|
|
paint.setTextSize(SkIntToScalar(100));
|
|
sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro");
|
|
path.reset();
|
|
paint.getTextPath("e", 1, 50, 50, &path);
|
|
canvas->translate(0, 100);
|
|
test_rev(canvas, path);
|
|
}
|
|
|
|
private:
|
|
typedef GM INHERITED;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
static GM* MyFactory(void*) { return new PathReverseGM; }
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
}
|