blob: 0fd46a1b5d0995cb01ca778f3df1aa16a3f0d5cb [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05007#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.comf5493692009-07-22 19:21:01 +000012
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040013class LCDView : public Sample {
reed@android.comf5493692009-07-22 19:21:01 +000014public:
15 LCDView() {}
rmistry@google.comae933ce2012-08-23 18:19:56 +000016
reed@android.comf5493692009-07-22 19:21:01 +000017protected:
Hal Canary8a027312019-07-03 10:55:44 -040018 SkString name() override { return SkString("LCD Text"); }
rmistry@google.comae933ce2012-08-23 18:19:56 +000019
reed@android.comf5493692009-07-22 19:21:01 +000020 void drawBG(SkCanvas* canvas) {
21 canvas->drawColor(SK_ColorWHITE);
22 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000023
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040024 void onDrawContent(SkCanvas* canvas) override {
reed@android.comf5493692009-07-22 19:21:01 +000025 this->drawBG(canvas);
26
27 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000028
reed@android.comf5493692009-07-22 19:21:01 +000029 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 Reed91919132019-01-02 12:21:01 -050037 SkFont font;
reed@android.comf5493692009-07-22 19:21:01 +000038 for (int i = 0; i < 20; i++) {
Mike Reed91919132019-01-02 12:21:01 -050039 font.setSize(textSize);
reed@android.comf5493692009-07-22 19:21:01 +000040 textSize += delta;
rmistry@google.comae933ce2012-08-23 18:19:56 +000041
Mike Reed91919132019-01-02 12:21:01 -050042 font.setEdging(SkFont::Edging::kAntiAlias);
Ben Wagner51e15a62019-05-07 15:38:46 -040043 canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x0, y, font, paint);
Mike Reed91919132019-01-02 12:21:01 -050044 font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
Ben Wagner51e15a62019-05-07 15:38:46 -040045 canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x1, y, font, paint);
rmistry@google.comae933ce2012-08-23 18:19:56 +000046
Mike Reed91919132019-01-02 12:21:01 -050047 y += font.getSpacing();
reed@android.comf5493692009-07-22 19:21:01 +000048 }
49 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000050
reed@android.comf5493692009-07-22 19:21:01 +000051private:
John Stiles7571f9e2020-09-02 22:42:33 -040052 using INHERITED = Sample;
reed@android.comf5493692009-07-22 19:21:01 +000053};
54
55//////////////////////////////////////////////////////////////////////////////
56
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040057DEF_SAMPLE( return new LCDView(); )