reed@google.com | 7edec14 | 2013-05-31 20:17:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | #include "SkGradientShader.h" |
| 11 | #include "../src/fonts/SkGScalerContext.h" |
| 12 | |
| 13 | class ColorTypeGM : public skiagm::GM { |
| 14 | public: |
| 15 | ColorTypeGM() { |
| 16 | const SkColor colors[] = { |
| 17 | SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, |
| 18 | SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW |
| 19 | }; |
reed@google.com | 7edec14 | 2013-05-31 20:17:57 +0000 | [diff] [blame] | 20 | SkMatrix local; |
| 21 | local.setRotate(180); |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 22 | SkShader* s = SkGradientShader::CreateSweep(0,0, colors, NULL, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 23 | SK_ARRAY_COUNT(colors), 0, &local); |
skia.committer@gmail.com | 26da7f0 | 2013-06-01 07:01:39 +0000 | [diff] [blame] | 24 | |
reed@google.com | 7edec14 | 2013-05-31 20:17:57 +0000 | [diff] [blame] | 25 | SkPaint paint; |
| 26 | paint.setAntiAlias(true); |
| 27 | paint.setShader(s)->unref(); |
skia.committer@gmail.com | 26da7f0 | 2013-06-01 07:01:39 +0000 | [diff] [blame] | 28 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 29 | SkTypeface* orig = sk_tool_utils::create_portable_typeface("Times", |
| 30 | SkTypeface::kBold); |
reed@google.com | 13e1540 | 2013-06-03 17:45:29 +0000 | [diff] [blame] | 31 | if (NULL == orig) { |
| 32 | orig = SkTypeface::RefDefault(); |
| 33 | } |
reed@google.com | 7edec14 | 2013-05-31 20:17:57 +0000 | [diff] [blame] | 34 | fColorType = SkNEW_ARGS(SkGTypeface, (orig, paint)); |
reed@google.com | 13e1540 | 2013-06-03 17:45:29 +0000 | [diff] [blame] | 35 | orig->unref(); |
reed@google.com | 7edec14 | 2013-05-31 20:17:57 +0000 | [diff] [blame] | 36 | } |
skia.committer@gmail.com | 26da7f0 | 2013-06-01 07:01:39 +0000 | [diff] [blame] | 37 | |
reed@google.com | 7edec14 | 2013-05-31 20:17:57 +0000 | [diff] [blame] | 38 | virtual ~ColorTypeGM() { |
| 39 | fColorType->unref(); |
| 40 | } |
| 41 | |
| 42 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 43 | SkString onShortName() override { |
reed@google.com | 7edec14 | 2013-05-31 20:17:57 +0000 | [diff] [blame] | 44 | return SkString("colortype"); |
| 45 | } |
| 46 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 47 | SkISize onISize() override { |
reed@google.com | 7edec14 | 2013-05-31 20:17:57 +0000 | [diff] [blame] | 48 | return SkISize::Make(640, 480); |
| 49 | } |
| 50 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 51 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | 7edec14 | 2013-05-31 20:17:57 +0000 | [diff] [blame] | 52 | SkPaint paint; |
| 53 | paint.setAntiAlias(true); |
| 54 | paint.setTypeface(fColorType); |
skia.committer@gmail.com | 26da7f0 | 2013-06-01 07:01:39 +0000 | [diff] [blame] | 55 | |
reed@google.com | e1613d8 | 2013-05-31 21:13:36 +0000 | [diff] [blame] | 56 | for (SkScalar size = 10; size <= 100; size += 10) { |
reed@google.com | 7edec14 | 2013-05-31 20:17:57 +0000 | [diff] [blame] | 57 | paint.setTextSize(size); |
| 58 | canvas->translate(0, paint.getFontMetrics(NULL)); |
| 59 | canvas->drawText("Hamburgefons", 12, 10, 10, paint); |
| 60 | } |
| 61 | } |
| 62 | |
reed@google.com | 7edec14 | 2013-05-31 20:17:57 +0000 | [diff] [blame] | 63 | private: |
| 64 | SkTypeface* fColorType; |
| 65 | |
| 66 | typedef skiagm::GM INHERITED; |
| 67 | }; |
| 68 | |
| 69 | DEF_GM( return SkNEW(ColorTypeGM); ) |