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