blob: cc9815c9d917be75008248c1e11e4090b09522ab [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
bungeman@google.com0f0c2882011-11-04 15:47:41 +000018protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000019
mtklein36352bf2015-03-25 18:17:31 -070020 SkString onShortName() override {
caryclark37213552015-07-24 11:08:01 -070021 SkString name("fontscaler");
22 name.append(sk_tool_utils::major_platform_os_name());
23 return name;
bungeman@google.com0f0c2882011-11-04 15:47:41 +000024 }
25
mtklein36352bf2015-03-25 18:17:31 -070026 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070027 return SkISize::Make(1450, 750);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000028 }
29
mtklein36352bf2015-03-25 18:17:31 -070030 void onDraw(SkCanvas* canvas) override {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000031 SkPaint paint;
32
bungeman@google.com0f0c2882011-11-04 15:47:41 +000033 paint.setAntiAlias(true);
34 paint.setLCDRenderText(true);
35 //With freetype the default (normal hinting) can be really ugly.
36 //Most distros now set slight (vertical hinting only) in any event.
37 paint.setHinting(SkPaint::kSlight_Hinting);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000038
bungeman@google.com0f0c2882011-11-04 15:47:41 +000039 const char* text = "Hamburgefons ooo mmm";
40 const size_t textLen = strlen(text);
41
42 for (int j = 0; j < 2; ++j) {
bsalomon@google.com4121f952013-09-09 16:19:40 +000043 // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config.
44 for (int i = 0; i < 5; ++i) {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000045 SkScalar x = SkIntToScalar(10);
46 SkScalar y = SkIntToScalar(20);
47
48 SkAutoCanvasRestore acr(canvas, true);
49 canvas->translate(SkIntToScalar(50 + i * 230),
50 SkIntToScalar(20));
bungeman7438bfc2016-07-12 15:01:19 -070051 canvas->rotate(SkIntToScalar(i * 5), x, y * 10);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000052
53 {
54 SkPaint p;
55 p.setAntiAlias(true);
56 SkRect r;
bungeman@google.coma682b932012-01-05 18:10:48 +000057 r.set(x - SkIntToScalar(3), SkIntToScalar(15),
58 x - SkIntToScalar(1), SkIntToScalar(280));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000059 canvas->drawRect(r, p);
60 }
61
bungeman@google.com0f0c2882011-11-04 15:47:41 +000062 for (int ps = 6; ps <= 22; ps++) {
63 paint.setTextSize(SkIntToScalar(ps));
64 canvas->drawText(text, textLen, x, y, paint);
halcanary96fcdcc2015-08-27 07:41:13 -070065 y += paint.getFontMetrics(nullptr);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000066 }
67 }
bungeman@google.coma682b932012-01-05 18:10:48 +000068 canvas->translate(0, SkIntToScalar(360));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000069 paint.setSubpixelText(true);
70 }
71 }
72
73private:
bungeman@google.com0f0c2882011-11-04 15:47:41 +000074 typedef GM INHERITED;
75};
76
77//////////////////////////////////////////////////////////////////////////////
borenet@google.com0682ca62012-06-26 17:23:52 +000078
bungeman@google.com0f0c2882011-11-04 15:47:41 +000079static GM* MyFactory(void*) { return new FontScalerGM; }
80static GMRegistry reg(MyFactory);
borenet@google.com0682ca62012-06-26 17:23:52 +000081
bungeman@google.com0f0c2882011-11-04 15:47:41 +000082}