Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
sksg::Text Class Referencefinal

#include <SkSGText.h>

Inheritance diagram for sksg::Text:
sksg::GeometryNode sksg::Node SkRefCnt SkRefCntBase

Public Member Functions

 ~Text () override
 
- Public Member Functions inherited from sksg::GeometryNode
void clip (SkCanvas *, bool antiAlias) const
 
void draw (SkCanvas *, const SkPaint &) const
 
bool contains (const SkPoint &) const
 
SkPath asPath () const
 
- Public Member Functions inherited from sksg::Node
const SkRectrevalidate (InvalidationController *, const SkMatrix &)
 
void invalidate (bool damage=true)
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< TextMake (sk_sp< SkTypeface > tf, const SkString &text)
 

Protected Member Functions

void onClip (SkCanvas *, bool antiAlias) const override
 
void onDraw (SkCanvas *, const SkPaint &) const override
 
bool onContains (const SkPoint &) const override
 
SkRect onRevalidate (InvalidationController *, const SkMatrix &) override
 
SkPath onAsPath () const override
 
- Protected Member Functions inherited from sksg::GeometryNode
 GeometryNode ()
 
virtual void onClip (SkCanvas *, bool antiAlias) const =0
 
virtual void onDraw (SkCanvas *, const SkPaint &) const =0
 
virtual bool onContains (const SkPoint &) const =0
 
virtual SkPath onAsPath () const =0
 
- Protected Member Functions inherited from sksg::Node
 Node (uint32_t invalTraits)
 
 ~Node () override
 
const SkRectbounds () const
 
bool hasInval () const
 
virtual SkRect onRevalidate (InvalidationController *, const SkMatrix &ctm)=0
 
void observeInval (const sk_sp< Node > &)
 
void unobserveInval (const sk_sp< Node > &)
 

Additional Inherited Members

- Protected Types inherited from sksg::Node
enum  InvalTraits { kBubbleDamage_Trait = 1 << 0 , kOverrideDamage_Trait = 1 << 1 }
 

Detailed Description

Concrete Geometry node, wrapping a (shaped) SkTextBlob.

Definition at line 35 of file SkSGText.h.

Constructor & Destructor Documentation

◆ ~Text()

sksg::Text::~Text ( )
overridedefault

Member Function Documentation

◆ Make()

sk_sp< Text > sksg::Text::Make ( sk_sp< SkTypeface tf,
const SkString text 
)
static

Definition at line 21 of file SkSGText.cpp.

21 {
22 return sk_sp<Text>(new Text(std::move(tf), text));
23}
std::u16string text

◆ onAsPath()

SkPath sksg::Text::onAsPath ( ) const
overrideprotectedvirtual

Implements sksg::GeometryNode.

Definition at line 83 of file SkSGText.cpp.

83 {
84 // TODO
85 return SkPath();
86}
Definition: SkPath.h:59

◆ onClip()

void sksg::Text::onClip ( SkCanvas canvas,
bool  antiAlias 
) const
overrideprotectedvirtual

Implements sksg::GeometryNode.

Definition at line 88 of file SkSGText.cpp.

88 {
89 canvas->clipPath(this->asPath(), antiAlias);
90}
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1456
SkPath asPath() const

◆ onContains()

bool sksg::Text::onContains ( const SkPoint p) const
overrideprotectedvirtual

Implements sksg::GeometryNode.

Definition at line 79 of file SkSGText.cpp.

79 {
80 return this->asPath().contains(p.x(), p.y());
81}
bool contains(SkScalar x, SkScalar y) const
Definition: SkPath.cpp:3118
constexpr float x() const
Definition: SkPoint_impl.h:181

◆ onDraw()

void sksg::Text::onDraw ( SkCanvas canvas,
const SkPaint paint 
) const
overrideprotectedvirtual

Implements sksg::GeometryNode.

Definition at line 74 of file SkSGText.cpp.

74 {
75 const auto aligned_pos = this->alignedPosition(this->bounds().width());
76 canvas->drawTextBlob(fBlob, aligned_pos.x(), aligned_pos.y(), paint);
77}
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
const SkRect & bounds() const
Definition: SkSGNode.h:55
const Paint & paint
Definition: color_source.cc:38
int32_t width

◆ onRevalidate()

SkRect sksg::Text::onRevalidate ( InvalidationController ,
const SkMatrix  
)
overrideprotectedvirtual

Implements sksg::Node.

Definition at line 48 of file SkSGText.cpp.

48 {
49 // TODO: we could potentially track invals which don't require rebuilding the blob.
50
52 font.setTypeface(fTypeface);
53 font.setSize(fSize);
54 font.setScaleX(fScaleX);
55 font.setSkewX(fSkewX);
56 font.setEdging(fEdging);
57 font.setHinting(fHinting);
58
59 // N.B.: fAlign is applied externally (in alignedPosition()), because
60 // 1) SkTextBlob has some trouble computing accurate bounds with alignment.
61 // 2) SkPaint::Align is slated for deprecation.
62
64 if (!fBlob) {
65 return SkRect::MakeEmpty();
66 }
67
68 const auto& bounds = fBlob->bounds();
69 const auto aligned_pos = this->alignedPosition(bounds.width());
70
71 return bounds.makeOffset(aligned_pos.x(), aligned_pos.y());
72}
@ kUTF8
uses bytes to represent UTF-8 or ASCII
Definition: SkFont.h:35
size_t size() const
Definition: SkString.h:131
const char * c_str() const
Definition: SkString.h:133
const SkRect & bounds() const
Definition: SkTextBlob.h:53
static sk_sp< SkTextBlob > MakeFromText(const void *text, size_t byteLength, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
Definition: SkTextBlob.cpp:788
font
Font Metadata and Metrics.
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595
constexpr SkRect makeOffset(float dx, float dy) const
Definition: SkRect.h:965
constexpr float width() const
Definition: SkRect.h:762

The documentation for this class was generated from the following files: