1 /* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 #ifndef SkClusterator_DEFINED 8 #define SkClusterator_DEFINED 9 10 #include <cstdint> 11 #include <vector> 12 13 namespace sktext { 14 class GlyphRun; 15 } 16 17 /** Given the m-to-n glyph-to-character mapping data (as returned by 18 harfbuzz), iterate over the clusters. */ 19 class SkClusterator { 20 public: 21 SkClusterator(const sktext::GlyphRun& run); glyphCount()22 uint32_t glyphCount() const { return fGlyphCount; } reversedChars()23 bool reversedChars() const { return fReversedChars; } 24 struct Cluster { 25 const char* fUtf8Text; 26 uint32_t fTextByteLength; 27 uint32_t fGlyphIndex; 28 uint32_t fGlyphCount; 29 explicit operator bool() const { return fGlyphCount != 0; } 30 bool operator==(const SkClusterator::Cluster& o) { 31 return fUtf8Text == o.fUtf8Text 32 && fTextByteLength == o.fTextByteLength 33 && fGlyphIndex == o.fGlyphIndex 34 && fGlyphCount == o.fGlyphCount; 35 } 36 }; 37 Cluster next(); 38 39 private: 40 uint32_t const * const fClusters; 41 char const * const fUtf8Text; 42 uint32_t const fGlyphCount; 43 uint32_t const fTextByteLength; 44 bool const fReversedChars; 45 uint32_t fCurrentGlyphIndex = 0; 46 }; 47 #endif // SkClusterator_DEFINED 48