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 | |
| 18 | virtual ~FontScalerGM() { |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 22 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 23 | SkString onShortName() override { |
caryclark | 3721355 | 2015-07-24 11:08:01 -0700 | [diff] [blame] | 24 | SkString name("fontscaler"); |
| 25 | name.append(sk_tool_utils::major_platform_os_name()); |
| 26 | return name; |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 27 | } |
| 28 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 29 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 30 | return SkISize::Make(1450, 750); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 31 | } |
| 32 | |
bungeman@google.com | a682b93 | 2012-01-05 18:10:48 +0000 | [diff] [blame] | 33 | static void rotate_about(SkCanvas* canvas, |
| 34 | SkScalar degrees, |
| 35 | SkScalar px, SkScalar py) { |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 36 | canvas->translate(px, py); |
| 37 | canvas->rotate(degrees); |
| 38 | canvas->translate(-px, -py); |
| 39 | } |
| 40 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 41 | void onDraw(SkCanvas* canvas) override { |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 42 | SkPaint paint; |
| 43 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 44 | paint.setAntiAlias(true); |
| 45 | paint.setLCDRenderText(true); |
| 46 | //With freetype the default (normal hinting) can be really ugly. |
| 47 | //Most distros now set slight (vertical hinting only) in any event. |
| 48 | paint.setHinting(SkPaint::kSlight_Hinting); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 49 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 50 | const char* text = "Hamburgefons ooo mmm"; |
| 51 | const size_t textLen = strlen(text); |
| 52 | |
| 53 | for (int j = 0; j < 2; ++j) { |
bsalomon@google.com | 4121f95 | 2013-09-09 16:19:40 +0000 | [diff] [blame] | 54 | // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config. |
| 55 | for (int i = 0; i < 5; ++i) { |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 56 | SkScalar x = SkIntToScalar(10); |
| 57 | SkScalar y = SkIntToScalar(20); |
| 58 | |
| 59 | SkAutoCanvasRestore acr(canvas, true); |
| 60 | canvas->translate(SkIntToScalar(50 + i * 230), |
| 61 | SkIntToScalar(20)); |
| 62 | rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10); |
| 63 | |
| 64 | { |
| 65 | SkPaint p; |
| 66 | p.setAntiAlias(true); |
| 67 | SkRect r; |
bungeman@google.com | a682b93 | 2012-01-05 18:10:48 +0000 | [diff] [blame] | 68 | r.set(x - SkIntToScalar(3), SkIntToScalar(15), |
| 69 | x - SkIntToScalar(1), SkIntToScalar(280)); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 70 | canvas->drawRect(r, p); |
| 71 | } |
| 72 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 73 | for (int ps = 6; ps <= 22; ps++) { |
| 74 | paint.setTextSize(SkIntToScalar(ps)); |
| 75 | canvas->drawText(text, textLen, x, y, paint); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 76 | y += paint.getFontMetrics(nullptr); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
bungeman@google.com | a682b93 | 2012-01-05 18:10:48 +0000 | [diff] [blame] | 79 | canvas->translate(0, SkIntToScalar(360)); |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 80 | paint.setSubpixelText(true); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | private: |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 85 | typedef GM INHERITED; |
| 86 | }; |
| 87 | |
| 88 | ////////////////////////////////////////////////////////////////////////////// |
borenet@google.com | 0682ca6 | 2012-06-26 17:23:52 +0000 | [diff] [blame] | 89 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 90 | static GM* MyFactory(void*) { return new FontScalerGM; } |
| 91 | static GMRegistry reg(MyFactory); |
borenet@google.com | 0682ca6 | 2012-06-26 17:23:52 +0000 | [diff] [blame] | 92 | |
bungeman@google.com | 0f0c288 | 2011-11-04 15:47:41 +0000 | [diff] [blame] | 93 | } |