epoger@google.com | 213c42b | 2011-06-28 16:20:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2011 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* Tests text rendering with LCD and subpixel rendering turned on and off. |
| 18 | */ |
| 19 | |
| 20 | #include "gm.h" |
| 21 | #include "SkCanvas.h" |
| 22 | |
| 23 | namespace skiagm { |
| 24 | |
| 25 | class LcdTextGM : public GM { |
| 26 | public: |
| 27 | LcdTextGM() { |
| 28 | const int pointSize = 36; |
| 29 | textHeight = SkIntToScalar(pointSize); |
| 30 | } |
| 31 | |
| 32 | protected: |
| 33 | |
| 34 | SkString onShortName() { |
| 35 | return SkString("lcdtext"); |
| 36 | } |
| 37 | |
| 38 | SkISize onISize() { return make_isize(640, 480); } |
| 39 | |
| 40 | void drawBG(SkCanvas* canvas) { |
| 41 | canvas->drawColor(SK_ColorWHITE); |
| 42 | } |
| 43 | |
| 44 | virtual void onDraw(SkCanvas* canvas) { |
| 45 | this->drawBG(canvas); |
| 46 | |
| 47 | y = textHeight; |
| 48 | drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"), |
| 49 | true, true); |
| 50 | drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderFalse"), |
| 51 | true, false); |
| 52 | drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderTrue"), |
| 53 | false, true); |
| 54 | drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"), |
| 55 | false, false); |
| 56 | } |
| 57 | |
| 58 | void drawText(SkCanvas* canvas, const SkString& string, |
| 59 | bool subpixelTextEnabled, bool lcdRenderTextEnabled) { |
| 60 | SkPaint paint; |
| 61 | paint.setColor(SK_ColorBLACK); |
| 62 | paint.setDither(true); |
| 63 | paint.setAntiAlias(true); |
| 64 | paint.setSubpixelText(subpixelTextEnabled); |
| 65 | paint.setLCDRenderText(lcdRenderTextEnabled); |
| 66 | paint.setTextSize(textHeight); |
| 67 | |
| 68 | canvas->drawText(string.c_str(), string.size(), 0, y, paint); |
| 69 | y += textHeight; |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | typedef GM INHERITED; |
| 74 | SkScalar y, textHeight; |
| 75 | }; |
| 76 | |
| 77 | /////////////////////////////////////////////////////////////////////////////// |
| 78 | |
| 79 | static GM* MyFactory(void*) { return new LcdTextGM; } |
| 80 | static GMRegistry reg(MyFactory); |
| 81 | |
| 82 | } |