blob: ec607e779133f2e6a7a53c33d806a3a487c0ebb2 [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"
Mike Klein33d20552017-03-22 13:47:51 -04008#include "sk_tool_utils.h"
bungeman@google.com0f0c2882011-11-04 15:47:41 +00009#include "SkTypeface.h"
10
11namespace skiagm {
12
bungeman@google.com0f0c2882011-11-04 15:47:41 +000013class FontScalerGM : public GM {
14public:
15 FontScalerGM() {
16 this->setBGColor(0xFFFFFFFF);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000017 }
18
bungeman@google.com0f0c2882011-11-04 15:47:41 +000019protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000020
mtklein36352bf2015-03-25 18:17:31 -070021 SkString onShortName() override {
caryclark37213552015-07-24 11:08:01 -070022 SkString name("fontscaler");
23 name.append(sk_tool_utils::major_platform_os_name());
24 return name;
bungeman@google.com0f0c2882011-11-04 15:47:41 +000025 }
26
mtklein36352bf2015-03-25 18:17:31 -070027 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070028 return SkISize::Make(1450, 750);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000029 }
30
mtklein36352bf2015-03-25 18:17:31 -070031 void onDraw(SkCanvas* canvas) override {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000032 SkPaint paint;
33
bungeman@google.com0f0c2882011-11-04 15:47:41 +000034 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);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000039
bungeman@google.com0f0c2882011-11-04 15:47:41 +000040 const char* text = "Hamburgefons ooo mmm";
41 const size_t textLen = strlen(text);
42
43 for (int j = 0; j < 2; ++j) {
bsalomon@google.com4121f952013-09-09 16:19:40 +000044 // 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) {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000046 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));
bungeman7438bfc2016-07-12 15:01:19 -070052 canvas->rotate(SkIntToScalar(i * 5), x, y * 10);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000053
54 {
55 SkPaint p;
56 p.setAntiAlias(true);
57 SkRect r;
bungeman@google.coma682b932012-01-05 18:10:48 +000058 r.set(x - SkIntToScalar(3), SkIntToScalar(15),
59 x - SkIntToScalar(1), SkIntToScalar(280));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000060 canvas->drawRect(r, p);
61 }
62
bungeman@google.com0f0c2882011-11-04 15:47:41 +000063 for (int ps = 6; ps <= 22; ps++) {
64 paint.setTextSize(SkIntToScalar(ps));
65 canvas->drawText(text, textLen, x, y, paint);
halcanary96fcdcc2015-08-27 07:41:13 -070066 y += paint.getFontMetrics(nullptr);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000067 }
68 }
bungeman@google.coma682b932012-01-05 18:10:48 +000069 canvas->translate(0, SkIntToScalar(360));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000070 paint.setSubpixelText(true);
71 }
72 }
73
74private:
bungeman@google.com0f0c2882011-11-04 15:47:41 +000075 typedef GM INHERITED;
76};
77
78//////////////////////////////////////////////////////////////////////////////
borenet@google.com0682ca62012-06-26 17:23:52 +000079
bungeman@google.com0f0c2882011-11-04 15:47:41 +000080static GM* MyFactory(void*) { return new FontScalerGM; }
81static GMRegistry reg(MyFactory);
borenet@google.com0682ca62012-06-26 17:23:52 +000082
bungeman@google.com0f0c2882011-11-04 15:47:41 +000083}