Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
SkShaper::RunHandler Class Referenceabstract

#include <SkShaper.h>

Inheritance diagram for SkShaper::RunHandler:
SkSVGTextContext SkShaperJSONWriter SkTextBlobBuilderRunHandler skia::textlayout::OneLineShaper

Classes

struct  Buffer
 
struct  Range
 
struct  RunInfo
 

Public Member Functions

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

Definition at line 194 of file SkShaper.h.

Constructor & Destructor Documentation

◆ ~RunHandler()

virtual SkShaper::RunHandler::~RunHandler ( )
virtualdefault

Member Function Documentation

◆ beginLine()

void RunHandler::beginLine ( )
pure virtual

Called when beginning a line.

Implemented in SkShaperJSONWriter, and SkTextBlobBuilderRunHandler.

Definition at line 135 of file shape.cpp.

135 {
136 fCurrentPosition = fOffset;
137 fMaxRunAscent = 0;
138 fMaxRunDescent = 0;
139 fMaxRunLeading = 0;
140}

◆ commitLine()

void RunHandler::commitLine ( )
pure virtual

Called when ending a line.

Implemented in SkShaperJSONWriter, and SkTextBlobBuilderRunHandler.

Definition at line 201 of file shape.cpp.

201 {
202 if (fLineEndOffsets.empty() || fTextOffset > fLineEndOffsets.back()) {
203 // Ensure that fLineEndOffsets is monotonic.
204 fLineEndOffsets.push_back(fTextOffset);
205 }
206 fOffset += { 0, fMaxRunDescent + fMaxRunLeading - fMaxRunAscent };
207}

◆ commitRunBuffer()

void RunHandler::commitRunBuffer ( const RunInfo info)
pure virtual

Called after each runBuffer is filled out.

Implemented in SkTextBlobBuilderRunHandler, and SkShaperJSONWriter.

Definition at line 176 of file shape.cpp.

176 {
177 // for (size_t i = 0; i < info.glyphCount; ++i) {
178 // SkASSERT(fClusters[i] >= info.utf8Range.begin());
179 // // this fails for khmer example.
180 // SkASSERT(fClusters[i] < info.utf8Range.end());
181 // }
182 if (fCallbackFunction) {
183 fCallbackFunction(fCallbackContext,
184 fUtf8Text,
185 info.utf8Range.end(),
186 info.glyphCount,
187 fCurrentGlyphs,
188 fCurrentPoints,
189 fClusters,
190 info.fFont);
191 }
192 SkASSERT(0 <= fClusterOffset);
193 for (int i = 0; i < fGlyphCount; ++i) {
194 SkASSERT(fClusters[i] >= (unsigned)fClusterOffset);
195 fClusters[i] -= fClusterOffset;
196 }
197 fCurrentPosition += info.fAdvance;
198 fTextOffset = std::max(fTextOffset, info.utf8Range.end());
199}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkASSERT(cond)
Definition: SkAssert.h:116
static float max(float r, float g, float b)
Definition: hsl.cpp:49

◆ commitRunInfo()

void RunHandler::commitRunInfo ( )
pure virtual

Called after all runInfo calls for a line.

Implemented in SkShaperJSONWriter, and SkTextBlobBuilderRunHandler.

Definition at line 150 of file shape.cpp.

150 {
151 fCurrentPosition.fY -= fMaxRunAscent;
152}
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ runBuffer()

SkShaper::RunHandler::Buffer RunHandler::runBuffer ( const RunInfo info)
pure virtual

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

Implemented in SkTextBlobBuilderRunHandler, and SkShaperJSONWriter.

Definition at line 154 of file shape.cpp.

154 {
155 int glyphCount = SkTFitsIn<int>(info.glyphCount) ? info.glyphCount : INT_MAX;
156 int utf8RangeSize = SkTFitsIn<int>(info.utf8Range.size()) ? info.utf8Range.size() : INT_MAX;
157
158 const auto& runBuffer = fBuilder.allocRunTextPos(info.fFont, glyphCount, utf8RangeSize);
159 fCurrentGlyphs = runBuffer.glyphs;
160 fCurrentPoints = runBuffer.points();
161
162 if (runBuffer.utf8text && fUtf8Text) {
163 memcpy(runBuffer.utf8text, fUtf8Text + info.utf8Range.begin(), utf8RangeSize);
164 }
165 fClusters = runBuffer.clusters;
166 fGlyphCount = glyphCount;
167 fClusterOffset = info.utf8Range.begin();
168
169 return {runBuffer.glyphs,
170 runBuffer.points(),
171 nullptr,
173 fCurrentPosition};
174}
virtual Buffer runBuffer(const RunInfo &)=0
Definition: shape.cpp:154

◆ runInfo()

void RunHandler::runInfo ( const RunInfo info)
pure virtual

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

Implemented in SkTextBlobBuilderRunHandler, and SkShaperJSONWriter.

Definition at line 142 of file shape.cpp.

142 {
143 SkFontMetrics metrics;
144 info.fFont.getMetrics(&metrics);
145 fMaxRunAscent = std::min(fMaxRunAscent, metrics.fAscent);
146 fMaxRunDescent = std::max(fMaxRunDescent, metrics.fDescent);
147 fMaxRunLeading = std::max(fMaxRunLeading, metrics.fLeading);
148}
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: