• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/core/SkCanvas.h"
8 #include "include/core/SkFont.h"
9 #include "include/core/SkPaint.h"
10 #include "include/core/SkShader.h"
11 #include "samplecode/Sample.h"
12 
13 class LCDView : public Sample {
14 public:
LCDView()15     LCDView() {}
16 
17 protected:
name()18     SkString name() override { return SkString("LCD Text"); }
19 
drawBG(SkCanvas * canvas)20     void drawBG(SkCanvas* canvas) {
21         canvas->drawColor(SK_ColorWHITE);
22     }
23 
onDrawContent(SkCanvas * canvas)24     void onDrawContent(SkCanvas* canvas) override {
25         this->drawBG(canvas);
26 
27         SkPaint paint;
28 
29         SkScalar textSize = SkIntToScalar(6);
30         SkScalar delta = SK_Scalar1;
31         const char* text = "HHHamburgefonts iii";
32         size_t len = strlen(text);
33         SkScalar x0 = SkIntToScalar(10);
34         SkScalar x1 = SkIntToScalar(310);
35         SkScalar y = SkIntToScalar(20);
36 
37         SkFont font;
38         for (int i = 0; i < 20; i++) {
39             font.setSize(textSize);
40             textSize += delta;
41 
42             font.setEdging(SkFont::Edging::kAntiAlias);
43             canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x0, y, font, paint);
44             font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
45             canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x1, y, font, paint);
46 
47             y += font.getSpacing();
48         }
49     }
50 
51 private:
52     typedef Sample INHERITED;
53 };
54 
55 //////////////////////////////////////////////////////////////////////////////
56 
57 DEF_SAMPLE( return new LCDView(); )
58