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" |
| 8 | #include "SkTypeface.h" |
| 9 | |
| 10 | namespace skiagm { |
| 11 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 12 | class FontScalerGM : public GM { |
| 13 | public: |
| 14 | FontScalerGM() { |
| 15 | this->setBGColor(0xFFFFFFFF); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 16 | } |
| 17 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 18 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 19 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 20 | SkString onShortName() override { |
caryclark | 3721355 | 2015-07-24 11:08:01 -0700 | [diff] [blame] | 21 | SkString name("fontscaler"); |
| 22 | name.append(sk_tool_utils::major_platform_os_name()); |
| 23 | return name; |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 24 | } |
| 25 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 26 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 27 | return SkISize::Make(1450, 750); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 28 | } |
| 29 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 30 | void onDraw(SkCanvas* canvas) override { |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 31 | SkPaint paint; |
| 32 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 33 | 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.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++) { |
| 63 | paint.setTextSize(SkIntToScalar(ps)); |
| 64 | canvas->drawText(text, textLen, x, y, paint); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 65 | y += paint.getFontMetrics(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)); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 69 | paint.setSubpixelText(true); |
| 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 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 79 | static GM* MyFactory(void*) { return new FontScalerGM; } |
| 80 | static GMRegistry reg(MyFactory); |
borenet@google.com | 0682ca6 | 2012-06-26 17:23:52 +0000 | [diff] [blame] | 81 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 82 | } |