blob: b4db0ff12af378bbdc00f0f1030cfa4394702d79 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
epoger@google.com213c42b2011-06-28 16:20:27 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.com213c42b2011-06-28 16:20:27 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
epoger@google.com213c42b2011-06-28 16:20:27 +000010/* Tests text rendering with LCD and subpixel rendering turned on and off.
11 */
12
13#include "gm.h"
14#include "SkCanvas.h"
15
16namespace skiagm {
17
18class LcdTextGM : public GM {
19public:
20 LcdTextGM() {
21 const int pointSize = 36;
22 textHeight = SkIntToScalar(pointSize);
23 }
24
25protected:
26
27 SkString onShortName() {
28 return SkString("lcdtext");
29 }
30
tfarinaf5393182014-06-09 23:59:03 -070031 SkISize onISize() { return SkISize::Make(640, 480); }
epoger@google.com213c42b2011-06-28 16:20:27 +000032
epoger@google.com213c42b2011-06-28 16:20:27 +000033 virtual void onDraw(SkCanvas* canvas) {
rmistry@google.comd6176b02012-08-23 18:14:13 +000034
epoger@google.com213c42b2011-06-28 16:20:27 +000035 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);
Cary Clark992c7b02014-07-31 08:58:44 -040052 sk_tool_utils::set_portable_typeface(&paint);
epoger@google.com213c42b2011-06-28 16:20:27 +000053 paint.setSubpixelText(subpixelTextEnabled);
54 paint.setLCDRenderText(lcdRenderTextEnabled);
55 paint.setTextSize(textHeight);
56
57 canvas->drawText(string.c_str(), string.size(), 0, y, paint);
58 y += textHeight;
59 }
60
61private:
62 typedef GM INHERITED;
63 SkScalar y, textHeight;
64};
65
66///////////////////////////////////////////////////////////////////////////////
67
68static GM* MyFactory(void*) { return new LcdTextGM; }
69static GMRegistry reg(MyFactory);
70
71}