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 | |
reed@google.com | 0d30c51 | 2014-03-14 14:02:58 +0000 | [diff] [blame^] | 11 | static void test_nulldev(SkCanvas* canvas) { |
| 12 | SkBitmap bm; |
| 13 | bm.setConfig(SkBitmap::kARGB_8888_Config, 30, 30); |
| 14 | // notice: no pixels mom! be sure we don't crash |
| 15 | // https://code.google.com/p/chromium/issues/detail?id=352616 |
| 16 | SkCanvas c(bm); |
| 17 | |
| 18 | SkBitmap src; |
| 19 | src.allocN32Pixels(10, 10); |
| 20 | src.eraseColor(SK_ColorRED); |
| 21 | |
| 22 | // ensure we don't crash |
| 23 | c.writePixels(src, 0, 0); |
| 24 | } |
| 25 | |
commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 26 | static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint) { |
| 27 | SkPaint p(paint); |
| 28 | SkPoint loc = { 20, 450 }; |
skia.committer@gmail.com | affa77d | 2014-03-13 03:02:23 +0000 | [diff] [blame] | 29 | |
commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 30 | canvas->drawText("P", 1, loc.fX, loc.fY - 225, p); |
| 31 | canvas->drawPosText("P", 1, &loc, p); |
skia.committer@gmail.com | affa77d | 2014-03-13 03:02:23 +0000 | [diff] [blame] | 32 | |
commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 33 | p.setColor(SK_ColorRED); |
| 34 | p.setStyle(SkPaint::kStroke_Style); |
| 35 | p.setStrokeWidth(10); |
skia.committer@gmail.com | affa77d | 2014-03-13 03:02:23 +0000 | [diff] [blame] | 36 | |
commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 37 | canvas->drawText("P", 1, loc.fX, loc.fY - 225, p); |
| 38 | canvas->drawPosText("P", 1, &loc, p); |
| 39 | } |
| 40 | |
| 41 | class StrokeTextGM : public skiagm::GM { |
| 42 | // Skia has a threshold above which it draws text via paths instead of using scalercontext |
| 43 | // and caching the glyph. This GM wants to ensure that we draw stroking correctly on both |
| 44 | // sides of this threshold. |
| 45 | enum { |
| 46 | kBelowThreshold_TextSize = 255, |
| 47 | kAboveThreshold_TextSize = 257 |
| 48 | }; |
| 49 | public: |
| 50 | StrokeTextGM() {} |
| 51 | |
| 52 | protected: |
| 53 | virtual SkString onShortName() SK_OVERRIDE { |
| 54 | return SkString("stroketext"); |
| 55 | } |
| 56 | |
| 57 | virtual SkISize onISize() SK_OVERRIDE { |
| 58 | return SkISize::Make(640, 480); |
| 59 | } |
| 60 | |
| 61 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
reed@google.com | 0d30c51 | 2014-03-14 14:02:58 +0000 | [diff] [blame^] | 62 | if (true) { test_nulldev(canvas); } |
commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 63 | SkPaint paint; |
| 64 | paint.setAntiAlias(true); |
skia.committer@gmail.com | affa77d | 2014-03-13 03:02:23 +0000 | [diff] [blame] | 65 | |
commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 66 | paint.setTextSize(kBelowThreshold_TextSize); |
| 67 | draw_text_stroked(canvas, paint); |
skia.committer@gmail.com | affa77d | 2014-03-13 03:02:23 +0000 | [diff] [blame] | 68 | |
commit-bot@chromium.org | 641e33b | 2014-03-12 20:31:24 +0000 | [diff] [blame] | 69 | canvas->translate(200, 0); |
| 70 | paint.setTextSize(kAboveThreshold_TextSize); |
| 71 | draw_text_stroked(canvas, paint); |
| 72 | } |
| 73 | |
| 74 | private: |
| 75 | typedef skiagm::GM INHERITED; |
| 76 | }; |
| 77 | |
| 78 | DEF_GM( return SkNEW(StrokeTextGM); ) |