blob: e6ffa0ec85f437605cfed7944878e79f106d041c [file] [log] [blame]
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +00001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkCanvas.h"
10
11static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint) {
12 SkPaint p(paint);
13 SkPoint loc = { 20, 450 };
14
15 canvas->drawText("P", 1, loc.fX, loc.fY - 225, p);
16 canvas->drawPosText("P", 1, &loc, p);
17
18 p.setColor(SK_ColorRED);
19 p.setStyle(SkPaint::kStroke_Style);
20 p.setStrokeWidth(10);
21
22 canvas->drawText("P", 1, loc.fX, loc.fY - 225, p);
23 canvas->drawPosText("P", 1, &loc, p);
24}
25
26class StrokeTextGM : public skiagm::GM {
27 // Skia has a threshold above which it draws text via paths instead of using scalercontext
28 // and caching the glyph. This GM wants to ensure that we draw stroking correctly on both
29 // sides of this threshold.
30 enum {
31 kBelowThreshold_TextSize = 255,
32 kAboveThreshold_TextSize = 257
33 };
34public:
35 StrokeTextGM() {}
36
37protected:
38 virtual SkString onShortName() SK_OVERRIDE {
39 return SkString("stroketext");
40 }
41
42 virtual SkISize onISize() SK_OVERRIDE {
43 return SkISize::Make(640, 480);
44 }
45
46 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
47 SkPaint paint;
48 paint.setAntiAlias(true);
49
50 paint.setTextSize(kBelowThreshold_TextSize);
51 draw_text_stroked(canvas, paint);
52
53 canvas->translate(200, 0);
54 paint.setTextSize(kAboveThreshold_TextSize);
55 draw_text_stroked(canvas, paint);
56 }
57
58private:
59 typedef skiagm::GM INHERITED;
60};
61
62DEF_GM( return SkNEW(StrokeTextGM); )