1// Copyright 2020 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3#include "tools/fiddle/examples.h"
4REG_FIDDLE(text_rendering, 256, 256, false, 0) {
5void draw(SkCanvas* canvas) {
6    const char* fontFamily = nullptr;  // Default system family, if it exists.
7    SkFontStyle fontStyle;  // Default is normal weight, normal width,  upright slant.
8    sk_sp<SkFontMgr> fontManager = SkFontMgr::RefDefault();
9    sk_sp<SkTypeface> typeface = fontManager->legacyMakeTypeface(fontFamily, fontStyle);
10
11    SkFont font1(typeface, 64.0f, 1.0f, 0.0f);
12    SkFont font2(typeface, 64.0f, 1.5f, 0.0f);
13    font1.setEdging(SkFont::Edging::kAntiAlias);
14    font2.setEdging(SkFont::Edging::kAntiAlias);
15
16    // Note: MakeFromString may fail to produce expected results if the typeface
17    // does not have glyphs for the characters in the string.  The characters
18    // will not be kerned or shaped beyond a simple mapping from one Unicode
19    // code point to one glyph with a default advance.
20    sk_sp<SkTextBlob> blob1 = SkTextBlob::MakeFromString("Skia", font1);
21    sk_sp<SkTextBlob> blob2 = SkTextBlob::MakeFromString("Skia", font2);
22
23    SkPaint paint1, paint2, paint3;
24
25    paint1.setAntiAlias(true);
26    paint1.setColor(SkColorSetARGB(0xFF, 0x42, 0x85, 0xF4));
27
28    paint2.setAntiAlias(true);
29    paint2.setColor(SkColorSetARGB(0xFF, 0xDB, 0x44, 0x37));
30    paint2.setStyle(SkPaint::kStroke_Style);
31    paint2.setStrokeWidth(3.0f);
32
33    paint3.setAntiAlias(true);
34    paint3.setColor(SkColorSetARGB(0xFF, 0x0F, 0x9D, 0x58));
35
36    canvas->clear(SK_ColorWHITE);
37    canvas->drawTextBlob(blob1.get(), 20.0f, 64.0f, paint1);
38    canvas->drawTextBlob(blob1.get(), 20.0f, 144.0f, paint2);
39    canvas->drawTextBlob(blob2.get(), 20.0f, 224.0f, paint3);
40}
41}  // END FIDDLE
42