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 | */ |
| 7 | #include "gm.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 8 | #include "sk_tool_utils.h" |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 9 | #include "SkTypeface.h" |
| 10 | |
| 11 | namespace skiagm { |
| 12 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 13 | class FontScalerGM : public GM { |
| 14 | public: |
| 15 | FontScalerGM() { |
| 16 | this->setBGColor(0xFFFFFFFF); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 17 | } |
| 18 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 19 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 20 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 21 | SkString onShortName() override { |
caryclark | 3721355 | 2015-07-24 11:08:01 -0700 | [diff] [blame] | 22 | SkString name("fontscaler"); |
| 23 | name.append(sk_tool_utils::major_platform_os_name()); |
| 24 | return name; |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 25 | } |
| 26 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 27 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 28 | return SkISize::Make(1450, 750); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 29 | } |
| 30 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 31 | void onDraw(SkCanvas* canvas) override { |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 32 | SkPaint paint; |
| 33 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 34 | 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.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 39 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 40 | const char* text = "Hamburgefons ooo mmm"; |
| 41 | const size_t textLen = strlen(text); |
| 42 | |
| 43 | for (int j = 0; j < 2; ++j) { |
bsalomon@google.com | 4121f95 | 2013-09-09 16:19:40 +0000 | [diff] [blame] | 44 | // 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.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 46 | 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)); |
bungeman | 7438bfc | 2016-07-12 15:01:19 -0700 | [diff] [blame] | 52 | canvas->rotate(SkIntToScalar(i * 5), x, y * 10); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 53 | |
| 54 | { |
| 55 | SkPaint p; |
| 56 | p.setAntiAlias(true); |
| 57 | SkRect r; |
bungeman@google.com | a682b93 | 2012-01-05 18:10:48 +0000 | [diff] [blame] | 58 | r.set(x - SkIntToScalar(3), SkIntToScalar(15), |
| 59 | x - SkIntToScalar(1), SkIntToScalar(280)); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 60 | canvas->drawRect(r, p); |
| 61 | } |
| 62 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 63 | for (int ps = 6; ps <= 22; ps++) { |
| 64 | paint.setTextSize(SkIntToScalar(ps)); |
| 65 | canvas->drawText(text, textLen, x, y, paint); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 66 | y += paint.getFontMetrics(nullptr); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 67 | } |
| 68 | } |
bungeman@google.com | a682b93 | 2012-01-05 18:10:48 +0000 | [diff] [blame] | 69 | canvas->translate(0, SkIntToScalar(360)); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 70 | paint.setSubpixelText(true); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | private: |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 75 | typedef GM INHERITED; |
| 76 | }; |
| 77 | |
| 78 | ////////////////////////////////////////////////////////////////////////////// |
borenet@google.com | 0682ca6 | 2012-06-26 17:23:52 +0000 | [diff] [blame] | 79 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 80 | static GM* MyFactory(void*) { return new FontScalerGM; } |
| 81 | static GMRegistry reg(MyFactory); |
borenet@google.com | 0682ca6 | 2012-06-26 17:23:52 +0000 | [diff] [blame] | 82 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 83 | } |