| Index: gm/patheffect4bigtext.cpp
|
| diff --git a/gm/patheffect4bigtext.cpp b/gm/patheffect4bigtext.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b090674678929761f6f1269b859db5e38daf8378
|
| --- /dev/null
|
| +++ b/gm/patheffect4bigtext.cpp
|
| @@ -0,0 +1,78 @@
|
| +/*
|
| + * Copyright 2014 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 "Sk2DPathEffect.h"
|
| +#include "SkCanvas.h"
|
| +
|
| +// PathEffect for a text impacts the paths generated for the text. Big text
|
| +// and hairline text are drawn by paths, instead of using scalercontext and
|
| +// caching the glyph. This GM wants to ensure that we draw filled, thick-stroked,
|
| +// and hairline-stroked text with path effect correctly on both sides of the
|
| +// threshold.
|
| +static void draw_text(SkCanvas* canvas, const SkPaint& paint) {
|
| + SkPaint p(paint);
|
| +
|
| + SkPoint loc = { 250, 225 };
|
| + p.setColor(SK_ColorRED);
|
| +
|
| + canvas->drawText("P", 1, loc.fX - 225, loc.fY, p);
|
| + canvas->drawPosText("P", 1, &loc, p);
|
| +
|
| + loc.set(250, 450);
|
| + p.setColor(SK_ColorGREEN);
|
| + p.setStyle(SkPaint::kStroke_Style);
|
| + p.setStrokeWidth(10);
|
| + canvas->drawText("P", 1, loc.fX - 225, loc.fY, p);
|
| + canvas->drawPosText("P", 1, &loc, p);
|
| +
|
| + loc.set(250, 675);
|
| + p.setColor(SK_ColorBLUE);
|
| + p.setStrokeWidth(0);
|
| + canvas->drawText("P", 1, loc.fX - 225, loc.fY, p);
|
| + canvas->drawPosText("P", 1, &loc, p);
|
| +}
|
| +
|
| +class PathEffect4BigTextGM : public skiagm::GM {
|
| +public:
|
| + PathEffect4BigTextGM() {}
|
| +
|
| +protected:
|
| + virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
| + return kSkipTiled_Flag;
|
| + }
|
| +
|
| + virtual SkString onShortName() SK_OVERRIDE {
|
| + return SkString("patheffect4bigtext");
|
| + }
|
| +
|
| + virtual SkISize onISize() SK_OVERRIDE {
|
| + return SkISize::Make(900, 700);
|
| + }
|
| +
|
| + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
| + SkPaint paint;
|
| + paint.setAntiAlias(true);
|
| +
|
| + SkMatrix lattice;
|
| + lattice.setScale(SK_Scalar1, SK_Scalar1 * 6, 0, 0);
|
| + lattice.postRotate(SkIntToScalar(30), 0, 0);
|
| + paint.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1 * 2, lattice))->unref();
|
| +
|
| + SkScalar textSize[2] = {240, 270};
|
| + for (size_t i = 0; i < SK_ARRAY_COUNT(textSize); ++i) {
|
| + paint.setTextSize(textSize[i]);
|
| + draw_text(canvas, paint);
|
| + canvas->translate(450, 0);
|
| + }
|
| + }
|
| +
|
| +private:
|
| + typedef skiagm::GM INHERITED;
|
| +};
|
| +
|
| +DEF_GM( return SkNEW(PathEffect4BigTextGM); )
|
|
|