1 /* 2 * Copyright 2011 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 #include <SkFont.h> 8 #include "Sample.h" 9 #include "SkCanvas.h" 10 #include "SkPaint.h" 11 #include "SkShader.h" 12 13 class LCDView : public Sample { 14 public: LCDView()15 LCDView() {} 16 17 protected: onQuery(Sample::Event * evt)18 bool onQuery(Sample::Event* evt) override { 19 if (Sample::TitleQ(*evt)) { 20 Sample::TitleR(evt, "LCD Text"); 21 return true; 22 } 23 return this->INHERITED::onQuery(evt); 24 } 25 drawBG(SkCanvas * canvas)26 void drawBG(SkCanvas* canvas) { 27 canvas->drawColor(SK_ColorWHITE); 28 } 29 onDrawContent(SkCanvas * canvas)30 void onDrawContent(SkCanvas* canvas) override { 31 this->drawBG(canvas); 32 33 SkPaint paint; 34 35 SkScalar textSize = SkIntToScalar(6); 36 SkScalar delta = SK_Scalar1; 37 const char* text = "HHHamburgefonts iii"; 38 size_t len = strlen(text); 39 SkScalar x0 = SkIntToScalar(10); 40 SkScalar x1 = SkIntToScalar(310); 41 SkScalar y = SkIntToScalar(20); 42 43 SkFont font; 44 for (int i = 0; i < 20; i++) { 45 font.setSize(textSize); 46 textSize += delta; 47 48 font.setEdging(SkFont::Edging::kAntiAlias); 49 canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, x0, y, font, paint); 50 font.setEdging(SkFont::Edging::kSubpixelAntiAlias); 51 canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, x1, y, font, paint); 52 53 y += font.getSpacing(); 54 } 55 } 56 57 private: 58 typedef Sample INHERITED; 59 }; 60 61 ////////////////////////////////////////////////////////////////////////////// 62 63 DEF_SAMPLE( return new LCDView(); ) 64