2014-03-12 20:31:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2014-03-12 20:31:24 +00:00
|
|
|
#include "SkCanvas.h"
|
2014-05-22 17:41:41 +00:00
|
|
|
#include "SkDashPathEffect.h"
|
2018-12-24 19:52:46 +00:00
|
|
|
#include "SkTextBlob.h"
|
2014-03-12 20:31:24 +00:00
|
|
|
|
2014-03-14 14:02:58 +00:00
|
|
|
static void test_nulldev(SkCanvas* canvas) {
|
|
|
|
SkBitmap bm;
|
2014-06-10 02:52:07 +00:00
|
|
|
bm.setInfo(SkImageInfo::MakeN32Premul(30, 30));
|
2014-03-14 14:02:58 +00:00
|
|
|
// notice: no pixels mom! be sure we don't crash
|
|
|
|
// https://code.google.com/p/chromium/issues/detail?id=352616
|
|
|
|
SkCanvas c(bm);
|
|
|
|
|
|
|
|
SkBitmap src;
|
|
|
|
src.allocN32Pixels(10, 10);
|
|
|
|
src.eraseColor(SK_ColorRED);
|
|
|
|
|
|
|
|
// ensure we don't crash
|
|
|
|
c.writePixels(src, 0, 0);
|
|
|
|
}
|
|
|
|
|
2018-12-24 19:52:46 +00:00
|
|
|
static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint, const SkFont& font,
|
|
|
|
SkScalar strokeWidth) {
|
2014-03-12 20:31:24 +00:00
|
|
|
SkPaint p(paint);
|
2014-05-22 17:41:41 +00:00
|
|
|
SkPoint loc = { 20, 435 };
|
2014-03-13 03:02:23 +00:00
|
|
|
|
2014-05-22 17:41:41 +00:00
|
|
|
if (strokeWidth > 0) {
|
|
|
|
p.setStyle(SkPaint::kFill_Style);
|
2018-12-24 19:52:46 +00:00
|
|
|
canvas->drawSimpleText("P", 1, kUTF8_SkTextEncoding, loc.fX, loc.fY - 225, font, p);
|
|
|
|
canvas->drawTextBlob(SkTextBlob::MakeFromPosText("P", 1, &loc, font), 0, 0, p);
|
2014-05-22 17:41:41 +00:00
|
|
|
}
|
2014-03-13 03:02:23 +00:00
|
|
|
|
2014-03-12 20:31:24 +00:00
|
|
|
p.setColor(SK_ColorRED);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
2014-05-22 17:41:41 +00:00
|
|
|
p.setStrokeWidth(strokeWidth);
|
2014-03-13 03:02:23 +00:00
|
|
|
|
2018-12-24 19:52:46 +00:00
|
|
|
canvas->drawSimpleText("P", 1, kUTF8_SkTextEncoding, loc.fX, loc.fY - 225, font, p);
|
|
|
|
canvas->drawTextBlob(SkTextBlob::MakeFromPosText("P", 1, &loc, font), 0, 0, p);
|
2014-03-12 20:31:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-24 19:52:46 +00:00
|
|
|
static void draw_text_set(SkCanvas* canvas, const SkPaint& paint, const SkFont& font) {
|
2014-05-22 17:41:41 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
2018-12-24 19:52:46 +00:00
|
|
|
draw_text_stroked(canvas, paint, font, 10);
|
2014-05-22 17:41:41 +00:00
|
|
|
|
|
|
|
canvas->translate(200, 0);
|
2018-12-24 19:52:46 +00:00
|
|
|
draw_text_stroked(canvas, paint, font, 0);
|
2014-05-22 17:41:41 +00:00
|
|
|
|
|
|
|
const SkScalar intervals[] = { 20, 10, 5, 10 };
|
|
|
|
const SkScalar phase = 0;
|
|
|
|
|
|
|
|
canvas->translate(200, 0);
|
|
|
|
SkPaint p(paint);
|
2016-03-18 18:22:57 +00:00
|
|
|
p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), phase));
|
2018-12-24 19:52:46 +00:00
|
|
|
draw_text_stroked(canvas, p, font, 10);
|
2014-05-22 17:41:41 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
namespace {
|
2014-03-12 20:31:24 +00:00
|
|
|
enum {
|
|
|
|
kBelowThreshold_TextSize = 255,
|
|
|
|
kAboveThreshold_TextSize = 257
|
|
|
|
};
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|
2014-03-12 20:31:24 +00:00
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
DEF_SIMPLE_GM(stroketext, canvas, 1200, 480) {
|
2018-12-24 19:52:46 +00:00
|
|
|
if (true) { test_nulldev(canvas); }
|
2014-03-13 03:02:23 +00:00
|
|
|
|
2018-12-24 19:52:46 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2014-03-13 03:02:23 +00:00
|
|
|
|
2018-12-24 19:52:46 +00:00
|
|
|
SkFont font(sk_tool_utils::create_portable_typeface(), kBelowThreshold_TextSize);
|
|
|
|
draw_text_set(canvas, paint, font);
|
|
|
|
|
|
|
|
canvas->translate(600, 0);
|
|
|
|
font.setSize(kAboveThreshold_TextSize);
|
|
|
|
draw_text_set(canvas, paint, font);
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|