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 | */ |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkFont.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 11 | #include "include/core/SkFontTypes.h" |
| 12 | #include "include/core/SkPaint.h" |
| 13 | #include "include/core/SkRect.h" |
| 14 | #include "include/core/SkScalar.h" |
| 15 | #include "include/core/SkSize.h" |
| 16 | #include "include/core/SkString.h" |
| 17 | |
| 18 | #include <string.h> |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 19 | |
| 20 | namespace skiagm { |
| 21 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 22 | class FontScalerGM : public GM { |
| 23 | public: |
| 24 | FontScalerGM() { |
| 25 | this->setBGColor(0xFFFFFFFF); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 26 | } |
| 27 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 28 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 29 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 30 | SkString onShortName() override { |
Mike Klein | bea1f94 | 2019-03-08 11:11:55 -0600 | [diff] [blame] | 31 | return SkString("fontscaler"); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 32 | } |
| 33 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 34 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 35 | return SkISize::Make(1450, 750); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 36 | } |
| 37 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 38 | void onDraw(SkCanvas* canvas) override { |
Mike Reed | 2e6db18 | 2018-12-15 13:45:33 -0500 | [diff] [blame] | 39 | SkFont font; |
| 40 | font.setEdging(SkFont::Edging::kSubpixelAntiAlias); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 41 | //With freetype the default (normal hinting) can be really ugly. |
| 42 | //Most distros now set slight (vertical hinting only) in any event. |
Ben Wagner | 5785e4a | 2019-05-07 16:50:29 -0400 | [diff] [blame] | 43 | font.setHinting(SkFontHinting::kSlight); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 44 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 45 | const char* text = "Hamburgefons ooo mmm"; |
| 46 | const size_t textLen = strlen(text); |
| 47 | |
| 48 | for (int j = 0; j < 2; ++j) { |
bsalomon@google.com | 4121f95 | 2013-09-09 16:19:40 +0000 | [diff] [blame] | 49 | // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config. |
| 50 | for (int i = 0; i < 5; ++i) { |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 51 | SkScalar x = 10; |
| 52 | SkScalar y = 20; |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 53 | |
| 54 | SkAutoCanvasRestore acr(canvas, true); |
| 55 | canvas->translate(SkIntToScalar(50 + i * 230), |
| 56 | SkIntToScalar(20)); |
bungeman | 7438bfc | 2016-07-12 15:01:19 -0700 | [diff] [blame] | 57 | canvas->rotate(SkIntToScalar(i * 5), x, y * 10); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 58 | |
| 59 | { |
| 60 | SkPaint p; |
| 61 | p.setAntiAlias(true); |
| 62 | SkRect r; |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 63 | r.setLTRB(x - 3, 15, x - 1, 280); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 64 | canvas->drawRect(r, p); |
| 65 | } |
| 66 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 67 | for (int ps = 6; ps <= 22; ps++) { |
Mike Reed | 2e6db18 | 2018-12-15 13:45:33 -0500 | [diff] [blame] | 68 | font.setSize(SkIntToScalar(ps)); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 69 | canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, SkPaint()); |
Mike Reed | 2e6db18 | 2018-12-15 13:45:33 -0500 | [diff] [blame] | 70 | y += font.getMetrics(nullptr); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 71 | } |
| 72 | } |
bungeman@google.com | a682b93 | 2012-01-05 18:10:48 +0000 | [diff] [blame] | 73 | canvas->translate(0, SkIntToScalar(360)); |
Mike Reed | 2e6db18 | 2018-12-15 13:45:33 -0500 | [diff] [blame] | 74 | font.setSubpixel(true); |
Ben Wagner | f460eee | 2019-04-18 16:37:45 -0400 | [diff] [blame] | 75 | font.setLinearMetrics(true); |
Ben Wagner | 54aa884 | 2019-08-27 16:20:39 -0400 | [diff] [blame] | 76 | font.setBaselineSnap(false); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
| 80 | private: |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 81 | typedef GM INHERITED; |
| 82 | }; |
| 83 | |
| 84 | ////////////////////////////////////////////////////////////////////////////// |
borenet@google.com | 0682ca6 | 2012-06-26 17:23:52 +0000 | [diff] [blame] | 85 | |
Hal Canary | e964c18 | 2019-01-23 10:22:01 -0500 | [diff] [blame] | 86 | DEF_GM( return new FontScalerGM; ) |
borenet@google.com | 0682ca6 | 2012-06-26 17:23:52 +0000 | [diff] [blame] | 87 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 88 | } |