blob: 51d84251ebb184b66eb0409687f603984f7b4948 [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 */
Mike Reed2e6db182018-12-15 13:45:33 -05007#include <SkFont.h>
bungeman@google.com0f0c2882011-11-04 15:47:41 +00008#include "gm.h"
Mike Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
bungeman@google.com0f0c2882011-11-04 15:47:41 +000010#include "SkTypeface.h"
11
12namespace skiagm {
13
bungeman@google.com0f0c2882011-11-04 15:47:41 +000014class FontScalerGM : public GM {
15public:
16 FontScalerGM() {
17 this->setBGColor(0xFFFFFFFF);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000018 }
19
bungeman@google.com0f0c2882011-11-04 15:47:41 +000020protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000021
mtklein36352bf2015-03-25 18:17:31 -070022 SkString onShortName() override {
caryclark37213552015-07-24 11:08:01 -070023 SkString name("fontscaler");
Mike Kleinb251b722017-11-13 11:03:16 -050024 name.append(sk_tool_utils::platform_font_manager());
caryclark37213552015-07-24 11:08:01 -070025 return name;
bungeman@google.com0f0c2882011-11-04 15:47:41 +000026 }
27
mtklein36352bf2015-03-25 18:17:31 -070028 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070029 return SkISize::Make(1450, 750);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000030 }
31
mtklein36352bf2015-03-25 18:17:31 -070032 void onDraw(SkCanvas* canvas) override {
Mike Reed2e6db182018-12-15 13:45:33 -050033 SkFont font;
34 font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000035 //With freetype the default (normal hinting) can be really ugly.
36 //Most distros now set slight (vertical hinting only) in any event.
Mike Reed2e6db182018-12-15 13:45:33 -050037 font.setHinting(kSlight_SkFontHinting);
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++) {
Mike Reed2e6db182018-12-15 13:45:33 -050063 font.setSize(SkIntToScalar(ps));
64 canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, x, y, font, SkPaint());
65 y += font.getMetrics(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));
Mike Reed2e6db182018-12-15 13:45:33 -050069 font.setSubpixel(true);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000070 }
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
Hal Canarye964c182019-01-23 10:22:01 -050079DEF_GM( return new FontScalerGM; )
borenet@google.com0682ca62012-06-26 17:23:52 +000080
bungeman@google.com0f0c2882011-11-04 15:47:41 +000081}