From 74266814a0d0fd5b0ec9be664be6b629aeddc0ea Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Thu, 22 May 2014 17:41:41 +0000 Subject: [PATCH] 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 --- expectations/gm/ignored-tests.txt | 4 ++++ gm/stroketext.cpp | 39 ++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/expectations/gm/ignored-tests.txt b/expectations/gm/ignored-tests.txt index 81313f1592..5d0ad0637e 100644 --- a/expectations/gm/ignored-tests.txt +++ b/expectations/gm/ignored-tests.txt @@ -64,3 +64,7 @@ tilemodes shadertext3 shadertext shadertext2 + +# Changing this GM to add more test cases (failing at the moment) +# Need to rebaseline when they are fixed +stroketext 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: