Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 19 of file SkClusterator.h.

Constructor & Destructor Documentation

◆ SkClusterator()

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

Definition at line 28 of file SkClusterator.cpp.

29 : fClusters(run.clusters().data())
30 , fUtf8Text(run.text().data())
31 , fGlyphCount(SkToU32(run.glyphsIDs().size()))
32 , fTextByteLength(SkToU32(run.text().size()))
33 , fReversedChars(fClusters ? is_reversed(fClusters, fGlyphCount) : false)
34{
35 if (fClusters) {
36 SkASSERT(fUtf8Text && fTextByteLength > 0 && fGlyphCount > 0);
37 } else {
38 SkASSERT(!fUtf8Text && fTextByteLength == 0);
39 }
40}
#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 22 of file SkClusterator.h.

22{ return fGlyphCount; }

◆ next()

SkClusterator::Cluster SkClusterator::next ( )

Definition at line 42 of file SkClusterator.cpp.

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

◆ reversedChars()

bool SkClusterator::reversedChars ( ) const
inline

Definition at line 23 of file SkClusterator.h.

23{ return fReversedChars; }

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