Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 ()
 
- Protected Member Functions inherited from sksg::Node
 Node (uint32_t invalTraits)
 
 ~Node () override
 
const SkRectbounds () const
 
bool hasInval () const
 
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}

◆ 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)

◆ 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:3054
constexpr float x() const

◆ 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)
const SkRect & bounds() const
Definition SkSGNode.h:55
const Paint & paint
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
63 fBlob = SkTextBlob::MakeFromText(fText.c_str(), fText.size(), font, SkTextEncoding::kUTF8);
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
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)
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: