diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-05-22 17:41:41 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-05-22 17:41:41 +0000 |
commit | 74266814a0d0fd5b0ec9be664be6b629aeddc0ea (patch) | |
tree | f9ce1c959b74fc7d8ee249c7f3b5371bfd16d503 /gm | |
parent | df1d83d7866836aa89e9aa762eda4f60a0588423 (diff) |
update stroketext gm
TBR=bungeman
Author: reed@google.com
Review URL: https://codereview.chromium.org/293983016
git-svn-id: http://skia.googlecode.com/svn/trunk@14848 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm')
-rw-r--r-- | gm/stroketext.cpp | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/gm/stroketext.cpp b/gm/stroketext.cpp index 387843a0b4..80c63fdc37 100644 --- a/gm/stroketext.cpp +++ b/gm/stroketext.cpp @@ -7,6 +7,7 @@ #include "gm.h" #include "SkCanvas.h" +#include "SkDashPathEffect.h" static void test_nulldev(SkCanvas* canvas) { SkBitmap bm; @@ -23,21 +24,41 @@ static void test_nulldev(SkCanvas* canvas) { c.writePixels(src, 0, 0); } -static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint) { +static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint, SkScalar strokeWidth) { SkPaint p(paint); - SkPoint loc = { 20, 450 }; + SkPoint loc = { 20, 435 }; - canvas->drawText("P", 1, loc.fX, loc.fY - 225, p); - canvas->drawPosText("P", 1, &loc, p); + if (strokeWidth > 0) { + p.setStyle(SkPaint::kFill_Style); + canvas->drawText("P", 1, loc.fX, loc.fY - 225, p); + canvas->drawPosText("P", 1, &loc, p); + } p.setColor(SK_ColorRED); p.setStyle(SkPaint::kStroke_Style); - p.setStrokeWidth(10); + p.setStrokeWidth(strokeWidth); canvas->drawText("P", 1, loc.fX, loc.fY - 225, p); canvas->drawPosText("P", 1, &loc, p); } +static void draw_text_set(SkCanvas* canvas, const SkPaint& paint) { + SkAutoCanvasRestore acr(canvas, true); + + draw_text_stroked(canvas, paint, 10); + + canvas->translate(200, 0); + draw_text_stroked(canvas, paint, 0); + + const SkScalar intervals[] = { 20, 10, 5, 10 }; + const SkScalar phase = 0; + + canvas->translate(200, 0); + SkPaint p(paint); + p.setPathEffect(SkDashPathEffect::Create(intervals, SK_ARRAY_COUNT(intervals), phase))->unref(); + draw_text_stroked(canvas, paint, 10); +} + class StrokeTextGM : public skiagm::GM { // Skia has a threshold above which it draws text via paths instead of using scalercontext // and caching the glyph. This GM wants to ensure that we draw stroking correctly on both @@ -59,7 +80,7 @@ protected: } virtual SkISize onISize() SK_OVERRIDE { - return SkISize::Make(640, 480); + return SkISize::Make(1200, 480); } virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { @@ -68,11 +89,11 @@ protected: paint.setAntiAlias(true); paint.setTextSize(kBelowThreshold_TextSize); - draw_text_stroked(canvas, paint); + draw_text_set(canvas, paint); - canvas->translate(200, 0); + canvas->translate(600, 0); paint.setTextSize(kAboveThreshold_TextSize); - draw_text_stroked(canvas, paint); + draw_text_set(canvas, paint); } private: |