epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
epoger@google.com | 213c42b | 2011-06-28 16:20:27 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
epoger@google.com | 213c42b | 2011-06-28 16:20:27 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
epoger@google.com | 213c42b | 2011-06-28 16:20:27 +0000 | [diff] [blame] | 10 | /* Tests text rendering with LCD and subpixel rendering turned on and off. |
| 11 | */ |
| 12 | |
| 13 | #include "gm.h" |
| 14 | #include "SkCanvas.h" |
| 15 | |
| 16 | namespace skiagm { |
| 17 | |
| 18 | class LcdTextGM : public GM { |
| 19 | public: |
| 20 | LcdTextGM() { |
| 21 | const int pointSize = 36; |
| 22 | textHeight = SkIntToScalar(pointSize); |
| 23 | } |
| 24 | |
| 25 | protected: |
| 26 | |
| 27 | SkString onShortName() { |
| 28 | return SkString("lcdtext"); |
| 29 | } |
| 30 | |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 31 | SkISize onISize() { return SkISize::Make(640, 480); } |
epoger@google.com | 213c42b | 2011-06-28 16:20:27 +0000 | [diff] [blame] | 32 | |
epoger@google.com | 213c42b | 2011-06-28 16:20:27 +0000 | [diff] [blame] | 33 | virtual void onDraw(SkCanvas* canvas) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 34 | |
epoger@google.com | 213c42b | 2011-06-28 16:20:27 +0000 | [diff] [blame] | 35 | y = textHeight; |
| 36 | drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"), |
| 37 | true, true); |
| 38 | drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderFalse"), |
| 39 | true, false); |
| 40 | drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderTrue"), |
| 41 | false, true); |
| 42 | drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"), |
| 43 | false, false); |
| 44 | } |
| 45 | |
| 46 | void drawText(SkCanvas* canvas, const SkString& string, |
| 47 | bool subpixelTextEnabled, bool lcdRenderTextEnabled) { |
| 48 | SkPaint paint; |
| 49 | paint.setColor(SK_ColorBLACK); |
| 50 | paint.setDither(true); |
| 51 | paint.setAntiAlias(true); |
| 52 | paint.setSubpixelText(subpixelTextEnabled); |
| 53 | paint.setLCDRenderText(lcdRenderTextEnabled); |
| 54 | paint.setTextSize(textHeight); |
| 55 | |
| 56 | canvas->drawText(string.c_str(), string.size(), 0, y, paint); |
| 57 | y += textHeight; |
| 58 | } |
| 59 | |
| 60 | private: |
| 61 | typedef GM INHERITED; |
| 62 | SkScalar y, textHeight; |
| 63 | }; |
| 64 | |
| 65 | /////////////////////////////////////////////////////////////////////////////// |
| 66 | |
| 67 | static GM* MyFactory(void*) { return new LcdTextGM; } |
| 68 | static GMRegistry reg(MyFactory); |
| 69 | |
| 70 | } |