Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Iterators.h
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
2#ifndef FontIterator_DEFINED
3#define FontIterator_DEFINED
4
10
11namespace skia {
12namespace textlayout {
13
15public:
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 , fCurrentLocale(defaultStyle.getLocale()) {}
22
23 void consume() override {
24 SkASSERT(fCurrentChar < fText.end());
25
26 if (fCurrentStyle == fTextStyles.end()) {
27 fCurrentChar = fText.end();
28 return;
29 }
30
31 fCurrentChar = fText.begin() + fCurrentStyle->fRange.end;
32 fCurrentLocale = fCurrentStyle->fStyle.getLocale();
33 while (++fCurrentStyle != fTextStyles.end() && !fCurrentStyle->fStyle.isPlaceholder()) {
34 if (fCurrentStyle->fStyle.getLocale() != fCurrentLocale) {
35 break;
36 }
37 fCurrentChar = fText.begin() + fCurrentStyle->fRange.end;
38 }
39 }
40
41 size_t endOfCurrentRun() const override { return fCurrentChar - fText.begin(); }
42 bool atEnd() const override { return fCurrentChar >= fText.end(); }
43 const char* currentLanguage() const override { return fCurrentLocale.c_str(); }
44
45private:
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
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr T * begin() const
Definition SkSpan_impl.h:90
constexpr T * end() const
Definition SkSpan_impl.h:91
const char * c_str() const
Definition SkString.h:133
const char * currentLanguage() const override
Definition Iterators.h:43
size_t endOfCurrentRun() const override
Definition Iterators.h:41
LangIterator(SkSpan< const char > utf8, SkSpan< Block > styles, const TextStyle &defaultStyle)
Definition Iterators.h:16
bool atEnd() const override
Definition Iterators.h:42
SkString getLocale() const
Definition TextStyle.h:279
static const char * begin(const StringSlice &s)
Definition editor.cpp:252