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.
9 #include "sk_tool_utils.h"
11 #include "SkDashPathEffect.h"
13 static void test_nulldev(SkCanvas* canvas) {
15 bm.setInfo(SkImageInfo::MakeN32Premul(30, 30));
16 // notice: no pixels mom! be sure we don't crash
17 // https://code.google.com/p/chromium/issues/detail?id=352616
21 src.allocN32Pixels(10, 10);
22 src.eraseColor(SK_ColorRED);
24 // ensure we don't crash
25 c.writePixels(src, 0, 0);
28 static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint, SkScalar strokeWidth) {
30 SkPoint loc = { 20, 435 };
32 if (strokeWidth > 0) {
33 p.setStyle(SkPaint::kFill_Style);
34 canvas->drawString("P", loc.fX, loc.fY - 225, p);
35 canvas->drawPosText("P", 1, &loc, p);
38 p.setColor(SK_ColorRED);
39 p.setStyle(SkPaint::kStroke_Style);
40 p.setStrokeWidth(strokeWidth);
42 canvas->drawString("P", loc.fX, loc.fY - 225, p);
43 canvas->drawPosText("P", 1, &loc, p);
46 static void draw_text_set(SkCanvas* canvas, const SkPaint& paint) {
47 SkAutoCanvasRestore acr(canvas, true);
49 draw_text_stroked(canvas, paint, 10);
51 canvas->translate(200, 0);
52 draw_text_stroked(canvas, paint, 0);
54 const SkScalar intervals[] = { 20, 10, 5, 10 };
55 const SkScalar phase = 0;
57 canvas->translate(200, 0);
59 p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), phase));
60 draw_text_stroked(canvas, p, 10);
65 kBelowThreshold_TextSize = 255,
66 kAboveThreshold_TextSize = 257
70 DEF_SIMPLE_GM(stroketext, canvas, 1200, 480) {
71 if (true) { test_nulldev(canvas); }
73 paint.setAntiAlias(true);
74 sk_tool_utils::set_portable_typeface(&paint);
76 paint.setTextSize(kBelowThreshold_TextSize);
77 draw_text_set(canvas, paint);
79 canvas->translate(600, 0);
80 paint.setTextSize(kAboveThreshold_TextSize);
81 draw_text_set(canvas, paint);