Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
SkTextBlob Class Referencefinal

#include <SkTextBlob.h>

Inheritance diagram for SkTextBlob:
SkNVRefCnt< SkTextBlob >

Classes

class  Iter
 

Public Types

enum  GlyphPositioning : uint8_t
 

Public Member Functions

const SkRectbounds () const
 
uint32_t uniqueID () const
 
int getIntercepts (const SkScalar bounds[2], SkScalar intervals[], const SkPaint *paint=nullptr) const
 
size_t serialize (const SkSerialProcs &procs, void *memory, size_t memory_size) const
 
sk_sp< SkDataserialize (const SkSerialProcs &procs) const
 
- Public Member Functions inherited from SkNVRefCnt< SkTextBlob >
 SkNVRefCnt ()
 
 ~SkNVRefCnt ()
 
bool unique () const
 
void ref () const
 
void unref () const
 
void deref () const
 
bool refCntGreaterThan (int32_t threadIsolatedTestCnt) const
 

Static Public Member Functions

static sk_sp< SkTextBlobMakeFromText (const void *text, size_t byteLength, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
 
static sk_sp< SkTextBlobMakeFromString (const char *string, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
 
static sk_sp< SkTextBlobMakeFromPosTextH (const void *text, size_t byteLength, const SkScalar xpos[], SkScalar constY, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
 
static sk_sp< SkTextBlobMakeFromPosText (const void *text, size_t byteLength, const SkPoint pos[], const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
 
static sk_sp< SkTextBlobMakeFromRSXform (const void *text, size_t byteLength, const SkRSXform xform[], const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
 
static sk_sp< SkTextBlobDeserialize (const void *data, size_t size, const SkDeserialProcs &procs)
 

Friends

class SkNVRefCnt< SkTextBlob >
 
class sktext::GlyphRunList
 
class SkTextBlobBuilder
 
class SkTextBlobPriv
 
class SkTextBlobRunIterator
 

Detailed Description

SkTextBlob combines multiple text runs into an immutable container. Each text run consists of glyphs, SkPaint, and position. Only parts of SkPaint related to fonts and text rendering are used by run.

Definition at line 41 of file SkTextBlob.h.

Member Enumeration Documentation

◆ GlyphPositioning

Definition at line 192 of file SkTextBlob.cpp.

192 : uint8_t {
193 kDefault_Positioning = 0, // Default glyph advances -- zero scalars per glyph.
194 kHorizontal_Positioning = 1, // Horizontal positioning -- one scalar per glyph.
195 kFull_Positioning = 2, // Point positioning -- two scalars per glyph.
196 kRSXform_Positioning = 3, // RSXform positioning -- four scalars per glyph.
197};
@ kHorizontal_Positioning
@ kDefault_Positioning
@ kRSXform_Positioning
@ kFull_Positioning

Member Function Documentation

◆ bounds()

const SkRect & SkTextBlob::bounds ( ) const
inline

Returns conservative bounding box. Uses SkPaint associated with each glyph to determine glyph bounds, and unions all bounds. Returned bounds may be larger than the bounds of all glyphs in runs.

Returns
conservative bounding box

Definition at line 53 of file SkTextBlob.h.

53{ return fBounds; }

◆ Deserialize()

sk_sp< SkTextBlob > SkTextBlob::Deserialize ( const void *  data,
size_t  size,
const SkDeserialProcs procs 
)
static

Recreates SkTextBlob that was serialized into data. Returns constructed SkTextBlob if successful; otherwise, returns nullptr. Fails if size is smaller than required data length, or if data does not permit constructing valid SkTextBlob.

procs.fTypefaceProc permits supplying a custom function to decode SkTypeface. If procs.fTypefaceProc is nullptr, default decoding is used. procs.fTypefaceCtx may be used to provide user context to procs.fTypefaceProc; procs.fTypefaceProc is called with a pointer to SkTypeface data, data byte length, and user context.

Parameters
datapointer for serial data
sizesize of data
procscustom serial data decoders; may be nullptr
Returns
SkTextBlob constructed from data in memory

Definition at line 855 of file SkTextBlob.cpp.

856 {
858 buffer.setDeserialProcs(procs);
860}
static sk_sp< SkTextBlob > MakeFromBuffer(SkReadBuffer &)
static const uint8_t buffer[]
size_t length

◆ getIntercepts()

int SkTextBlob::getIntercepts ( const SkScalar  bounds[2],
SkScalar  intervals[],
const SkPaint paint = nullptr 
) const

Returns the number of intervals that intersect bounds. bounds describes a pair of lines parallel to the text advance. The return count is zero or a multiple of two, and is at most twice the number of glyphs in the the blob.

Pass nullptr for intervals to determine the size of the interval array.

Runs within the blob that contain SkRSXform are ignored when computing intercepts.

Parameters
boundslower and upper line parallel to the advance
intervalsreturned intersections; may be nullptr
paintspecifies stroking, SkPathEffect that affects the result; may be nullptr
Returns
number of intersections; may be zero

Definition at line 927 of file SkTextBlob.cpp.

928 {
929 SkTLazy<SkPaint> defaultPaint;
930 if (paint == nullptr) {
931 defaultPaint.init();
932 paint = defaultPaint.get();
933 }
934
936 auto glyphRunList = builder.blobToGlyphRunList(*this, {0, 0});
937
938 int intervalCount = 0;
939 for (const sktext::GlyphRun& glyphRun : glyphRunList) {
940 // Ignore RSXForm runs.
941 if (glyphRun.scaledRotations().empty()) {
942 intervalCount = get_glyph_run_intercepts(
943 glyphRun, *paint, bounds, intervals, &intervalCount);
944 }
945 }
946
947 return intervalCount;
948}
T * init(Args &&... args)
Definition SkTLazy.h:45
T * get()
Definition SkTLazy.h:83
const SkRect & bounds() const
Definition SkTextBlob.h:53
const Paint & paint

◆ MakeFromPosText()

sk_sp< SkTextBlob > SkTextBlob::MakeFromPosText ( const void *  text,
size_t  byteLength,
const SkPoint  pos[],
const SkFont font,
SkTextEncoding  encoding = SkTextEncoding::kUTF8 
)
static

Returns a textblob built from a single run of text with positions. This is equivalent to using SkTextBlobBuilder and calling allocRunPos(). Returns nullptr if byteLength is zero.

Parameters
textcharacter code points or glyphs drawn (based on encoding)
byteLengthbyte length of text array
posarray of positions, must contain values for all of the character points.
fontSkFont used for this run
encodingspecifies the encoding of the text array.
Returns
new textblob or nullptr

Definition at line 803 of file SkTextBlob.cpp.

805 {
806 const int count = font.countText(text, byteLength, encoding);
807 if (count < 1) {
808 return nullptr;
809 }
811 auto buffer = builder.allocRunPos(font, count);
812 font.textToGlyphs(text, byteLength, encoding, buffer.glyphs, count);
813 memcpy(buffer.points(), pos, count * sizeof(SkPoint));
814 return builder.make();
815}
int count
SkPoint pos
std::u16string text
font
Font Metadata and Metrics.

◆ MakeFromPosTextH()

sk_sp< SkTextBlob > SkTextBlob::MakeFromPosTextH ( const void *  text,
size_t  byteLength,
const SkScalar  xpos[],
SkScalar  constY,
const SkFont font,
SkTextEncoding  encoding = SkTextEncoding::kUTF8 
)
static

Returns a textblob built from a single run of text with x-positions and a single y value. This is equivalent to using SkTextBlobBuilder and calling allocRunPosH(). Returns nullptr if byteLength is zero.

Parameters
textcharacter code points or glyphs drawn (based on encoding)
byteLengthbyte length of text array
xposarray of x-positions, must contain values for all of the character points.
constYshared y-position for each character point, to be paired with each xpos.
fontSkFont used for this run
encodingspecifies the encoding of the text array.
Returns
new textblob or nullptr

Definition at line 817 of file SkTextBlob.cpp.

819 {
820 const int count = font.countText(text, byteLength, encoding);
821 if (count < 1) {
822 return nullptr;
823 }
825 auto buffer = builder.allocRunPosH(font, count, constY);
826 font.textToGlyphs(text, byteLength, encoding, buffer.glyphs, count);
827 memcpy(buffer.pos, xpos, count * sizeof(SkScalar));
828 return builder.make();
829}
float SkScalar
Definition extension.cpp:12

◆ MakeFromRSXform()

sk_sp< SkTextBlob > SkTextBlob::MakeFromRSXform ( const void *  text,
size_t  byteLength,
const SkRSXform  xform[],
const SkFont font,
SkTextEncoding  encoding = SkTextEncoding::kUTF8 
)
static

Definition at line 831 of file SkTextBlob.cpp.

833 {
834 const int count = font.countText(text, byteLength, encoding);
835 if (count < 1) {
836 return nullptr;
837 }
839 auto buffer = builder.allocRunRSXform(font, count);
840 font.textToGlyphs(text, byteLength, encoding, buffer.glyphs, count);
841 memcpy(buffer.xforms(), xform, count * sizeof(SkRSXform));
842 return builder.make();
843}

◆ MakeFromString()

static sk_sp< SkTextBlob > SkTextBlob::MakeFromString ( const char *  string,
const SkFont font,
SkTextEncoding  encoding = SkTextEncoding::kUTF8 
)
inlinestatic

Creates SkTextBlob with a single run. string meaning depends on SkTextEncoding; by default, string is encoded as UTF-8.

font contains attributes used to define the run text.

When encoding is SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, or SkTextEncoding::kUTF32, this function uses the default character-to-glyph mapping from the SkTypeface in font. It does not perform typeface fallback for characters not found in the SkTypeface. It does not perform kerning or other complex shaping; glyphs are positioned based on their default advances.

Parameters
stringcharacter code points or glyphs drawn
fonttext size, typeface, text scale, and so on, used to draw
encodingtext encoding used in the text array
Returns
SkTextBlob constructed from one run

Definition at line 115 of file SkTextBlob.h.

116 {
117 if (!string) {
118 return nullptr;
119 }
120 return MakeFromText(string, strlen(string), font, encoding);
121 }
static sk_sp< SkTextBlob > MakeFromText(const void *text, size_t byteLength, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)

◆ MakeFromText()

sk_sp< SkTextBlob > SkTextBlob::MakeFromText ( const void *  text,
size_t  byteLength,
const SkFont font,
SkTextEncoding  encoding = SkTextEncoding::kUTF8 
)
static

Creates SkTextBlob with a single run.

font contains attributes used to define the run text.

When encoding is SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, or SkTextEncoding::kUTF32, this function uses the default character-to-glyph mapping from the SkTypeface in font. It does not perform typeface fallback for characters not found in the SkTypeface. It does not perform kerning or other complex shaping; glyphs are positioned based on their default advances.

Parameters
textcharacter code points or glyphs drawn
byteLengthbyte length of text array
fonttext size, typeface, text scale, and so on, used to draw
encodingtext encoding used in the text array
Returns
SkTextBlob constructed from one run

Definition at line 788 of file SkTextBlob.cpp.

789 {
790 // Note: we deliberately promote this to fully positioned blobs, since we'd have to pay the
791 // same cost down stream (i.e. computing bounds), so its cheaper to pay the cost once now.
792 const int count = font.countText(text, byteLength, encoding);
793 if (count < 1) {
794 return nullptr;
795 }
797 auto buffer = builder.allocRunPos(font, count);
798 font.textToGlyphs(text, byteLength, encoding, buffer.glyphs, count);
799 font.getPos(buffer.glyphs, count, buffer.points(), {0, 0});
800 return builder.make();
801}

◆ serialize() [1/2]

sk_sp< SkData > SkTextBlob::serialize ( const SkSerialProcs procs) const

Returns storage containing SkData describing SkTextBlob, using optional custom encoders.

procs.fTypefaceProc permits supplying a custom function to encode SkTypeface. If procs.fTypefaceProc is nullptr, default encoding is used. procs.fTypefaceCtx may be used to provide user context to procs.fTypefaceProc; procs.fTypefaceProc is called with a pointer to SkTypeface and user context.

Parameters
procscustom serial data encoders; may be nullptr
Returns
storage containing serialized SkTextBlob

example: https://fiddle.skia.org/c/@TextBlob_serialize_2

Definition at line 845 of file SkTextBlob.cpp.

845 {
848
849 size_t total = buffer.bytesWritten();
851 buffer.writeToMemory(data->writable_data());
852 return data;
853}
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition SkData.cpp:116
static void Flatten(const SkTextBlob &, SkWriteBuffer &)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ serialize() [2/2]

size_t SkTextBlob::serialize ( const SkSerialProcs procs,
void *  memory,
size_t  memory_size 
) const

Writes data to allow later reconstruction of SkTextBlob. memory points to storage to receive the encoded data, and memory_size describes the size of storage. Returns bytes used if provided storage is large enough to hold all data; otherwise, returns zero.

procs.fTypefaceProc permits supplying a custom function to encode SkTypeface. If procs.fTypefaceProc is nullptr, default encoding is used. procs.fTypefaceCtx may be used to provide user context to procs.fTypefaceProc; procs.fTypefaceProc is called with a pointer to SkTypeface and user context.

Parameters
procscustom serial data encoders; may be nullptr
memorystorage for data
memory_sizesize of storage
Returns
bytes written, or zero if required storage is larger than memory_size

example: https://fiddle.skia.org/c/@TextBlob_serialize

Definition at line 864 of file SkTextBlob.cpp.

864 {
865 SkBinaryWriteBuffer buffer(memory, memory_size, procs);
867 return buffer.usingInitialStorage() ? buffer.bytesWritten() : 0u;
868}

◆ uniqueID()

uint32_t SkTextBlob::uniqueID ( ) const
inline

Returns a non-zero value unique among all text blobs.

Returns
identifier for SkTextBlob

Definition at line 59 of file SkTextBlob.h.

59{ return fUniqueID; }

Friends And Related Symbol Documentation

◆ SkNVRefCnt< SkTextBlob >

friend class SkNVRefCnt< SkTextBlob >
friend

Definition at line 209 of file SkTextBlob.h.

◆ sktext::GlyphRunList

friend class sktext::GlyphRunList
friend

Definition at line 269 of file SkTextBlob.h.

◆ SkTextBlobBuilder

friend class SkTextBlobBuilder
friend

Definition at line 270 of file SkTextBlob.h.

◆ SkTextBlobPriv

friend class SkTextBlobPriv
friend

Definition at line 271 of file SkTextBlob.h.

◆ SkTextBlobRunIterator

friend class SkTextBlobRunIterator
friend

Definition at line 272 of file SkTextBlob.h.


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