Hal Canary | 1521c8a | 2018-03-28 09:51:00 -0700 | [diff] [blame] | 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> |
Hal Canary | 98caedd | 2018-07-23 10:50:49 -0400 | [diff] [blame] | 11 | #include <cstdint> |
Hal Canary | 1521c8a | 2018-03-28 09:51:00 -0700 | [diff] [blame] | 12 | |
Hal Canary | 98caedd | 2018-07-23 10:50:49 -0400 | [diff] [blame] | 13 | class SkGlyphRun; |
Hal Canary | 1521c8a | 2018-03-28 09:51:00 -0700 | [diff] [blame] | 14 | |
| 15 | /** Given the m-to-n glyph-to-character mapping data (as returned by |
| 16 | harfbuzz), iterate over the clusters. */ |
| 17 | class SkClusterator { |
| 18 | public: |
Hal Canary | 98caedd | 2018-07-23 10:50:49 -0400 | [diff] [blame] | 19 | SkClusterator(const SkGlyphRun& run); |
Hal Canary | 1521c8a | 2018-03-28 09:51:00 -0700 | [diff] [blame] | 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; } |
Hal Canary | e9e19dd | 2018-04-02 11:36:39 -0400 | [diff] [blame] | 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 | } |
Hal Canary | 1521c8a | 2018-03-28 09:51:00 -0700 | [diff] [blame] | 34 | }; |
| 35 | Cluster next(); |
| 36 | |
| 37 | private: |
Hal Canary | 1521c8a | 2018-03-28 09:51:00 -0700 | [diff] [blame] | 38 | const uint32_t* fClusters; |
| 39 | const char* fUtf8Text; |
| 40 | uint32_t fGlyphCount; |
| 41 | uint32_t fTextByteLength; |
| 42 | uint32_t fCurrentGlyphIndex = 0; |
| 43 | bool fReversedChars = false; |
| 44 | }; |
| 45 | |
| 46 | |
| 47 | #endif // SkClusterator_DEFINED |