Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
skia::textlayout::Cluster Class Reference

#include <Run.h>

Public Types

enum  BreakType { None , GraphemeBreak , SoftLineBreak , HardLineBreak }
 

Public Member Functions

 Cluster ()
 
 Cluster (ParagraphImpl *owner, RunIndex runIndex, size_t start, size_t end, SkSpan< const char > text, SkScalar width, SkScalar height)
 
 Cluster (TextRange textRange)
 
 Cluster (const Cluster &)=default
 
 ~Cluster ()=default
 
SkScalar sizeToChar (TextIndex ch) const
 
SkScalar sizeFromChar (TextIndex ch) const
 
size_t roundPos (SkScalar s) const
 
void space (SkScalar shift)
 
ParagraphImplgetOwner () const
 
void setOwner (ParagraphImpl *owner)
 
bool isWhitespaceBreak () const
 
bool isIntraWordBreak () const
 
bool isHardBreak () const
 
bool isIdeographic () const
 
bool isSoftBreak () const
 
bool isGraphemeBreak () const
 
bool canBreakLineAfter () const
 
size_t startPos () const
 
size_t endPos () const
 
SkScalar width () const
 
SkScalar height () const
 
size_t size () const
 
void setHalfLetterSpacing (SkScalar halfLetterSpacing)
 
SkScalar getHalfLetterSpacing () const
 
TextRange textRange () const
 
RunIndex runIndex () const
 
ParagraphImplowner () const
 
RunrunOrNull () const
 
Runrun () const
 
SkFont font () const
 
SkScalar trimmedWidth (size_t pos) const
 
bool contains (TextIndex ch) const
 
bool belongs (TextRange text) const
 
bool startsIn (TextRange text) const
 

Detailed Description

Definition at line 263 of file Run.h.

Member Enumeration Documentation

◆ BreakType

Enumerator
None 
GraphemeBreak 
SoftLineBreak 
HardLineBreak 

Definition at line 265 of file Run.h.

265 {
266 None,
267 GraphemeBreak, // calculated for all clusters (UBRK_CHARACTER)
268 SoftLineBreak, // calculated for all clusters (UBRK_LINE & UBRK_CHARACTER)
269 HardLineBreak, // calculated for all clusters (UBRK_LINE)
270 };

Constructor & Destructor Documentation

◆ Cluster() [1/4]

skia::textlayout::Cluster::Cluster ( )
inline

Definition at line 272 of file Run.h.

273 : fOwner(nullptr)
274 , fRunIndex(EMPTY_RUN)
275 , fTextRange(EMPTY_TEXT)
276 , fGraphemeRange(EMPTY_RANGE)
277 , fStart(0)
278 , fEnd()
279 , fWidth()
280 , fHeight()
281 , fHalfLetterSpacing(0.0) {}
const SkRange< size_t > EMPTY_TEXT
Definition TextStyle.h:338
const SkRange< size_t > EMPTY_RANGE
Definition DartTypes.h:128
const size_t EMPTY_RUN
Definition Run.h:33

◆ Cluster() [2/4]

skia::textlayout::Cluster::Cluster ( ParagraphImpl owner,
RunIndex  runIndex,
size_t  start,
size_t  end,
SkSpan< const char >  text,
SkScalar  width,
SkScalar  height 
)

Definition at line 337 of file ParagraphImpl.cpp.

344 : fOwner(owner)
345 , fRunIndex(runIndex)
346 , fTextRange(text.begin() - fOwner->text().begin(), text.end() - fOwner->text().begin())
347 , fGraphemeRange(EMPTY_RANGE)
348 , fStart(start)
349 , fEnd(end)
350 , fWidth(width)
351 , fHeight(height)
352 , fHalfLetterSpacing(0.0)
353 , fIsIdeographic(false) {
354 size_t whiteSpacesBreakLen = 0;
355 size_t intraWordBreakLen = 0;
356
357 const char* ch = text.begin();
358 if (text.end() - ch == 1 && *(const unsigned char*)ch <= 0x7F) {
359 // I am not even sure it's worth it if we do not save a unicode call
360 if (is_ascii_7bit_space(*ch)) {
361 ++whiteSpacesBreakLen;
362 }
363 } else {
364 for (auto i = fTextRange.start; i < fTextRange.end; ++i) {
366 ++whiteSpacesBreakLen;
367 }
369 ++intraWordBreakLen;
370 }
372 fIsIdeographic = true;
373 }
374 }
375 }
376
377 fIsWhiteSpaceBreak = whiteSpacesBreakLen == fTextRange.width();
378 fIsIntraWordBreak = intraWordBreakLen == fTextRange.width();
379 fIsHardBreak = fOwner->codeUnitHasProperty(fTextRange.end,
381}
constexpr T * begin() const
Definition SkSpan_impl.h:90
@ kPartOfWhiteSpaceBreak
Definition SkUnicode.h:81
@ kHardLineBreakBefore
Definition SkUnicode.h:84
@ kIdeographic
Definition SkUnicode.h:89
@ kPartOfIntraWordBreak
Definition SkUnicode.h:85
ParagraphImpl * owner() const
Definition Run.h:328
RunIndex runIndex() const
Definition Run.h:327
SkScalar width() const
Definition Run.h:318
SkScalar height() const
Definition Run.h:319
bool codeUnitHasProperty(size_t index, SkUnicode::CodeUnitFlags property) const
SkSpan< const char > text() const
glong glong end
std::u16string text
static bool is_ascii_7bit_space(int c)

◆ Cluster() [3/4]

skia::textlayout::Cluster::Cluster ( TextRange  textRange)
inline

Definition at line 291 of file Run.h.

291: fTextRange(textRange), fGraphemeRange(EMPTY_RANGE) { }
TextRange textRange() const
Definition Run.h:325

◆ Cluster() [4/4]

skia::textlayout::Cluster::Cluster ( const Cluster )
default

◆ ~Cluster()

skia::textlayout::Cluster::~Cluster ( )
default

Member Function Documentation

◆ belongs()

bool skia::textlayout::Cluster::belongs ( TextRange  text) const
inline

Definition at line 338 of file Run.h.

338 {
339 return fTextRange.start >= text.start && fTextRange.end <= text.end;
340 }

◆ canBreakLineAfter()

bool skia::textlayout::Cluster::canBreakLineAfter ( ) const
inline

Definition at line 315 of file Run.h.

315{ return isHardBreak() || isSoftBreak(); }
bool isSoftBreak() const
Definition Run.cpp:346
bool isHardBreak() const
Definition Run.h:310

◆ contains()

bool skia::textlayout::Cluster::contains ( TextIndex  ch) const
inline

Definition at line 336 of file Run.h.

336{ return ch >= fTextRange.start && ch < fTextRange.end; }

◆ endPos()

size_t skia::textlayout::Cluster::endPos ( ) const
inline

Definition at line 317 of file Run.h.

317{ return fEnd; }

◆ font()

SkFont skia::textlayout::Cluster::font ( ) const

Definition at line 341 of file Run.cpp.

341 {
342 SkASSERT(fRunIndex < fOwner->runs().size());
343 return fOwner->run(fRunIndex).font();
344}
#define SkASSERT(cond)
Definition SkAssert.h:116
size_t size() const
Definition Run.h:320
Run & run(RunIndex runIndex)
const SkFont & font() const
Definition Run.h:95

◆ getHalfLetterSpacing()

SkScalar skia::textlayout::Cluster::getHalfLetterSpacing ( ) const
inline

Definition at line 323 of file Run.h.

323{ return fHalfLetterSpacing; }

◆ getOwner()

ParagraphImpl * skia::textlayout::Cluster::getOwner ( ) const
inline

Definition at line 305 of file Run.h.

305{ return fOwner; }

◆ height()

SkScalar skia::textlayout::Cluster::height ( ) const
inline

Definition at line 319 of file Run.h.

319{ return fHeight; }

◆ isGraphemeBreak()

bool skia::textlayout::Cluster::isGraphemeBreak ( ) const

Definition at line 351 of file Run.cpp.

351 {
353}
@ kGraphemeStart
Definition SkUnicode.h:82

◆ isHardBreak()

bool skia::textlayout::Cluster::isHardBreak ( ) const
inline

Definition at line 310 of file Run.h.

310{ return fIsHardBreak; }

◆ isIdeographic()

bool skia::textlayout::Cluster::isIdeographic ( ) const
inline

Definition at line 311 of file Run.h.

311{ return fIsIdeographic; }

◆ isIntraWordBreak()

bool skia::textlayout::Cluster::isIntraWordBreak ( ) const
inline

Definition at line 309 of file Run.h.

309{ return fIsIntraWordBreak; }

◆ isSoftBreak()

bool skia::textlayout::Cluster::isSoftBreak ( ) const

Definition at line 346 of file Run.cpp.

346 {
347 return fOwner->codeUnitHasProperty(fTextRange.end,
349}
@ kSoftLineBreakBefore
Definition SkUnicode.h:83

◆ isWhitespaceBreak()

bool skia::textlayout::Cluster::isWhitespaceBreak ( ) const
inline

Definition at line 308 of file Run.h.

308{ return fIsWhiteSpaceBreak; }

◆ owner()

ParagraphImpl * skia::textlayout::Cluster::owner ( ) const
inline

Definition at line 328 of file Run.h.

328{ return fOwner; }

◆ roundPos()

size_t skia::textlayout::Cluster::roundPos ( SkScalar  s) const

Definition at line 296 of file Run.cpp.

296 {
297 auto ratio = (s * 1.0) / fWidth;
298 return sk_double_floor2int(ratio * size());
299}
#define sk_double_floor2int(x)
struct MyStruct s

◆ run()

Run & skia::textlayout::Cluster::run ( ) const

Definition at line 336 of file Run.cpp.

336 {
337 SkASSERT(fRunIndex < fOwner->runs().size());
338 return fOwner->run(fRunIndex);
339}

◆ runIndex()

RunIndex skia::textlayout::Cluster::runIndex ( ) const
inline

Definition at line 327 of file Run.h.

327{ return fRunIndex; }

◆ runOrNull()

Run * skia::textlayout::Cluster::runOrNull ( ) const

Definition at line 329 of file Run.cpp.

329 {
330 if (fRunIndex >= fOwner->runs().size()) {
331 return nullptr;
332 }
333 return &fOwner->run(fRunIndex);
334}

◆ setHalfLetterSpacing()

void skia::textlayout::Cluster::setHalfLetterSpacing ( SkScalar  halfLetterSpacing)
inline

Definition at line 322 of file Run.h.

322{ fHalfLetterSpacing = halfLetterSpacing; }

◆ setOwner()

void skia::textlayout::Cluster::setOwner ( ParagraphImpl owner)
inline

Definition at line 306 of file Run.h.

306{ fOwner = owner; }

◆ size()

size_t skia::textlayout::Cluster::size ( ) const
inline

Definition at line 320 of file Run.h.

320{ return fEnd - fStart; }

◆ sizeFromChar()

SkScalar skia::textlayout::Cluster::sizeFromChar ( TextIndex  ch) const

Definition at line 286 of file Run.cpp.

286 {
287 if (ch < fTextRange.start || ch >= fTextRange.end) {
288 return 0;
289 }
290 auto shift = fTextRange.end - ch - 1;
291 auto ratio = shift * 1.0 / fTextRange.width();
292
293 return SkDoubleToScalar(fWidth * ratio);
294}
#define SkDoubleToScalar(x)
Definition SkScalar.h:64

◆ sizeToChar()

SkScalar skia::textlayout::Cluster::sizeToChar ( TextIndex  ch) const

Definition at line 276 of file Run.cpp.

276 {
277 if (ch < fTextRange.start || ch >= fTextRange.end) {
278 return 0;
279 }
280 auto shift = ch - fTextRange.start;
281 auto ratio = shift * 1.0 / fTextRange.width();
282
283 return SkDoubleToScalar(fWidth * ratio);
284}

◆ space()

void skia::textlayout::Cluster::space ( SkScalar  shift)
inline

Definition at line 301 of file Run.h.

301 {
302 fWidth += shift;
303 }

◆ startPos()

size_t skia::textlayout::Cluster::startPos ( ) const
inline

Definition at line 316 of file Run.h.

316{ return fStart; }

◆ startsIn()

bool skia::textlayout::Cluster::startsIn ( TextRange  text) const
inline

Definition at line 342 of file Run.h.

342 {
343 return fTextRange.start >= text.start && fTextRange.start < text.end;
344 }

◆ textRange()

TextRange skia::textlayout::Cluster::textRange ( ) const
inline

Definition at line 325 of file Run.h.

325{ return fTextRange; }

◆ trimmedWidth()

SkScalar skia::textlayout::Cluster::trimmedWidth ( size_t  pos) const

Definition at line 301 of file Run.cpp.

301 {
302 // Find the width until the pos and return the min between trimmedWidth and the width(pos)
303 // We don't have to take in account cluster shift since it's the same for 0 and for pos
304 auto& run = fOwner->run(fRunIndex);
305 return std::min(run.positionX(pos) - run.positionX(fStart), fWidth);
306}
SkPoint pos
Definition run.py:1

◆ width()

SkScalar skia::textlayout::Cluster::width ( ) const
inline

Definition at line 318 of file Run.h.

318{ return fWidth; }

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