1 2 /* 3 * 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. 7 */ 8 #include "SampleCode.h" 9 #include "SkView.h" 10 #include "SkCanvas.h" 11 #include "SkDevice.h" 12 #include "SkPaint.h" 13 #include "SkShader.h" 14 15 class LCDView : public SkView { 16 public: LCDView()17 LCDView() {} 18 19 protected: 20 // overrides from SkEventSink onQuery(SkEvent * evt)21 virtual bool onQuery(SkEvent* evt) { 22 if (SampleCode::TitleQ(*evt)) { 23 SampleCode::TitleR(evt, "LCD Text"); 24 return true; 25 } 26 return this->INHERITED::onQuery(evt); 27 } 28 drawBG(SkCanvas * canvas)29 void drawBG(SkCanvas* canvas) { 30 canvas->drawColor(SK_ColorWHITE); 31 } 32 onDraw(SkCanvas * canvas)33 virtual void onDraw(SkCanvas* canvas) { 34 this->drawBG(canvas); 35 36 SkPaint paint; 37 paint.setAntiAlias(true); 38 39 SkScalar textSize = SkIntToScalar(6); 40 SkScalar delta = SK_Scalar1; 41 const char* text = "HHHamburgefonts iii"; 42 size_t len = strlen(text); 43 SkScalar x0 = SkIntToScalar(10); 44 SkScalar x1 = SkIntToScalar(310); 45 SkScalar y = SkIntToScalar(20); 46 47 for (int i = 0; i < 20; i++) { 48 paint.setTextSize(textSize); 49 textSize += delta; 50 51 paint.setLCDRenderText(false); 52 canvas->drawText(text, len, x0, y, paint); 53 paint.setLCDRenderText(true); 54 canvas->drawText(text, len, x1, y, paint); 55 56 y += paint.getFontSpacing(); 57 } 58 } 59 60 private: 61 typedef SkView INHERITED; 62 }; 63 64 ////////////////////////////////////////////////////////////////////////////// 65 MyFactory()66static SkView* MyFactory() { return new LCDView; } 67 static SkViewRegister reg(MyFactory); 68