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 <vector>
11#include <cstdint>
12
13class SkGlyphRun;
14
15/** Given the m-to-n glyph-to-character mapping data (as returned by
16 harfbuzz), iterate over the clusters. */
17class SkClusterator {
18public:
19 SkClusterator(const SkGlyphRun& run);
20 uint32_t glyphCount() const { return fGlyphCount; }
21 bool reversedChars() const { return fReversedChars; }
22 struct Cluster {
23 const char* fUtf8Text;
24 uint32_t fTextByteLength;
25 uint32_t fGlyphIndex;
26 uint32_t fGlyphCount;
27 explicit operator bool() const { return fGlyphCount != 0; }
28 bool operator==(const SkClusterator::Cluster& o) {
29 return fUtf8Text == o.fUtf8Text
30 && fTextByteLength == o.fTextByteLength
31 && fGlyphIndex == o.fGlyphIndex
32 && fGlyphCount == o.fGlyphCount;
33 }
34 };
35 Cluster next();
36
37private:
38 uint32_t const * const fClusters;
39 char const * const fUtf8Text;
40 uint32_t const fGlyphCount;
41 uint32_t const fTextByteLength;
42 bool const fReversedChars;
43 uint32_t fCurrentGlyphIndex = 0;
44};
45
46
47#endif // SkClusterator_DEFINED
48