epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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" |
reed@android.com | f549369 | 2009-07-22 19:21:01 +0000 | [diff] [blame] | 12 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 13 | class LCDView : public Sample { |
reed@android.com | f549369 | 2009-07-22 19:21:01 +0000 | [diff] [blame] | 14 | public: |
| 15 | LCDView() {} |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 16 | |
reed@android.com | f549369 | 2009-07-22 19:21:01 +0000 | [diff] [blame] | 17 | protected: |
Hal Canary | 8a02731 | 2019-07-03 10:55:44 -0400 | [diff] [blame] | 18 | SkString name() override { return SkString("LCD Text"); } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 19 | |
reed@android.com | f549369 | 2009-07-22 19:21:01 +0000 | [diff] [blame] | 20 | void drawBG(SkCanvas* canvas) { |
| 21 | canvas->drawColor(SK_ColorWHITE); |
| 22 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 23 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 24 | void onDrawContent(SkCanvas* canvas) override { |
reed@android.com | f549369 | 2009-07-22 19:21:01 +0000 | [diff] [blame] | 25 | this->drawBG(canvas); |
| 26 | |
| 27 | SkPaint paint; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 28 | |
reed@android.com | f549369 | 2009-07-22 19:21:01 +0000 | [diff] [blame] | 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 | |
Mike Reed | 9191913 | 2019-01-02 12:21:01 -0500 | [diff] [blame] | 37 | SkFont font; |
reed@android.com | f549369 | 2009-07-22 19:21:01 +0000 | [diff] [blame] | 38 | for (int i = 0; i < 20; i++) { |
Mike Reed | 9191913 | 2019-01-02 12:21:01 -0500 | [diff] [blame] | 39 | font.setSize(textSize); |
reed@android.com | f549369 | 2009-07-22 19:21:01 +0000 | [diff] [blame] | 40 | textSize += delta; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 41 | |
Mike Reed | 9191913 | 2019-01-02 12:21:01 -0500 | [diff] [blame] | 42 | font.setEdging(SkFont::Edging::kAntiAlias); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 43 | canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x0, y, font, paint); |
Mike Reed | 9191913 | 2019-01-02 12:21:01 -0500 | [diff] [blame] | 44 | font.setEdging(SkFont::Edging::kSubpixelAntiAlias); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 45 | canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x1, y, font, paint); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 46 | |
Mike Reed | 9191913 | 2019-01-02 12:21:01 -0500 | [diff] [blame] | 47 | y += font.getSpacing(); |
reed@android.com | f549369 | 2009-07-22 19:21:01 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 50 | |
reed@android.com | f549369 | 2009-07-22 19:21:01 +0000 | [diff] [blame] | 51 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 52 | using INHERITED = Sample; |
reed@android.com | f549369 | 2009-07-22 19:21:01 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | ////////////////////////////////////////////////////////////////////////////// |
| 56 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 57 | DEF_SAMPLE( return new LCDView(); ) |