OLD | NEW |
(Empty) | |
| 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 }; |
| 20 SkShader* s = SkGradientShader::CreateSweep(0,0, colors, NULL, |
| 21 SK_ARRAY_COUNT(colors)); |
| 22 SkMatrix local; |
| 23 local.setRotate(180); |
| 24 s->setLocalMatrix(local); |
| 25 |
| 26 SkPaint paint; |
| 27 paint.setAntiAlias(true); |
| 28 paint.setShader(s)->unref(); |
| 29 |
| 30 SkAutoTUnref<SkTypeface> orig(SkTypeface::CreateFromName("Times", |
| 31 SkTypeface::kBold)); |
| 32 fColorType = SkNEW_ARGS(SkGTypeface, (orig, paint)); |
| 33 } |
| 34 |
| 35 virtual ~ColorTypeGM() { |
| 36 fColorType->unref(); |
| 37 } |
| 38 |
| 39 protected: |
| 40 virtual SkString onShortName() SK_OVERRIDE { |
| 41 return SkString("colortype"); |
| 42 } |
| 43 |
| 44 virtual SkISize onISize() SK_OVERRIDE { |
| 45 return SkISize::Make(640, 480); |
| 46 } |
| 47 |
| 48 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 49 SkPaint paint; |
| 50 paint.setAntiAlias(true); |
| 51 paint.setTypeface(fColorType); |
| 52 |
| 53 for (int size = 10; size <= 100; size += 10) { |
| 54 paint.setTextSize(size); |
| 55 canvas->translate(0, paint.getFontMetrics(NULL)); |
| 56 canvas->drawText("Hamburgefons", 12, 10, 10, paint); |
| 57 } |
| 58 } |
| 59 |
| 60 virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } |
| 61 |
| 62 private: |
| 63 SkTypeface* fColorType; |
| 64 |
| 65 typedef skiagm::GM INHERITED; |
| 66 }; |
| 67 |
| 68 DEF_GM( return SkNEW(ColorTypeGM); ) |
OLD | NEW |