blob: 979dcb7ee8274be6687287159cdb4894b1c209d4 [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:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040018 bool onQuery(Sample::Event* evt) override {
19 if (Sample::TitleQ(*evt)) {
20 Sample::TitleR(evt, "LCD Text");
reed@android.comf5493692009-07-22 19:21:01 +000021 return true;
22 }
23 return this->INHERITED::onQuery(evt);
24 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000025
reed@android.comf5493692009-07-22 19:21:01 +000026 void drawBG(SkCanvas* canvas) {
27 canvas->drawColor(SK_ColorWHITE);
28 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000029
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040030 void onDrawContent(SkCanvas* canvas) override {
reed@android.comf5493692009-07-22 19:21:01 +000031 this->drawBG(canvas);
32
33 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000034
reed@android.comf5493692009-07-22 19:21:01 +000035 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
Mike Reed91919132019-01-02 12:21:01 -050043 SkFont font;
reed@android.comf5493692009-07-22 19:21:01 +000044 for (int i = 0; i < 20; i++) {
Mike Reed91919132019-01-02 12:21:01 -050045 font.setSize(textSize);
reed@android.comf5493692009-07-22 19:21:01 +000046 textSize += delta;
rmistry@google.comae933ce2012-08-23 18:19:56 +000047
Mike Reed91919132019-01-02 12:21:01 -050048 font.setEdging(SkFont::Edging::kAntiAlias);
Ben Wagner51e15a62019-05-07 15:38:46 -040049 canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x0, y, font, paint);
Mike Reed91919132019-01-02 12:21:01 -050050 font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
Ben Wagner51e15a62019-05-07 15:38:46 -040051 canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x1, y, font, paint);
rmistry@google.comae933ce2012-08-23 18:19:56 +000052
Mike Reed91919132019-01-02 12:21:01 -050053 y += font.getSpacing();
reed@android.comf5493692009-07-22 19:21:01 +000054 }
55 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000056
reed@android.comf5493692009-07-22 19:21:01 +000057private:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040058 typedef Sample INHERITED;
reed@android.comf5493692009-07-22 19:21:01 +000059};
60
61//////////////////////////////////////////////////////////////////////////////
62
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040063DEF_SAMPLE( return new LCDView(); )