3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 /* Tests text rendering with LCD and subpixel rendering turned on and off.
16 class LcdTextGM : public skiagm::GM {
19 const int pointSize = 36;
20 textHeight = SkIntToScalar(pointSize);
25 SkString onShortName() {
26 return SkString("lcdtext");
29 SkISize onISize() { return SkISize::Make(640, 480); }
31 virtual void onDraw(SkCanvas* canvas) {
34 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"),
36 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderFalse"),
38 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderTrue"),
40 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"),
44 void drawText(SkCanvas* canvas, const SkString& string,
45 bool subpixelTextEnabled, bool lcdRenderTextEnabled) {
47 paint.setColor(SK_ColorBLACK);
48 paint.setDither(true);
49 paint.setAntiAlias(true);
50 sk_tool_utils::set_portable_typeface(&paint);
51 paint.setSubpixelText(subpixelTextEnabled);
52 paint.setLCDRenderText(lcdRenderTextEnabled);
53 paint.setTextSize(textHeight);
55 canvas->drawText(string.c_str(), string.size(), 0, y, paint);
60 typedef skiagm::GM INHERITED;
61 SkScalar y, textHeight;
65 * Skia will automatically disable LCD requests if the total size exceeds some limit
66 * (hard coded in this test for now, as it is now avaiable as an API)
68 * Test this both by changing "textsize" and by changing the computed size (textsize * CTM)
70 class LcdTextSizeGM : public skiagm::GM {
72 kLCDTextSizeLimit = 48
75 static void ScaleAbout(SkCanvas* canvas, SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) {
77 m.setScale(sx, sy, px, py);
85 SkString onShortName() {
86 return SkString("lcdtextsize");
89 SkISize onISize() { return SkISize::Make(320, 120); }
91 virtual void onDraw(SkCanvas* canvas) {
92 const char* lcd_text = "LCD";
93 const char* gray_text = "GRAY";
96 paint.setAntiAlias(true);
97 paint.setLCDRenderText(true);
105 { { 10, 50 }, kLCDTextSizeLimit - 1, 1, lcd_text },
106 { { 160, 50 }, kLCDTextSizeLimit + 1, 1, gray_text },
107 { { 10, 100 }, kLCDTextSizeLimit / 2, 1.99f, lcd_text },
108 { { 160, 100 }, kLCDTextSizeLimit / 2, 2.01f, gray_text },
111 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
112 const SkPoint loc = rec[i].fLoc;
113 SkAutoCanvasRestore acr(canvas, true);
115 paint.setTextSize(rec[i].fTextSize);
116 ScaleAbout(canvas, rec[i].fScale, rec[i].fScale, loc.x(), loc.y());
117 canvas->drawText(rec[i].fText, strlen(rec[i].fText), loc.x(), loc.y(), paint);
122 typedef skiagm::GM INHERITED;
125 ///////////////////////////////////////////////////////////////////////////////
127 DEF_GM( return new LcdTextGM; )
128 DEF_GM( return new LcdTextSizeGM; )