OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 /* Tests text rendering with LCD and subpixel rendering turned on and off. | 9 /* Tests text rendering with LCD and subpixel rendering turned on and off. |
10 */ | 10 */ |
11 | 11 |
12 #include "gm.h" | 12 #include "gm.h" |
13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
14 #include "SkPicture.h" | 14 #include "SkPicture.h" |
15 #include "SkPictureImageFilter.h" | 15 #include "SkPictureImageFilter.h" |
16 #include "SkPictureRecorder.h" | 16 #include "SkPictureRecorder.h" |
17 #include "SkSurface.h" | 17 #include "SkSurface.h" |
18 | 18 |
19 | 19 |
20 class LcdTextGM : public skiagm::GM { | 20 class LcdTextGM : public skiagm::GM { |
21 public: | 21 public: |
22 LcdTextGM() { | 22 LcdTextGM() { |
23 const int pointSize = 36; | 23 const int pointSize = 36; |
24 textHeight = SkIntToScalar(pointSize); | 24 textHeight = SkIntToScalar(pointSize); |
25 } | 25 } |
26 | 26 |
27 protected: | 27 protected: |
28 | 28 |
29 SkString onShortName() { | 29 SkString onShortName() { |
30 return SkString("lcdtext"); | 30 SkString name("lcdtext"); |
| 31 name.append(sk_tool_utils::major_platform_os_name()); |
| 32 return name; |
31 } | 33 } |
32 | 34 |
33 SkISize onISize() { return SkISize::Make(640, 480); } | 35 SkISize onISize() { return SkISize::Make(640, 480); } |
34 | 36 |
35 virtual void onDraw(SkCanvas* canvas) { | 37 virtual void onDraw(SkCanvas* canvas) { |
36 | 38 |
37 y = textHeight; | 39 y = textHeight; |
38 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"), | 40 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"), |
39 true, true); | 41 true, true); |
40 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderFalse"), | 42 drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderFalse"), |
41 true, false); | 43 true, false); |
42 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderTrue"), | 44 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderTrue"), |
43 false, true); | 45 false, true); |
44 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"), | 46 drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"), |
45 false, false); | 47 false, false); |
46 } | 48 } |
47 | 49 |
48 void drawText(SkCanvas* canvas, const SkString& string, | 50 void drawText(SkCanvas* canvas, const SkString& string, |
49 bool subpixelTextEnabled, bool lcdRenderTextEnabled) { | 51 bool subpixelTextEnabled, bool lcdRenderTextEnabled) { |
50 SkPaint paint; | 52 SkPaint paint; |
51 paint.setColor(SK_ColorBLACK); | 53 paint.setColor(SK_ColorBLACK); |
52 paint.setDither(true); | 54 paint.setDither(true); |
53 paint.setAntiAlias(true); | 55 paint.setAntiAlias(true); |
54 sk_tool_utils::set_portable_typeface(&paint); | |
55 paint.setSubpixelText(subpixelTextEnabled); | 56 paint.setSubpixelText(subpixelTextEnabled); |
56 paint.setLCDRenderText(lcdRenderTextEnabled); | 57 paint.setLCDRenderText(lcdRenderTextEnabled); |
57 paint.setTextSize(textHeight); | 58 paint.setTextSize(textHeight); |
58 | 59 |
59 canvas->drawText(string.c_str(), string.size(), 0, y, paint); | 60 canvas->drawText(string.c_str(), string.size(), 0, y, paint); |
60 y += textHeight; | 61 y += textHeight; |
61 } | 62 } |
62 | 63 |
63 private: | 64 private: |
64 typedef skiagm::GM INHERITED; | 65 typedef skiagm::GM INHERITED; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 canvas->drawText(rec[i].fText, strlen(rec[i].fText), loc.x(), loc.y(
), paint); | 122 canvas->drawText(rec[i].fText, strlen(rec[i].fText), loc.x(), loc.y(
), paint); |
122 } | 123 } |
123 } | 124 } |
124 | 125 |
125 private: | 126 private: |
126 typedef skiagm::GM INHERITED; | 127 typedef skiagm::GM INHERITED; |
127 }; | 128 }; |
128 | 129 |
129 DEF_GM( return new LcdTextGM; ) | 130 DEF_GM( return new LcdTextGM; ) |
130 DEF_GM( return new LcdTextSizeGM; ) | 131 DEF_GM( return new LcdTextSizeGM; ) |
OLD | NEW |