blob: b9d56f10e470b167e9df738e3d3a671209a0d073 [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
reed@google.com0d30c512014-03-14 14:02:58 +000011static void test_nulldev(SkCanvas* canvas) {
12 SkBitmap bm;
13 bm.setConfig(SkBitmap::kARGB_8888_Config, 30, 30);
14 // notice: no pixels mom! be sure we don't crash
15 // https://code.google.com/p/chromium/issues/detail?id=352616
16 SkCanvas c(bm);
17
18 SkBitmap src;
19 src.allocN32Pixels(10, 10);
20 src.eraseColor(SK_ColorRED);
21
22 // ensure we don't crash
23 c.writePixels(src, 0, 0);
24}
25
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +000026static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint) {
27 SkPaint p(paint);
28 SkPoint loc = { 20, 450 };
skia.committer@gmail.comaffa77d2014-03-13 03:02:23 +000029
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +000030 canvas->drawText("P", 1, loc.fX, loc.fY - 225, p);
31 canvas->drawPosText("P", 1, &loc, p);
skia.committer@gmail.comaffa77d2014-03-13 03:02:23 +000032
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +000033 p.setColor(SK_ColorRED);
34 p.setStyle(SkPaint::kStroke_Style);
35 p.setStrokeWidth(10);
skia.committer@gmail.comaffa77d2014-03-13 03:02:23 +000036
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +000037 canvas->drawText("P", 1, loc.fX, loc.fY - 225, p);
38 canvas->drawPosText("P", 1, &loc, p);
39}
40
41class StrokeTextGM : public skiagm::GM {
42 // Skia has a threshold above which it draws text via paths instead of using scalercontext
43 // and caching the glyph. This GM wants to ensure that we draw stroking correctly on both
44 // sides of this threshold.
45 enum {
46 kBelowThreshold_TextSize = 255,
47 kAboveThreshold_TextSize = 257
48 };
49public:
50 StrokeTextGM() {}
51
52protected:
53 virtual SkString onShortName() SK_OVERRIDE {
54 return SkString("stroketext");
55 }
56
57 virtual SkISize onISize() SK_OVERRIDE {
58 return SkISize::Make(640, 480);
59 }
60
61 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
reed@google.com0d30c512014-03-14 14:02:58 +000062 if (true) { test_nulldev(canvas); }
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +000063 SkPaint paint;
64 paint.setAntiAlias(true);
skia.committer@gmail.comaffa77d2014-03-13 03:02:23 +000065
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +000066 paint.setTextSize(kBelowThreshold_TextSize);
67 draw_text_stroked(canvas, paint);
skia.committer@gmail.comaffa77d2014-03-13 03:02:23 +000068
commit-bot@chromium.org641e33b2014-03-12 20:31:24 +000069 canvas->translate(200, 0);
70 paint.setTextSize(kAboveThreshold_TextSize);
71 draw_text_stroked(canvas, paint);
72 }
73
74private:
75 typedef skiagm::GM INHERITED;
76};
77
78DEF_GM( return SkNEW(StrokeTextGM); )