blob: e0e895c50a42b1f7960e92c7a7261f684261df53 [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
31 SkISize onISize() { return make_isize(640, 480); }
32
33 void drawBG(SkCanvas* canvas) {
34 canvas->drawColor(SK_ColorWHITE);
35 }
36
37 virtual void onDraw(SkCanvas* canvas) {
38 this->drawBG(canvas);
39
40 y = textHeight;
41 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"),
42 true, true);
43 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderFalse"),
44 true, false);
45 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderTrue"),
46 false, true);
47 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"),
48 false, false);
49 }
50
51 void drawText(SkCanvas* canvas, const SkString& string,
52 bool subpixelTextEnabled, bool lcdRenderTextEnabled) {
53 SkPaint paint;
54 paint.setColor(SK_ColorBLACK);
55 paint.setDither(true);
56 paint.setAntiAlias(true);
57 paint.setSubpixelText(subpixelTextEnabled);
58 paint.setLCDRenderText(lcdRenderTextEnabled);
59 paint.setTextSize(textHeight);
60
61 canvas->drawText(string.c_str(), string.size(), 0, y, paint);
62 y += textHeight;
63 }
64
65private:
66 typedef GM INHERITED;
67 SkScalar y, textHeight;
68};
69
70///////////////////////////////////////////////////////////////////////////////
71
72static GM* MyFactory(void*) { return new LcdTextGM; }
73static GMRegistry reg(MyFactory);
74
75}