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