Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSGText.h
Go to the documentation of this file.
1/*
2 * Copyright 2018 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 */
7
8#ifndef SkSGText_DEFINED
9#define SkSGText_DEFINED
10
11#include "include/core/SkFont.h"
13#include "include/core/SkPath.h"
15#include "include/core/SkRect.h"
22
23class SkCanvas;
24class SkMatrix;
25class SkPaint;
26class SkTextBlob;
27class SkTypeface;
28
29namespace sksg {
30class InvalidationController;
31
32/**
33 * Concrete Geometry node, wrapping a (shaped) SkTextBlob.
34 */
35class Text final : public GeometryNode {
36public:
38 ~Text() override;
39
40 SG_ATTRIBUTE(Typeface, sk_sp<SkTypeface> , fTypeface)
41 SG_ATTRIBUTE(Text , SkString , fText )
42 SG_ATTRIBUTE(Position, SkPoint , fPosition)
43 SG_ATTRIBUTE(Size , SkScalar , fSize )
44 SG_ATTRIBUTE(ScaleX , SkScalar , fScaleX )
45 SG_ATTRIBUTE(SkewX , SkScalar , fSkewX )
47 SG_ATTRIBUTE(Edging , SkFont::Edging , fEdging )
48 SG_ATTRIBUTE(Hinting , SkFontHinting , fHinting )
49
50 // TODO: add shaping functionality.
51
52protected:
53 void onClip(SkCanvas*, bool antiAlias) const override;
54 void onDraw(SkCanvas*, const SkPaint&) const override;
55 bool onContains(const SkPoint&) const override;
56
58 SkPath onAsPath() const override;
59
60private:
62
63 SkPoint alignedPosition(SkScalar advance) const;
64
65 sk_sp<SkTypeface> fTypeface;
66 SkString fText;
67 SkPoint fPosition = SkPoint::Make(0, 0);
68 SkScalar fSize = 12;
69 SkScalar fScaleX = 1;
70 SkScalar fSkewX = 0;
74
75 sk_sp<SkTextBlob> fBlob; // cached text blob
76
77 using INHERITED = GeometryNode;
78};
79
80} // namespace sksg
81
82#endif // SkSGText_DEFINED
Align
SkFontHinting
Definition SkFontTypes.h:18
@ kNormal
glyph outlines modified to improve constrast
#define SG_ATTRIBUTE(attr_name, attr_type, attr_container)
Definition SkSGNode.h:100
Edging
Definition SkFont.h:39
@ kAntiAlias
may have transparent pixels on glyph edges
~Text() override
static sk_sp< Text > Make(sk_sp< SkTypeface > tf, const SkString &text)
Definition SkSGText.cpp:21
bool onContains(const SkPoint &) const override
Definition SkSGText.cpp:79
SkPath onAsPath() const override
Definition SkSGText.cpp:83
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
Definition SkSGText.cpp:48
void onDraw(SkCanvas *, const SkPaint &) const override
Definition SkSGText.cpp:74
void onClip(SkCanvas *, bool antiAlias) const override
Definition SkSGText.cpp:88
float SkScalar
Definition extension.cpp:12
std::u16string text
Definition Skottie.h:32
static constexpr SkPoint Make(float x, float y)