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

#include <SkClusterator.h>

Classes

struct  Cluster
 

Public Member Functions

 SkClusterator (const sktext::GlyphRun &run)
 
uint32_t glyphCount () const
 
bool reversedChars () const
 
Cluster next ()
 

Detailed Description

Given the m-to-n glyph-to-character mapping data (as returned by harfbuzz), iterate over the clusters.

Definition at line 18 of file SkClusterator.h.

Constructor & Destructor Documentation

◆ SkClusterator()

SkClusterator::SkClusterator ( const sktext::GlyphRun run)

Definition at line 29 of file SkClusterator.cpp.

30 : fClusters(run.clusters().data())
31 , fUtf8Text(run.text().data())
32 , fGlyphCount(SkToU32(run.glyphsIDs().size()))
33 , fTextByteLength(SkToU32(run.text().size()))
34 , fReversedChars(fClusters ? is_reversed(fClusters, fGlyphCount) : false)
35{
36 if (fClusters) {
37 SkASSERT(fUtf8Text && fTextByteLength > 0 && fGlyphCount > 0);
38 } else {
39 SkASSERT(!fUtf8Text && fTextByteLength == 0);
40 }
41}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool is_reversed(const uint32_t *clusters, uint32_t count)
constexpr uint32_t SkToU32(S x)
Definition: SkTo.h:26
Definition: run.py:1

Member Function Documentation

◆ glyphCount()

uint32_t SkClusterator::glyphCount ( ) const
inline

Definition at line 21 of file SkClusterator.h.

21{ return fGlyphCount; }

◆ next()

SkClusterator::Cluster SkClusterator::next ( )

Definition at line 43 of file SkClusterator.cpp.

43 {
44 if (fCurrentGlyphIndex >= fGlyphCount) {
45 return Cluster{nullptr, 0, 0, 0};
46 }
47 if (!fClusters || !fUtf8Text) {
48 return Cluster{nullptr, 0, fCurrentGlyphIndex++, 1};
49 }
50 uint32_t clusterGlyphIndex = fCurrentGlyphIndex;
51 uint32_t cluster = fClusters[clusterGlyphIndex];
52 do {
53 ++fCurrentGlyphIndex;
54 } while (fCurrentGlyphIndex < fGlyphCount && cluster == fClusters[fCurrentGlyphIndex]);
55 uint32_t clusterGlyphCount = fCurrentGlyphIndex - clusterGlyphIndex;
56 uint32_t clusterEnd = fTextByteLength;
57 for (unsigned i = 0; i < fGlyphCount; ++i) {
58 uint32_t c = fClusters[i];
59 if (c > cluster && c < clusterEnd) {
60 clusterEnd = c;
61 }
62 }
63 uint32_t clusterLen = clusterEnd - cluster;
64 return Cluster{fUtf8Text + cluster, clusterLen, clusterGlyphIndex, clusterGlyphCount};
65}

◆ reversedChars()

bool SkClusterator::reversedChars ( ) const
inline

Definition at line 22 of file SkClusterator.h.

22{ return fReversedChars; }

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