Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: gm/lcdtext.cpp

Issue 617353003: fix prev change to tooBigForLCD, and add test (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkPaint.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 /* Tests text rendering with LCD and subpixel rendering turned on and off. 10 /* Tests text rendering with LCD and subpixel rendering turned on and off.
11 */ 11 */
12 12
13 #include "gm.h" 13 #include "gm.h"
14 #include "SkCanvas.h" 14 #include "SkCanvas.h"
15 15
16 namespace skiagm { 16 class LcdTextGM : public skiagm::GM {
17
18 class LcdTextGM : public GM {
19 public: 17 public:
20 LcdTextGM() { 18 LcdTextGM() {
21 const int pointSize = 36; 19 const int pointSize = 36;
22 textHeight = SkIntToScalar(pointSize); 20 textHeight = SkIntToScalar(pointSize);
23 } 21 }
24 22
25 protected: 23 protected:
26 24
27 SkString onShortName() { 25 SkString onShortName() {
28 return SkString("lcdtext"); 26 return SkString("lcdtext");
29 } 27 }
30 28
31 SkISize onISize() { return SkISize::Make(640, 480); } 29 SkISize onISize() { return SkISize::Make(640, 480); }
32 30
33 virtual void onDraw(SkCanvas* canvas) { 31 virtual void onDraw(SkCanvas* canvas) {
34 32
35 y = textHeight; 33 y = textHeight;
36 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"), 34 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"),
37 true, true); 35 true, true);
38 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderFalse"), 36 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderFalse"),
39 true, false); 37 true, false);
40 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderTrue"), 38 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderTrue"),
41 false, true); 39 false, true);
42 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"), 40 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"),
43 false, false); 41 false, false);
44 } 42 }
45 43
46 void drawText(SkCanvas* canvas, const SkString& string, 44 void drawText(SkCanvas* canvas, const SkString& string,
47 bool subpixelTextEnabled, bool lcdRenderTextEnabled) { 45 bool subpixelTextEnabled, bool lcdRenderTextEnabled) {
48 SkPaint paint; 46 SkPaint paint;
49 paint.setColor(SK_ColorBLACK); 47 paint.setColor(SK_ColorBLACK);
50 paint.setDither(true); 48 paint.setDither(true);
51 paint.setAntiAlias(true); 49 paint.setAntiAlias(true);
52 sk_tool_utils::set_portable_typeface(&paint); 50 sk_tool_utils::set_portable_typeface(&paint);
53 paint.setSubpixelText(subpixelTextEnabled); 51 paint.setSubpixelText(subpixelTextEnabled);
54 paint.setLCDRenderText(lcdRenderTextEnabled); 52 paint.setLCDRenderText(lcdRenderTextEnabled);
55 paint.setTextSize(textHeight); 53 paint.setTextSize(textHeight);
56 54
57 canvas->drawText(string.c_str(), string.size(), 0, y, paint); 55 canvas->drawText(string.c_str(), string.size(), 0, y, paint);
58 y += textHeight; 56 y += textHeight;
59 } 57 }
58
59 private:
60 typedef skiagm::GM INHERITED;
61 SkScalar y, textHeight;
62 };
63
64 /*
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)
67 *
68 * Test this both by changing "textsize" and by changing the computed size (tex tsize * CTM)
69 */
70 class LcdTextSizeGM : public skiagm::GM {
71 enum {
72 kLCDTextSizeLimit = 48
73 };
74
75 static void ScaleAbout(SkCanvas* canvas, SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) {
76 SkMatrix m;
77 m.setScale(sx, sy, px, py);
78 canvas->concat(m);
79 }
80
81 public:
82 LcdTextSizeGM() {}
83
84 protected:
85 SkString onShortName() {
86 return SkString("lcdtextsize");
87 }
88
89 SkISize onISize() { return SkISize::Make(320, 120); }
90
91 virtual void onDraw(SkCanvas* canvas) {
92 const char* lcd_text = "LCD";
93 const char* gray_text = "GRAY";
94
95 SkPaint paint;
96 paint.setAntiAlias(true);
97 paint.setLCDRenderText(true);
98
99 const struct {
100 SkPoint fLoc;
101 SkScalar fTextSize;
102 SkScalar fScale;
103 const char* fText;
104 } rec[] = {
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 },
109 };
110
111 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
112 const SkPoint loc = rec[i].fLoc;
113 SkAutoCanvasRestore acr(canvas, true);
114
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);
118 }
119 }
60 120
61 private: 121 private:
62 typedef GM INHERITED; 122 typedef skiagm::GM INHERITED;
63 SkScalar y, textHeight;
64 }; 123 };
65 124
66 /////////////////////////////////////////////////////////////////////////////// 125 ///////////////////////////////////////////////////////////////////////////////
67 126
68 static GM* MyFactory(void*) { return new LcdTextGM; } 127 DEF_GM( return new LcdTextGM; )
69 static GMRegistry reg(MyFactory); 128 DEF_GM( return new LcdTextSizeGM; )
70
71 }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPaint.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698