Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Friends | List of all members
SkTextBlobBuilder Class Reference

#include <SkTextBlob.h>

Classes

struct  RunBuffer
 

Public Member Functions

 SkTextBlobBuilder ()
 
 ~SkTextBlobBuilder ()
 
sk_sp< SkTextBlobmake ()
 
const RunBufferallocRun (const SkFont &font, int count, SkScalar x, SkScalar y, const SkRect *bounds=nullptr)
 
const RunBufferallocRunPosH (const SkFont &font, int count, SkScalar y, const SkRect *bounds=nullptr)
 
const RunBufferallocRunPos (const SkFont &font, int count, const SkRect *bounds=nullptr)
 
const RunBufferallocRunRSXform (const SkFont &font, int count)
 
const RunBufferallocRunText (const SkFont &font, int count, SkScalar x, SkScalar y, int textByteCount, const SkRect *bounds=nullptr)
 
const RunBufferallocRunTextPosH (const SkFont &font, int count, SkScalar y, int textByteCount, const SkRect *bounds=nullptr)
 
const RunBufferallocRunTextPos (const SkFont &font, int count, int textByteCount, const SkRect *bounds=nullptr)
 
const RunBufferallocRunTextRSXform (const SkFont &font, int count, int textByteCount, const SkRect *bounds=nullptr)
 

Friends

class SkTextBlobPriv
 
class SkTextBlobBuilderPriv
 

Detailed Description

Helper class for constructing SkTextBlob.

Definition at line 290 of file SkTextBlob.h.

Constructor & Destructor Documentation

◆ SkTextBlobBuilder()

SkTextBlobBuilder::SkTextBlobBuilder ( )

Constructs empty SkTextBlobBuilder. By default, SkTextBlobBuilder has no runs.

Returns
empty SkTextBlobBuilder

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

Definition at line 258 of file SkTextBlob.cpp.

259 : fStorageSize(0)
260 , fStorageUsed(0)
261 , fRunCount(0)
262 , fDeferredBounds(false)
263 , fLastRun(0) {
264 fBounds.setEmpty();
265}
void setEmpty()
Definition: SkRect.h:842

◆ ~SkTextBlobBuilder()

SkTextBlobBuilder::~SkTextBlobBuilder ( )

Deletes data allocated internally by SkTextBlobBuilder.

Definition at line 267 of file SkTextBlob.cpp.

267 {
268 if (nullptr != fStorage.get()) {
269 // We are abandoning runs and must destruct the associated font data.
270 // The easiest way to accomplish that is to use the blob destructor.
271 this->make();
272 }
273}
sk_sp< SkTextBlob > make()
Definition: SkTextBlob.cpp:617

Member Function Documentation

◆ allocRun()

const SkTextBlobBuilder::RunBuffer & SkTextBlobBuilder::allocRun ( const SkFont font,
int  count,
SkScalar  x,
SkScalar  y,
const SkRect bounds = nullptr 
)

Returns run with storage for glyphs. Caller must write count glyphs to RunBuffer::glyphs before next call to SkTextBlobBuilder.

RunBuffer::pos, RunBuffer::utf8text, and RunBuffer::clusters should be ignored.

Glyphs share metrics in font.

Glyphs are positioned on a baseline at (x, y), using font metrics to determine their relative placement.

bounds defines an optional bounding box, used to suppress drawing when SkTextBlob bounds does not intersect SkSurface bounds. If bounds is nullptr, SkTextBlob bounds is computed from (x, y) and RunBuffer::glyphs metrics.

Parameters
fontSkFont used for this run
countnumber of glyphs
xhorizontal offset within the blob
yvertical offset within the blob
boundsoptional run bounding box
Returns
writable glyph buffer

Definition at line 539 of file SkTextBlob.cpp.

541 {
542 this->allocInternal(font, SkTextBlob::kDefault_Positioning, count, 0, {x, y}, bounds);
543 return fCurrentRunBuffer;
544}
int count
Definition: FontMgrTest.cpp:50
@ kDefault_Positioning
Definition: SkTextBlob.cpp:193
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
font
Font Metadata and Metrics.

◆ allocRunPos()

const SkTextBlobBuilder::RunBuffer & SkTextBlobBuilder::allocRunPos ( const SkFont font,
int  count,
const SkRect bounds = nullptr 
)

Returns run with storage for glyphs and SkPoint positions. Caller must write count glyphs to RunBuffer::glyphs and count SkPoint to RunBuffer::pos before next call to SkTextBlobBuilder.

RunBuffer::utf8text and RunBuffer::clusters should be ignored.

Glyphs share metrics in font.

Glyphs are positioned using SkPoint written by caller to RunBuffer::pos, using two scalar values for each SkPoint.

bounds defines an optional bounding box, used to suppress drawing when SkTextBlob bounds does not intersect SkSurface bounds. If bounds is nullptr, SkTextBlob bounds is computed from RunBuffer::pos, and RunBuffer::glyphs metrics.

Parameters
fontSkFont used for this run
countnumber of glyphs
boundsoptional run bounding box
Returns
writable glyph buffer and SkPoint buffer

Definition at line 553 of file SkTextBlob.cpp.

554 {
555 this->allocInternal(font, SkTextBlob::kFull_Positioning, count, 0, {0, 0}, bounds);
556 return fCurrentRunBuffer;
557}
@ kFull_Positioning
Definition: SkTextBlob.cpp:195

◆ allocRunPosH()

const SkTextBlobBuilder::RunBuffer & SkTextBlobBuilder::allocRunPosH ( const SkFont font,
int  count,
SkScalar  y,
const SkRect bounds = nullptr 
)

Returns run with storage for glyphs and positions along baseline. Caller must write count glyphs to RunBuffer::glyphs and count scalars to RunBuffer::pos before next call to SkTextBlobBuilder.

RunBuffer::utf8text and RunBuffer::clusters should be ignored.

Glyphs share metrics in font.

Glyphs are positioned on a baseline at y, using x-axis positions written by caller to RunBuffer::pos.

bounds defines an optional bounding box, used to suppress drawing when SkTextBlob bounds does not intersect SkSurface bounds. If bounds is nullptr, SkTextBlob bounds is computed from y, RunBuffer::pos, and RunBuffer::glyphs metrics.

Parameters
fontSkFont used for this run
countnumber of glyphs
yvertical offset within the blob
boundsoptional run bounding box
Returns
writable glyph buffer and x-axis position buffer

Definition at line 546 of file SkTextBlob.cpp.

548 {
549 this->allocInternal(font, SkTextBlob::kHorizontal_Positioning, count, 0, {0, y}, bounds);
550 return fCurrentRunBuffer;
551}
@ kHorizontal_Positioning
Definition: SkTextBlob.cpp:194

◆ allocRunRSXform()

const SkTextBlobBuilder::RunBuffer & SkTextBlobBuilder::allocRunRSXform ( const SkFont font,
int  count 
)

Definition at line 560 of file SkTextBlob.cpp.

560 {
561 this->allocInternal(font, SkTextBlob::kRSXform_Positioning, count, 0, {0, 0}, nullptr);
562 return fCurrentRunBuffer;
563}
@ kRSXform_Positioning
Definition: SkTextBlob.cpp:196

◆ allocRunText()

const SkTextBlobBuilder::RunBuffer & SkTextBlobBuilder::allocRunText ( const SkFont font,
int  count,
SkScalar  x,
SkScalar  y,
int  textByteCount,
const SkRect bounds = nullptr 
)

Returns run with storage for glyphs, text, and clusters. Caller must write count glyphs to RunBuffer::glyphs, textByteCount UTF-8 code units into RunBuffer::utf8text, and count monotonic indexes into utf8text into RunBuffer::clusters before next call to SkTextBlobBuilder.

RunBuffer::pos should be ignored.

Glyphs share metrics in font.

Glyphs are positioned on a baseline at (x, y), using font metrics to determine their relative placement.

bounds defines an optional bounding box, used to suppress drawing when SkTextBlob bounds does not intersect SkSurface bounds. If bounds is nullptr, SkTextBlob bounds is computed from (x, y) and RunBuffer::glyphs metrics.

Parameters
fontSkFont used for this run
countnumber of glyphs
xhorizontal offset within the blob
yvertical offset within the blob
textByteCountnumber of UTF-8 code units
boundsoptional run bounding box
Returns
writable glyph buffer, text buffer, and cluster buffer

Definition at line 565 of file SkTextBlob.cpp.

568 {
569 this->allocInternal(font,
571 count,
572 textByteCount,
573 SkPoint::Make(x, y),
574 bounds);
575 return fCurrentRunBuffer;
576}
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173

◆ allocRunTextPos()

const SkTextBlobBuilder::RunBuffer & SkTextBlobBuilder::allocRunTextPos ( const SkFont font,
int  count,
int  textByteCount,
const SkRect bounds = nullptr 
)

Returns run with storage for glyphs, SkPoint positions, text, and clusters. Caller must write count glyphs to RunBuffer::glyphs, count SkPoint to RunBuffer::pos, textByteCount UTF-8 code units into RunBuffer::utf8text, and count monotonic indexes into utf8text into RunBuffer::clusters before next call to SkTextBlobBuilder.

Glyphs share metrics in font.

Glyphs are positioned using SkPoint written by caller to RunBuffer::pos, using two scalar values for each SkPoint.

bounds defines an optional bounding box, used to suppress drawing when SkTextBlob bounds does not intersect SkSurface bounds. If bounds is nullptr, SkTextBlob bounds is computed from RunBuffer::pos, and RunBuffer::glyphs metrics.

Parameters
fontSkFont used for this run
countnumber of glyphs
textByteCountnumber of UTF-8 code units
boundsoptional run bounding box
Returns
writable glyph buffer, SkPoint buffer, text buffer, and cluster buffer

Definition at line 592 of file SkTextBlob.cpp.

595 {
596 this->allocInternal(font,
598 count, textByteCount,
599 SkPoint::Make(0, 0),
600 bounds);
601 return fCurrentRunBuffer;
602}

◆ allocRunTextPosH()

const SkTextBlobBuilder::RunBuffer & SkTextBlobBuilder::allocRunTextPosH ( const SkFont font,
int  count,
SkScalar  y,
int  textByteCount,
const SkRect bounds = nullptr 
)

Returns run with storage for glyphs, positions along baseline, text, and clusters. Caller must write count glyphs to RunBuffer::glyphs, count scalars to RunBuffer::pos, textByteCount UTF-8 code units into RunBuffer::utf8text, and count monotonic indexes into utf8text into RunBuffer::clusters before next call to SkTextBlobBuilder.

Glyphs share metrics in font.

Glyphs are positioned on a baseline at y, using x-axis positions written by caller to RunBuffer::pos.

bounds defines an optional bounding box, used to suppress drawing when SkTextBlob bounds does not intersect SkSurface bounds. If bounds is nullptr, SkTextBlob bounds is computed from y, RunBuffer::pos, and RunBuffer::glyphs metrics.

Parameters
fontSkFont used for this run
countnumber of glyphs
yvertical offset within the blob
textByteCountnumber of UTF-8 code units
boundsoptional run bounding box
Returns
writable glyph buffer, x-axis position buffer, text buffer, and cluster buffer

Definition at line 578 of file SkTextBlob.cpp.

582 {
583 this->allocInternal(font,
585 count,
586 textByteCount,
587 SkPoint::Make(0, y),
588 bounds);
589 return fCurrentRunBuffer;
590}

◆ allocRunTextRSXform()

const SkTextBlobBuilder::RunBuffer & SkTextBlobBuilder::allocRunTextRSXform ( const SkFont font,
int  count,
int  textByteCount,
const SkRect bounds = nullptr 
)

Definition at line 604 of file SkTextBlob.cpp.

607 {
608 this->allocInternal(font,
610 count,
611 textByteCount,
612 {0, 0},
613 bounds);
614 return fCurrentRunBuffer;
615}

◆ make()

sk_sp< SkTextBlob > SkTextBlobBuilder::make ( )

Returns SkTextBlob built from runs of glyphs added by builder. Returned SkTextBlob is immutable; it may be copied, but its contents may not be altered. Returns nullptr if no runs of glyphs were added by builder.

Resets SkTextBlobBuilder to its initial empty state, allowing it to be reused to build a new set of runs.

Returns
SkTextBlob or nullptr

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

Definition at line 617 of file SkTextBlob.cpp.

617 {
618 if (!fRunCount) {
619 // We don't instantiate empty blobs.
620 SkASSERT(!fStorage.get());
621 SkASSERT(fStorageUsed == 0);
622 SkASSERT(fStorageSize == 0);
623 SkASSERT(fLastRun == 0);
624 SkASSERT(fBounds.isEmpty());
625 return nullptr;
626 }
627
628 this->updateDeferredBounds();
629
630 // Tag the last run as such.
631 auto* lastRun = reinterpret_cast<SkTextBlob::RunRecord*>(fStorage.get() + fLastRun);
632 lastRun->fFlags |= SkTextBlob::RunRecord::kLast_Flag;
633
634 SkTextBlob* blob = new (fStorage.release()) SkTextBlob(fBounds);
635 SkDEBUGCODE(const_cast<SkTextBlob*>(blob)->fStorageSize = fStorageSize;)
636
638 SkSafeMath safe;
639 size_t validateSize = SkAlignPtr(sizeof(SkTextBlob));
640 for (const auto* run = SkTextBlob::RunRecord::First(blob); run;
641 run = SkTextBlob::RunRecord::Next(run)) {
642 validateSize += SkTextBlob::RunRecord::StorageSize(
643 run->fCount, run->textSize(), run->positioning(), &safe);
644 run->validate(reinterpret_cast<const uint8_t*>(blob) + fStorageUsed);
645 fRunCount--;
646 }
647 SkASSERT(validateSize == fStorageUsed);
648 SkASSERT(fRunCount == 0);
649 SkASSERT(safe);
650 )
651
652 fStorageUsed = 0;
653 fStorageSize = 0;
654 fRunCount = 0;
655 fLastRun = 0;
656 fBounds.setEmpty();
657
658 return sk_sp<SkTextBlob>(blob);
659}
static constexpr T SkAlignPtr(T x)
Definition: SkAlign.h:23
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
Definition: run.py:1
def run(cmd)
Definition: run.py:14
bool isEmpty() const
Definition: SkRect.h:693

Friends And Related Function Documentation

◆ SkTextBlobBuilderPriv

friend class SkTextBlobBuilderPriv
friend

Definition at line 505 of file SkTextBlob.h.

◆ SkTextBlobPriv

friend class SkTextBlobPriv
friend

Definition at line 504 of file SkTextBlob.h.


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