blob: 40d9994ba3f179dee8d7799d30082bf6d49bc553 [file] [log] [blame]
Hal Canary1521c8a2018-03-28 09:51:00 -07001/*
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 Canary98caedd2018-07-23 10:50:49 -040011#include <cstdint>
Hal Canary1521c8a2018-03-28 09:51:00 -070012
Hal Canary98caedd2018-07-23 10:50:49 -040013class SkGlyphRun;
Hal Canary1521c8a2018-03-28 09:51:00 -070014
15/** Given the m-to-n glyph-to-character mapping data (as returned by
16 harfbuzz), iterate over the clusters. */
17class SkClusterator {
18public:
Hal Canary98caedd2018-07-23 10:50:49 -040019 SkClusterator(const SkGlyphRun& run);
Hal Canary1521c8a2018-03-28 09:51:00 -070020 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 Canarye9e19dd2018-04-02 11:36:39 -040028 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 Canary1521c8a2018-03-28 09:51:00 -070034 };
35 Cluster next();
36
37private:
Hal Canary1521c8a2018-03-28 09:51:00 -070038 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