2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkDashPathEffect.h"
12 static void test_nulldev(SkCanvas* canvas) {
14 bm.setInfo(SkImageInfo::MakeN32Premul(30, 30));
15 // notice: no pixels mom! be sure we don't crash
16 // https://code.google.com/p/chromium/issues/detail?id=352616
20 src.allocN32Pixels(10, 10);
21 src.eraseColor(SK_ColorRED);
23 // ensure we don't crash
24 c.writePixels(src, 0, 0);
27 static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint, SkScalar strokeWidth) {
29 SkPoint loc = { 20, 435 };
31 if (strokeWidth > 0) {
32 p.setStyle(SkPaint::kFill_Style);
33 canvas->drawText("P", 1, loc.fX, loc.fY - 225, p);
34 canvas->drawPosText("P", 1, &loc, p);
37 p.setColor(SK_ColorRED);
38 p.setStyle(SkPaint::kStroke_Style);
39 p.setStrokeWidth(strokeWidth);
41 canvas->drawText("P", 1, loc.fX, loc.fY - 225, p);
42 canvas->drawPosText("P", 1, &loc, p);
45 static void draw_text_set(SkCanvas* canvas, const SkPaint& paint) {
46 SkAutoCanvasRestore acr(canvas, true);
48 draw_text_stroked(canvas, paint, 10);
50 canvas->translate(200, 0);
51 draw_text_stroked(canvas, paint, 0);
53 const SkScalar intervals[] = { 20, 10, 5, 10 };
54 const SkScalar phase = 0;
56 canvas->translate(200, 0);
58 p.setPathEffect(SkDashPathEffect::Create(intervals, SK_ARRAY_COUNT(intervals), phase))->unref();
59 draw_text_stroked(canvas, p, 10);
62 class StrokeTextGM : public skiagm::GM {
63 // Skia has a threshold above which it draws text via paths instead of using scalercontext
64 // and caching the glyph. This GM wants to ensure that we draw stroking correctly on both
65 // sides of this threshold.
67 kBelowThreshold_TextSize = 255,
68 kAboveThreshold_TextSize = 257
75 SkString onShortName() override {
76 return SkString("stroketext");
79 SkISize onISize() override {
80 return SkISize::Make(1200, 480);
83 void onDraw(SkCanvas* canvas) override {
84 if (true) { test_nulldev(canvas); }
86 paint.setAntiAlias(true);
87 sk_tool_utils::set_portable_typeface(&paint);
89 paint.setTextSize(kBelowThreshold_TextSize);
90 draw_text_set(canvas, paint);
92 canvas->translate(600, 0);
93 paint.setTextSize(kAboveThreshold_TextSize);
94 draw_text_set(canvas, paint);
98 typedef skiagm::GM INHERITED;
101 DEF_GM( return SkNEW(StrokeTextGM); )