blob: f209e9708941286aba18516b6a58eacee9df7f22 [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 Reed91919132019-01-02 12:21:01 -05007#include <SkFont.h>
Ben Wagnerb2c4ea62018-08-08 11:36:17 -04008#include "Sample.h"
reed@android.comf5493692009-07-22 19:21:01 +00009#include "SkCanvas.h"
reed@android.comf5493692009-07-22 19:21:01 +000010#include "SkPaint.h"
11#include "SkShader.h"
12
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);
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);
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(); )