commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gm.h" |
| 9 | #include "SkCanvas.h" |
| 10 | |
| 11 | static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint) { |
| 12 | SkPaint p(paint); |
| 13 | SkPoint loc = { 20, 450 }; |
skia.committer@gmail.com | affa77d | 2014-03-13 03:02:23 +0000 | [diff] [blame] | 14 | |
commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 15 | canvas->drawText("P", 1, loc.fX, loc.fY - 225, p); |
| 16 | canvas->drawPosText("P", 1, &loc, p); |
skia.committer@gmail.com | affa77d | 2014-03-13 03:02:23 +0000 | [diff] [blame] | 17 | |
commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 18 | p.setColor(SK_ColorRED); |
| 19 | p.setStyle(SkPaint::kStroke_Style); |
| 20 | p.setStrokeWidth(10); |
skia.committer@gmail.com | affa77d | 2014-03-13 03:02:23 +0000 | [diff] [blame] | 21 | |
commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 22 | canvas->drawText("P", 1, loc.fX, loc.fY - 225, p); |
| 23 | canvas->drawPosText("P", 1, &loc, p); |
| 24 | } |
| 25 | |
| 26 | class StrokeTextGM : public skiagm::GM { |
| 27 | // Skia has a threshold above which it draws text via paths instead of using scalercontext |
| 28 | // and caching the glyph. This GM wants to ensure that we draw stroking correctly on both |
| 29 | // sides of this threshold. |
| 30 | enum { |
| 31 | kBelowThreshold_TextSize = 255, |
| 32 | kAboveThreshold_TextSize = 257 |
| 33 | }; |
| 34 | public: |
| 35 | StrokeTextGM() {} |
| 36 | |
| 37 | protected: |
| 38 | virtual SkString onShortName() SK_OVERRIDE { |
| 39 | return SkString("stroketext"); |
| 40 | } |
| 41 | |
| 42 | virtual SkISize onISize() SK_OVERRIDE { |
| 43 | return SkISize::Make(640, 480); |
| 44 | } |
| 45 | |
| 46 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 47 | SkPaint paint; |
| 48 | paint.setAntiAlias(true); |
skia.committer@gmail.com | affa77d | 2014-03-13 03:02:23 +0000 | [diff] [blame] | 49 | |
commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 50 | paint.setTextSize(kBelowThreshold_TextSize); |
| 51 | draw_text_stroked(canvas, paint); |
skia.committer@gmail.com | affa77d | 2014-03-13 03:02:23 +0000 | [diff] [blame] | 52 | |
commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 53 | canvas->translate(200, 0); |
| 54 | paint.setTextSize(kAboveThreshold_TextSize); |
| 55 | draw_text_stroked(canvas, paint); |
| 56 | } |
| 57 | |
| 58 | private: |
| 59 | typedef skiagm::GM INHERITED; |
| 60 | }; |
| 61 | |
| 62 | DEF_GM( return SkNEW(StrokeTextGM); ) |