Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / gm / colortype.cpp
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         SkMatrix local;
21         local.setRotate(180);
22         SkShader* s = SkGradientShader::CreateSweep(0,0, colors, NULL,
23                                                     SK_ARRAY_COUNT(colors), 0, &local);
24
25         SkPaint paint;
26         paint.setAntiAlias(true);
27         paint.setShader(s)->unref();
28
29         SkTypeface* orig = sk_tool_utils::create_portable_typeface("Times",
30                                                             SkTypeface::kBold);
31         if (NULL == orig) {
32             orig = SkTypeface::RefDefault();
33         }
34         fColorType = SkNEW_ARGS(SkGTypeface, (orig, paint));
35         orig->unref();
36     }
37
38     virtual ~ColorTypeGM() {
39         fColorType->unref();
40     }
41
42 protected:
43     virtual SkString onShortName() SK_OVERRIDE {
44         return SkString("colortype");
45     }
46
47     virtual SkISize onISize() SK_OVERRIDE {
48         return SkISize::Make(640, 480);
49     }
50
51     virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
52         SkPaint paint;
53         paint.setAntiAlias(true);
54         paint.setTypeface(fColorType);
55
56         for (SkScalar size = 10; size <= 100; size += 10) {
57             paint.setTextSize(size);
58             canvas->translate(0, paint.getFontMetrics(NULL));
59             canvas->drawText("Hamburgefons", 12, 10, 10, paint);
60         }
61     }
62
63     virtual uint32_t onGetFlags() const {
64         return kSkipPipe_Flag | kSkipPicture_Flag;
65     }
66
67 private:
68     SkTypeface* fColorType;
69
70     typedef skiagm::GM INHERITED;
71 };
72
73 DEF_GM( return SkNEW(ColorTypeGM); )