blob: 69cf346c4d2826d1c69825a4b3b5158f798f125b [file] [log] [blame]
bungeman@google.com0f0c2882011-11-04 15:47:41 +00001/*
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
10namespace skiagm {
11
bungeman@google.com0f0c2882011-11-04 15:47:41 +000012class FontScalerGM : public GM {
13public:
14 FontScalerGM() {
15 this->setBGColor(0xFFFFFFFF);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000016 }
17
18 virtual ~FontScalerGM() {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000019 }
20
21protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000022
mtklein36352bf2015-03-25 18:17:31 -070023 SkString onShortName() override {
caryclark37213552015-07-24 11:08:01 -070024 SkString name("fontscaler");
25 name.append(sk_tool_utils::major_platform_os_name());
26 return name;
bungeman@google.com0f0c2882011-11-04 15:47:41 +000027 }
28
mtklein36352bf2015-03-25 18:17:31 -070029 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070030 return SkISize::Make(1450, 750);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000031 }
32
bungeman@google.coma682b932012-01-05 18:10:48 +000033 static void rotate_about(SkCanvas* canvas,
34 SkScalar degrees,
35 SkScalar px, SkScalar py) {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000036 canvas->translate(px, py);
37 canvas->rotate(degrees);
38 canvas->translate(-px, -py);
39 }
40
mtklein36352bf2015-03-25 18:17:31 -070041 void onDraw(SkCanvas* canvas) override {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000042 SkPaint paint;
43
bungeman@google.com0f0c2882011-11-04 15:47:41 +000044 paint.setAntiAlias(true);
45 paint.setLCDRenderText(true);
46 //With freetype the default (normal hinting) can be really ugly.
47 //Most distros now set slight (vertical hinting only) in any event.
48 paint.setHinting(SkPaint::kSlight_Hinting);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000049
bungeman@google.com0f0c2882011-11-04 15:47:41 +000050 const char* text = "Hamburgefons ooo mmm";
51 const size_t textLen = strlen(text);
52
53 for (int j = 0; j < 2; ++j) {
bsalomon@google.com4121f952013-09-09 16:19:40 +000054 // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config.
55 for (int i = 0; i < 5; ++i) {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000056 SkScalar x = SkIntToScalar(10);
57 SkScalar y = SkIntToScalar(20);
58
59 SkAutoCanvasRestore acr(canvas, true);
60 canvas->translate(SkIntToScalar(50 + i * 230),
61 SkIntToScalar(20));
62 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10);
63
64 {
65 SkPaint p;
66 p.setAntiAlias(true);
67 SkRect r;
bungeman@google.coma682b932012-01-05 18:10:48 +000068 r.set(x - SkIntToScalar(3), SkIntToScalar(15),
69 x - SkIntToScalar(1), SkIntToScalar(280));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000070 canvas->drawRect(r, p);
71 }
72
bungeman@google.com0f0c2882011-11-04 15:47:41 +000073 for (int ps = 6; ps <= 22; ps++) {
74 paint.setTextSize(SkIntToScalar(ps));
75 canvas->drawText(text, textLen, x, y, paint);
halcanary96fcdcc2015-08-27 07:41:13 -070076 y += paint.getFontMetrics(nullptr);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000077 }
78 }
bungeman@google.coma682b932012-01-05 18:10:48 +000079 canvas->translate(0, SkIntToScalar(360));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000080 paint.setSubpixelText(true);
81 }
82 }
83
84private:
bungeman@google.com0f0c2882011-11-04 15:47:41 +000085 typedef GM INHERITED;
86};
87
88//////////////////////////////////////////////////////////////////////////////
borenet@google.com0682ca62012-06-26 17:23:52 +000089
bungeman@google.com0f0c2882011-11-04 15:47:41 +000090static GM* MyFactory(void*) { return new FontScalerGM; }
91static GMRegistry reg(MyFactory);
borenet@google.com0682ca62012-06-26 17:23:52 +000092
bungeman@google.com0f0c2882011-11-04 15:47:41 +000093}