Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
sktext::GlyphRunBuilder Class Reference

#include <GlyphRun.h>

Public Member Functions

GlyphRunList makeGlyphRunList (const GlyphRun &run, const SkPaint &paint, SkPoint origin)
 
const GlyphRunListtextToGlyphRunList (const SkFont &font, const SkPaint &paint, const void *bytes, size_t byteLength, SkPoint origin, SkTextEncoding encoding=SkTextEncoding::kUTF8)
 
const GlyphRunListblobToGlyphRunList (const SkTextBlob &blob, SkPoint origin)
 
std::tuple< SkSpan< const SkPoint >, SkSpan< const SkVector > > convertRSXForm (SkSpan< const SkRSXform > xforms)
 
bool empty () const
 

Detailed Description

Definition at line 137 of file GlyphRun.h.

Member Function Documentation

◆ blobToGlyphRunList()

const GlyphRunList & sktext::GlyphRunBuilder::blobToGlyphRunList ( const SkTextBlob blob,
SkPoint  origin 
)

Definition at line 233 of file GlyphRun.cpp.

234 {
235 // Pre-size all the buffers, so they don't move during processing.
236 this->initialize(blob);
237
238 SkPoint* positionCursor = fPositions;
239 SkVector* scaledRotationsCursor = fScaledRotations;
240 for (SkTextBlobRunIterator it(&blob); !it.done(); it.next()) {
241 size_t runSize = it.glyphCount();
242 if (runSize == 0 || !SkFontPriv::IsFinite(it.font())) {
243 // If no glyphs or the font is not finite, don't add the run.
244 continue;
245 }
246
247 const SkFont& font = it.font();
248 auto glyphIDs = SkSpan<const SkGlyphID>{it.glyphs(), runSize};
249
250 SkSpan<const SkPoint> positions;
251 SkSpan<const SkVector> scaledRotations;
252 switch (it.positioning()) {
254 positions = draw_text_positions(font, glyphIDs, it.offset(), positionCursor);
255 positionCursor += positions.size();
256 break;
257 }
259 positions = SkSpan(positionCursor, runSize);
260 for (auto x : SkSpan<const SkScalar>{it.pos(), glyphIDs.size()}) {
261 *positionCursor++ = SkPoint::Make(x, it.offset().y());
262 }
263 break;
264 }
266 positions = SkSpan(it.points(), runSize);
267 break;
268 }
270 positions = SkSpan(positionCursor, runSize);
271 scaledRotations = SkSpan(scaledRotationsCursor, runSize);
272 for (const SkRSXform& xform : SkSpan(it.xforms(), runSize)) {
273 *positionCursor++ = {xform.fTx, xform.fTy};
274 *scaledRotationsCursor++ = {xform.fSCos, xform.fSSin};
275 }
276 break;
277 }
278 }
279
280 const uint32_t* clusters = it.clusters();
281 this->makeGlyphRun(
282 font,
283 glyphIDs,
284 positions,
285 SkSpan<const char>(it.text(), it.textSize()),
286 SkSpan<const uint32_t>(clusters, clusters ? runSize : 0),
287 scaledRotations);
288 }
289
290 return this->setGlyphRunList(&blob, blob.bounds(), origin);
291}
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
static bool IsFinite(const SkFont &font)
Definition: SkFontPriv.h:78
Definition: SkFont.h:35
constexpr size_t size() const
Definition: SkSpan_impl.h:95
const SkRect & bounds() const
Definition: SkTextBlob.h:53
double x
font
Font Metadata and Metrics.
static SkSpan< const SkPoint > draw_text_positions(const SkFont &font, SkSpan< const SkGlyphID > glyphIDs, SkPoint origin, SkPoint *buffer)
Definition: GlyphRun.cpp:196
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173

◆ convertRSXForm()

std::tuple< SkSpan< const SkPoint >, SkSpan< const SkVector > > sktext::GlyphRunBuilder::convertRSXForm ( SkSpan< const SkRSXform xforms)

Definition at line 294 of file GlyphRun.cpp.

294 {
295 const int count = SkCount(xforms);
296 this->prepareBuffers(count, count);
297 auto positions = SkSpan(fPositions.get(), count);
298 auto scaledRotations = SkSpan(fScaledRotations.get(), count);
299 for (auto [pos, sr, xform] : SkMakeZip(positions, scaledRotations, xforms)) {
300 auto [scos, ssin, tx, ty] = xform;
301 pos = {tx, ty};
302 sr = {scos, ssin};
303 }
304 return {positions, scaledRotations};
305}
int count
Definition: FontMgrTest.cpp:50
SkPoint pos
constexpr int SkCount(const Container &c)
Definition: SkTLogic.h:54
constexpr auto SkMakeZip(Ts &&... ts)
Definition: SkZip.h:212
PODArray< SkRSXform > xforms
Definition: SkRecords.h:332

◆ empty()

bool sktext::GlyphRunBuilder::empty ( ) const
inline

Definition at line 150 of file GlyphRun.h.

150{ return fGlyphRunListStorage.empty(); }

◆ makeGlyphRunList()

GlyphRunList sktext::GlyphRunBuilder::makeGlyphRunList ( const GlyphRun run,
const SkPaint paint,
SkPoint  origin 
)

Definition at line 189 of file GlyphRun.cpp.

190 {
191 const SkRect bounds =
192 glyphrun_source_bounds(run.font(), paint, run.source(), run.scaledRotations());
193 return GlyphRunList{run, bounds, origin, this};
194}
const Paint & paint
Definition: color_source.cc:38
Optional< SkRect > bounds
Definition: SkRecords.h:189
Definition: run.py:1
def run(cmd)
Definition: run.py:14
static SkRect glyphrun_source_bounds(const SkFont &font, const SkPaint &paint, SkZip< const SkGlyphID, const SkPoint > source, SkSpan< const SkVector > scaledRotations)
Definition: GlyphRun.cpp:119

◆ textToGlyphRunList()

const GlyphRunList & sktext::GlyphRunBuilder::textToGlyphRunList ( const SkFont font,
const SkPaint paint,
const void *  bytes,
size_t  byteLength,
SkPoint  origin,
SkTextEncoding  encoding = SkTextEncoding::kUTF8 
)

Definition at line 211 of file GlyphRun.cpp.

214 {
215 auto glyphIDs = textToGlyphIDs(font, bytes, byteLength, encoding);
217 this->prepareBuffers(glyphIDs.size(), 0);
218 if (!glyphIDs.empty()) {
219 SkSpan<const SkPoint> positions = draw_text_positions(font, glyphIDs, {0, 0}, fPositions);
220 this->makeGlyphRun(font,
221 glyphIDs,
222 positions,
226 auto run = fGlyphRunListStorage.front();
227 bounds = glyphrun_source_bounds(run.font(), paint, run.source(), run.scaledRotations());
228 }
229
230 return this->setGlyphRunList(nullptr, bounds, origin);
231}
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595

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