bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 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 | */ |
Mike Reed | 2e6db18 | 2018-12-15 13:45:33 -0500 | [diff] [blame] | 7 | #include <SkFont.h> |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 8 | #include "gm.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 10 | #include "SkTypeface.h" |
| 11 | |
| 12 | namespace skiagm { |
| 13 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 14 | class FontScalerGM : public GM { |
| 15 | public: |
| 16 | FontScalerGM() { |
| 17 | this->setBGColor(0xFFFFFFFF); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 18 | } |
| 19 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 20 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 21 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 22 | SkString onShortName() override { |
caryclark | 3721355 | 2015-07-24 11:08:01 -0700 | [diff] [blame] | 23 | SkString name("fontscaler"); |
Mike Klein | b251b72 | 2017-11-13 11:03:16 -0500 | [diff] [blame] | 24 | name.append(sk_tool_utils::platform_font_manager()); |
caryclark | 3721355 | 2015-07-24 11:08:01 -0700 | [diff] [blame] | 25 | return name; |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 26 | } |
| 27 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 28 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 29 | return SkISize::Make(1450, 750); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 30 | } |
| 31 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 32 | void onDraw(SkCanvas* canvas) override { |
Mike Reed | 2e6db18 | 2018-12-15 13:45:33 -0500 | [diff] [blame] | 33 | SkFont font; |
| 34 | font.setEdging(SkFont::Edging::kSubpixelAntiAlias); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 35 | //With freetype the default (normal hinting) can be really ugly. |
| 36 | //Most distros now set slight (vertical hinting only) in any event. |
Mike Reed | 2e6db18 | 2018-12-15 13:45:33 -0500 | [diff] [blame] | 37 | font.setHinting(kSlight_SkFontHinting); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 38 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 39 | const char* text = "Hamburgefons ooo mmm"; |
| 40 | const size_t textLen = strlen(text); |
| 41 | |
| 42 | for (int j = 0; j < 2; ++j) { |
bsalomon@google.com | 4121f95 | 2013-09-09 16:19:40 +0000 | [diff] [blame] | 43 | // 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.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 45 | 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)); |
bungeman | 7438bfc | 2016-07-12 15:01:19 -0700 | [diff] [blame] | 51 | canvas->rotate(SkIntToScalar(i * 5), x, y * 10); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 52 | |
| 53 | { |
| 54 | SkPaint p; |
| 55 | p.setAntiAlias(true); |
| 56 | SkRect r; |
bungeman@google.com | a682b93 | 2012-01-05 18:10:48 +0000 | [diff] [blame] | 57 | r.set(x - SkIntToScalar(3), SkIntToScalar(15), |
| 58 | x - SkIntToScalar(1), SkIntToScalar(280)); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 59 | canvas->drawRect(r, p); |
| 60 | } |
| 61 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 62 | for (int ps = 6; ps <= 22; ps++) { |
Mike Reed | 2e6db18 | 2018-12-15 13:45:33 -0500 | [diff] [blame] | 63 | font.setSize(SkIntToScalar(ps)); |
| 64 | canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, x, y, font, SkPaint()); |
| 65 | y += font.getMetrics(nullptr); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 66 | } |
| 67 | } |
bungeman@google.com | a682b93 | 2012-01-05 18:10:48 +0000 | [diff] [blame] | 68 | canvas->translate(0, SkIntToScalar(360)); |
Mike Reed | 2e6db18 | 2018-12-15 13:45:33 -0500 | [diff] [blame] | 69 | font.setSubpixel(true); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | private: |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 74 | typedef GM INHERITED; |
| 75 | }; |
| 76 | |
| 77 | ////////////////////////////////////////////////////////////////////////////// |
borenet@google.com | 0682ca6 | 2012-06-26 17:23:52 +0000 | [diff] [blame] | 78 | |
Hal Canary | e964c18 | 2019-01-23 10:22:01 -0500 | [diff] [blame] | 79 | DEF_GM( return new FontScalerGM; ) |
borenet@google.com | 0682ca6 | 2012-06-26 17:23:52 +0000 | [diff] [blame] | 80 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 81 | } |