blob: 1791fea528ca3f4a1bf4cf3c7e1f4f6fd134f793 [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 };
skia.committer@gmail.comaffa77d2014-03-13 03:02:23 +000014
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +000015 canvas->drawText("P", 1, loc.fX, loc.fY - 225, p);
16 canvas->drawPosText("P", 1, &loc, p);
skia.committer@gmail.comaffa77d2014-03-13 03:02:23 +000017
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +000018 p.setColor(SK_ColorRED);
19 p.setStyle(SkPaint::kStroke_Style);
20 p.setStrokeWidth(10);
skia.committer@gmail.comaffa77d2014-03-13 03:02:23 +000021
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +000022 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);
skia.committer@gmail.comaffa77d2014-03-13 03:02:23 +000049
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +000050 paint.setTextSize(kBelowThreshold_TextSize);
51 draw_text_stroked(canvas, paint);
skia.committer@gmail.comaffa77d2014-03-13 03:02:23 +000052
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +000053 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); )