Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkTextBlobBuilderRunHandler Class Referencefinal

#include <SkShaper.h>

Inheritance diagram for SkTextBlobBuilderRunHandler:
SkShaper::RunHandler

Public Member Functions

 SkTextBlobBuilderRunHandler (const char *utf8Text, SkPoint offset)
 
sk_sp< SkTextBlobmakeBlob ()
 
SkPoint endPoint ()
 
void beginLine () override
 
void runInfo (const RunInfo &) override
 
void commitRunInfo () override
 
Buffer runBuffer (const RunInfo &) override
 
void commitRunBuffer (const RunInfo &) override
 
void commitLine () override
 
- Public Member Functions inherited from SkShaper::RunHandler
virtual ~RunHandler ()=default
 
virtual void beginLine ()=0
 
virtual void runInfo (const RunInfo &)=0
 
virtual void commitRunInfo ()=0
 
virtual Buffer runBuffer (const RunInfo &)=0
 
virtual void commitRunBuffer (const RunInfo &)=0
 
virtual void commitLine ()=0
 

Detailed Description

Helper for shaping text directly into a SkTextBlob.

Definition at line 278 of file SkShaper.h.

Constructor & Destructor Documentation

◆ SkTextBlobBuilderRunHandler()

SkTextBlobBuilderRunHandler::SkTextBlobBuilderRunHandler ( const char *  utf8Text,
SkPoint  offset 
)
inline

Definition at line 280 of file SkShaper.h.

281 : fUtf8Text(utf8Text)
282 , fOffset(offset) {}
SeparatedVector2 offset

Member Function Documentation

◆ beginLine()

void SkTextBlobBuilderRunHandler::beginLine ( )
overridevirtual

Called when beginning a line.

Implements SkShaper::RunHandler.

Definition at line 208 of file SkShaper.cpp.

208 {
209 fCurrentPosition = fOffset;
210 fMaxRunAscent = 0;
211 fMaxRunDescent = 0;
212 fMaxRunLeading = 0;
213}

◆ commitLine()

void SkTextBlobBuilderRunHandler::commitLine ( )
overridevirtual

Called when ending a line.

Implements SkShaper::RunHandler.

Definition at line 253 of file SkShaper.cpp.

253 {
254 fOffset += { 0, fMaxRunDescent + fMaxRunLeading - fMaxRunAscent };
255}

◆ commitRunBuffer()

void SkTextBlobBuilderRunHandler::commitRunBuffer ( const RunInfo info)
overridevirtual

Called after each runBuffer is filled out.

Implements SkShaper::RunHandler.

Definition at line 245 of file SkShaper.cpp.

245 {
246 SkASSERT(0 <= fClusterOffset);
247 for (int i = 0; i < fGlyphCount; ++i) {
248 SkASSERT(fClusters[i] >= (unsigned)fClusterOffset);
249 fClusters[i] -= fClusterOffset;
250 }
251 fCurrentPosition += info.fAdvance;
252}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ commitRunInfo()

void SkTextBlobBuilderRunHandler::commitRunInfo ( )
overridevirtual

Called after all runInfo calls for a line.

Implements SkShaper::RunHandler.

Definition at line 222 of file SkShaper.cpp.

222 {
223 fCurrentPosition.fY -= fMaxRunAscent;
224}
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ endPoint()

SkPoint SkTextBlobBuilderRunHandler::endPoint ( )
inline

Definition at line 284 of file SkShaper.h.

284{ return fOffset; }

◆ makeBlob()

sk_sp< SkTextBlob > SkTextBlobBuilderRunHandler::makeBlob ( )

Definition at line 257 of file SkShaper.cpp.

257 {
258 return fBuilder.make();
259}
sk_sp< SkTextBlob > make()
Definition: SkTextBlob.cpp:617

◆ runBuffer()

SkShaper::RunHandler::Buffer SkTextBlobBuilderRunHandler::runBuffer ( const RunInfo info)
overridevirtual

Called for each run in a line after commitRunInfo. The buffer will be filled out.

Implements SkShaper::RunHandler.

Definition at line 226 of file SkShaper.cpp.

226 {
227 int glyphCount = SkTFitsIn<int>(info.glyphCount) ? info.glyphCount : INT_MAX;
228 int utf8RangeSize = SkTFitsIn<int>(info.utf8Range.size()) ? info.utf8Range.size() : INT_MAX;
229
230 const auto& runBuffer = fBuilder.allocRunTextPos(info.fFont, glyphCount, utf8RangeSize);
231 if (runBuffer.utf8text && fUtf8Text) {
232 memcpy(runBuffer.utf8text, fUtf8Text + info.utf8Range.begin(), utf8RangeSize);
233 }
234 fClusters = runBuffer.clusters;
235 fGlyphCount = glyphCount;
236 fClusterOffset = info.utf8Range.begin();
237
238 return { runBuffer.glyphs,
239 runBuffer.points(),
240 nullptr,
242 fCurrentPosition };
243}
Buffer runBuffer(const RunInfo &) override
Definition: SkShaper.cpp:226
const RunBuffer & allocRunTextPos(const SkFont &font, int count, int textByteCount, const SkRect *bounds=nullptr)
Definition: SkTextBlob.cpp:592

◆ runInfo()

void SkTextBlobBuilderRunHandler::runInfo ( const RunInfo info)
overridevirtual

Called once for each run in a line. Can compute baselines and offsets.

Implements SkShaper::RunHandler.

Definition at line 214 of file SkShaper.cpp.

214 {
215 SkFontMetrics metrics;
216 info.fFont.getMetrics(&metrics);
217 fMaxRunAscent = std::min(fMaxRunAscent, metrics.fAscent);
218 fMaxRunDescent = std::max(fMaxRunDescent, metrics.fDescent);
219 fMaxRunLeading = std::max(fMaxRunLeading, metrics.fLeading);
220}
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
SkScalar fLeading
distance to add between lines, typically positive or zero
Definition: SkFontMetrics.h:57
SkScalar fAscent
distance to reserve above baseline, typically negative
Definition: SkFontMetrics.h:54
SkScalar fDescent
distance to reserve below baseline, typically positive
Definition: SkFontMetrics.h:55

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