Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / gm / fontscaler.cpp
1 /*
2  * Copyright 2011 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/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkFont.h"
11 #include "include/core/SkFontTypes.h"
12 #include "include/core/SkPaint.h"
13 #include "include/core/SkRect.h"
14 #include "include/core/SkScalar.h"
15 #include "include/core/SkSize.h"
16 #include "include/core/SkString.h"
17
18 #include <string.h>
19
20 namespace skiagm {
21
22 class FontScalerGM : public GM {
23 public:
24     FontScalerGM() {
25         this->setBGColor(0xFFFFFFFF);
26     }
27
28 protected:
29
30     SkString onShortName() override {
31         return SkString("fontscaler");
32     }
33
34     SkISize onISize() override {
35         return SkISize::Make(1450, 750);
36     }
37
38     void onDraw(SkCanvas* canvas) override {
39         SkFont font;
40         font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
41         //With freetype the default (normal hinting) can be really ugly.
42         //Most distros now set slight (vertical hinting only) in any event.
43         font.setHinting(SkFontHinting::kSlight);
44
45         const char* text = "Hamburgefons ooo mmm";
46         const size_t textLen = strlen(text);
47
48         for (int j = 0; j < 2; ++j) {
49             // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config.
50             for (int i = 0; i < 5; ++i) {
51                 SkScalar x = 10;
52                 SkScalar y = 20;
53
54                 SkAutoCanvasRestore acr(canvas, true);
55                 canvas->translate(SkIntToScalar(50 + i * 230),
56                                   SkIntToScalar(20));
57                 canvas->rotate(SkIntToScalar(i * 5), x, y * 10);
58
59                 {
60                     SkPaint p;
61                     p.setAntiAlias(true);
62                     SkRect r;
63                     r.setLTRB(x - 3, 15, x - 1, 280);
64                     canvas->drawRect(r, p);
65                 }
66
67                 for (int ps = 6; ps <= 22; ps++) {
68                     font.setSize(SkIntToScalar(ps));
69                     canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, SkPaint());
70                     y += font.getMetrics(nullptr);
71                 }
72             }
73             canvas->translate(0, SkIntToScalar(360));
74             font.setSubpixel(true);
75             font.setLinearMetrics(true);
76             font.setBaselineSnap(false);
77         }
78     }
79
80 private:
81     using INHERITED = GM;
82 };
83
84 //////////////////////////////////////////////////////////////////////////////
85
86 DEF_GM( return new FontScalerGM; )
87
88 }  // namespace skiagm