• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "gm.h"
8 #include "SkTypeface.h"
9 
10 namespace skiagm {
11 
12 class FontScalerGM : public GM {
13 public:
FontScalerGM()14     FontScalerGM() {
15         this->setBGColor(0xFFFFFFFF);
16     }
17 
~FontScalerGM()18     virtual ~FontScalerGM() {
19     }
20 
21 protected:
onGetFlags() const22     virtual uint32_t onGetFlags() const SK_OVERRIDE {
23         return kSkipTiled_Flag;
24     }
25 
onShortName()26     virtual SkString onShortName() {
27         return SkString("fontscaler");
28     }
29 
onISize()30     virtual SkISize onISize() {
31         return SkISize::Make(1450, 750);
32     }
33 
rotate_about(SkCanvas * canvas,SkScalar degrees,SkScalar px,SkScalar py)34     static void rotate_about(SkCanvas* canvas,
35                              SkScalar degrees,
36                              SkScalar px, SkScalar py) {
37         canvas->translate(px, py);
38         canvas->rotate(degrees);
39         canvas->translate(-px, -py);
40     }
41 
onDraw(SkCanvas * canvas)42     virtual void onDraw(SkCanvas* canvas) {
43         SkPaint paint;
44 
45         paint.setAntiAlias(true);
46         paint.setLCDRenderText(true);
47         //With freetype the default (normal hinting) can be really ugly.
48         //Most distros now set slight (vertical hinting only) in any event.
49         paint.setHinting(SkPaint::kSlight_Hinting);
50         SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromName("Times Roman", SkTypeface::kNormal)));
51 
52         const char* text = "Hamburgefons ooo mmm";
53         const size_t textLen = strlen(text);
54 
55         for (int j = 0; j < 2; ++j) {
56             // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config.
57             for (int i = 0; i < 5; ++i) {
58                 SkScalar x = SkIntToScalar(10);
59                 SkScalar y = SkIntToScalar(20);
60 
61                 SkAutoCanvasRestore acr(canvas, true);
62                 canvas->translate(SkIntToScalar(50 + i * 230),
63                                   SkIntToScalar(20));
64                 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10);
65 
66                 {
67                     SkPaint p;
68                     p.setAntiAlias(true);
69                     SkRect r;
70                     r.set(x - SkIntToScalar(3), SkIntToScalar(15),
71                           x - SkIntToScalar(1), SkIntToScalar(280));
72                     canvas->drawRect(r, p);
73                 }
74 
75                 int index = 0;
76                 for (int ps = 6; ps <= 22; ps++) {
77                     paint.setTextSize(SkIntToScalar(ps));
78                     canvas->drawText(text, textLen, x, y, paint);
79                     y += paint.getFontMetrics(NULL);
80                     index += 1;
81                 }
82             }
83             canvas->translate(0, SkIntToScalar(360));
84             paint.setSubpixelText(true);
85         }
86     }
87 
88 private:
89     typedef GM INHERITED;
90 };
91 
92 //////////////////////////////////////////////////////////////////////////////
93 
MyFactory(void *)94 static GM* MyFactory(void*) { return new FontScalerGM; }
95 static GMRegistry reg(MyFactory);
96 
97 }
98