/src/skia/modules/skparagraph/src/Iterators.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2019 Google LLC. |
2 | | #ifndef FontIterator_DEFINED |
3 | | #define FontIterator_DEFINED |
4 | | |
5 | | #include "include/core/SkSpan.h" |
6 | | #include "include/core/SkString.h" |
7 | | #include "include/core/SkTypes.h" |
8 | | #include "modules/skparagraph/include/TextStyle.h" |
9 | | #include "modules/skshaper/include/SkShaper.h" |
10 | | |
11 | | namespace skia { |
12 | | namespace textlayout { |
13 | | |
14 | | class LangIterator final : public SkShaper::LanguageRunIterator { |
15 | | public: |
16 | | LangIterator(SkSpan<const char> utf8, SkSpan<Block> styles, const TextStyle& defaultStyle) |
17 | | : fText(utf8) |
18 | | , fTextStyles(styles) |
19 | | , fCurrentChar(utf8.begin()) |
20 | | , fCurrentStyle(fTextStyles.begin()) |
21 | 0 | , fCurrentLocale(defaultStyle.getLocale()) {} |
22 | | |
23 | 0 | void consume() override { |
24 | 0 | SkASSERT(fCurrentChar < fText.end()); |
25 | |
|
26 | 0 | if (fCurrentStyle == fTextStyles.end()) { |
27 | 0 | fCurrentChar = fText.end(); |
28 | 0 | return; |
29 | 0 | } |
30 | | |
31 | 0 | fCurrentChar = fText.begin() + fCurrentStyle->fRange.end; |
32 | 0 | fCurrentLocale = fCurrentStyle->fStyle.getLocale(); |
33 | 0 | while (++fCurrentStyle != fTextStyles.end() && !fCurrentStyle->fStyle.isPlaceholder()) { |
34 | 0 | if (fCurrentStyle->fStyle.getLocale() != fCurrentLocale) { |
35 | 0 | break; |
36 | 0 | } |
37 | 0 | fCurrentChar = fText.begin() + fCurrentStyle->fRange.end; |
38 | 0 | } |
39 | 0 | } |
40 | | |
41 | 0 | size_t endOfCurrentRun() const override { return fCurrentChar - fText.begin(); } |
42 | 0 | bool atEnd() const override { return fCurrentChar >= fText.end(); } |
43 | 0 | const char* currentLanguage() const override { return fCurrentLocale.c_str(); } |
44 | | |
45 | | private: |
46 | | SkSpan<const char> fText; |
47 | | SkSpan<Block> fTextStyles; |
48 | | const char* fCurrentChar; |
49 | | Block* fCurrentStyle; |
50 | | SkString fCurrentLocale; |
51 | | }; |
52 | | } // namespace textlayout |
53 | | } // namespace skia |
54 | | |
55 | | #endif // FontIterator_DEFINED |