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 : fColorType(nullptr) { 17 } 18 19 virtual ~ColorTypeGM() { 20 SkSafeUnref(fColorType); 21 } 22 23 protected: 24 void onOnceBeforeDraw() override { 25 const SkColor colors[] = { 26 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, 27 SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW 28 }; 29 SkMatrix local; 30 local.setRotate(180); 31 SkShader* s = SkGradientShader::CreateSweep(0,0, colors, nullptr, 32 SK_ARRAY_COUNT(colors), 0, &local); 33 34 SkPaint paint; 35 paint.setAntiAlias(true); 36 paint.setShader(s)->unref(); 37 38 SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", 39 SkTypeface::kBold); 40 if (nullptr == orig) { 41 orig = SkTypeface::RefDefault(); 42 } 43 fColorType = new SkGTypeface(orig, paint); 44 orig->unref(); 45 } 46 47 SkString onShortName() override { 48 return SkString("colortype"); 49 } 50 51 SkISize onISize() override { 52 return SkISize::Make(640, 480); 53 } 54 55 void onDraw(SkCanvas* canvas) override { 56 SkPaint paint; 57 paint.setAntiAlias(true); 58 paint.setTypeface(fColorType); 59 60 for (SkScalar size = 10; size <= 100; size += 10) { 61 paint.setTextSize(size); 62 canvas->translate(0, paint.getFontMetrics(nullptr)); 63 canvas->drawText("Hamburgefons", 12, 10, 10, paint); 64 } 65 } 66 67 private: 68 SkTypeface* fColorType; 69 70 typedef skiagm::GM INHERITED; 71 }; 72 73 DEF_GM(return new ColorTypeGM;) 74