Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
FontMgrRunIterator Class Referencefinal
Inheritance diagram for FontMgrRunIterator:
SkShaper::FontRunIterator SkShaper::RunIterator

Public Member Functions

 FontMgrRunIterator (const char *utf8, size_t utf8Bytes, const SkFont &font, sk_sp< SkFontMgr > fallbackMgr, const char *requestName, SkFontStyle requestStyle, const SkShaper::LanguageRunIterator *lang)
 
 FontMgrRunIterator (const char *utf8, size_t utf8Bytes, const SkFont &font, sk_sp< SkFontMgr > fallbackMgr)
 
void consume () override
 
size_t endOfCurrentRun () const override
 
bool atEnd () const override
 
const SkFontcurrentFont () const override
 
- Public Member Functions inherited from SkShaper::RunIterator
virtual ~RunIterator ()=default
 

Detailed Description

Definition at line 89 of file SkShaper.cpp.

Constructor & Destructor Documentation

◆ FontMgrRunIterator() [1/2]

FontMgrRunIterator::FontMgrRunIterator ( const char *  utf8,
size_t  utf8Bytes,
const SkFont font,
sk_sp< SkFontMgr fallbackMgr,
const char *  requestName,
SkFontStyle  requestStyle,
const SkShaper::LanguageRunIterator lang 
)
inline

Definition at line 91 of file SkShaper.cpp.

95 : fCurrent(utf8), fBegin(utf8), fEnd(fCurrent + utf8Bytes)
96 , fFallbackMgr(std::move(fallbackMgr))
97 , fFont(font)
98 , fFallbackFont(fFont)
99 , fCurrentFont(nullptr)
100 , fRequestName(requestName)
101 , fRequestStyle(requestStyle)
102 , fLanguage(lang)
103 {
104 // If fallback is not wanted, clients should use TrivialFontRunIterator.
105 SkASSERT(fFallbackMgr);
106 fFont.setTypeface(font.refTypeface());
107 fFallbackFont.setTypeface(nullptr);
108 }
#define SkASSERT(cond)
Definition SkAssert.h:116
void setTypeface(sk_sp< SkTypeface > tf)
Definition SkFont.cpp:90
font
Font Metadata and Metrics.

◆ FontMgrRunIterator() [2/2]

FontMgrRunIterator::FontMgrRunIterator ( const char *  utf8,
size_t  utf8Bytes,
const SkFont font,
sk_sp< SkFontMgr fallbackMgr 
)
inline

Definition at line 109 of file SkShaper.cpp.

111 : FontMgrRunIterator(utf8, utf8Bytes, font, std::move(fallbackMgr),
112 nullptr, font.getTypeface()->fontStyle(), nullptr)
113 {}

Member Function Documentation

◆ atEnd()

bool FontMgrRunIterator::atEnd ( ) const
inlineoverridevirtual

Return true if consume should no longer be called.

Implements SkShaper::RunIterator.

Definition at line 165 of file SkShaper.cpp.

165 {
166 return fCurrent == fEnd;
167 }

◆ consume()

void FontMgrRunIterator::consume ( )
inlineoverridevirtual

Set state to that of current run and move iterator to end of that run.

Implements SkShaper::RunIterator.

Definition at line 115 of file SkShaper.cpp.

115 {
116 SkASSERT(fCurrent < fEnd);
117 SkASSERT(!fLanguage || this->endOfCurrentRun() <= fLanguage->endOfCurrentRun());
118 SkUnichar u = utf8_next(&fCurrent, fEnd);
119 // If the starting typeface can handle this character, use it.
120 if (fFont.unicharToGlyph(u)) {
121 fCurrentFont = &fFont;
122 // If the current fallback can handle this character, use it.
123 } else if (fFallbackFont.getTypeface() && fFallbackFont.unicharToGlyph(u)) {
124 fCurrentFont = &fFallbackFont;
125 // If not, try to find a fallback typeface
126 } else {
127 const char* language = fLanguage ? fLanguage->currentLanguage() : nullptr;
128 int languageCount = fLanguage ? 1 : 0;
129 sk_sp<SkTypeface> candidate(fFallbackMgr->matchFamilyStyleCharacter(
130 fRequestName, fRequestStyle, &language, languageCount, u));
131 if (candidate) {
132 fFallbackFont.setTypeface(std::move(candidate));
133 fCurrentFont = &fFallbackFont;
134 } else {
135 fCurrentFont = &fFont;
136 }
137 }
138
139 while (fCurrent < fEnd) {
140 const char* prev = fCurrent;
141 u = utf8_next(&fCurrent, fEnd);
142
143 // End run if not using initial typeface and initial typeface has this character.
144 if (fCurrentFont->getTypeface() != fFont.getTypeface() && fFont.unicharToGlyph(u)) {
145 fCurrent = prev;
146 return;
147 }
148
149 // End run if current typeface does not have this character and some other font does.
150 if (!fCurrentFont->unicharToGlyph(u)) {
151 const char* language = fLanguage ? fLanguage->currentLanguage() : nullptr;
152 int languageCount = fLanguage ? 1 : 0;
153 sk_sp<SkTypeface> candidate(fFallbackMgr->matchFamilyStyleCharacter(
154 fRequestName, fRequestStyle, &language, languageCount, u));
155 if (candidate) {
156 fCurrent = prev;
157 return;
158 }
159 }
160 }
161 }
static float prev(float f)
static SkUnichar utf8_next(const char **ptr, const char *end)
Definition SkShaper.cpp:84
int32_t SkUnichar
Definition SkTypes.h:175
size_t endOfCurrentRun() const override
Definition SkShaper.cpp:162
sk_sp< SkTypeface > matchFamilyStyleCharacter(const char familyName[], const SkFontStyle &, const char *bcp47[], int bcp47Count, SkUnichar character) const
SkTypeface * getTypeface() const
Definition SkFont.h:208
SkGlyphID unicharToGlyph(SkUnichar uni) const
Definition SkFont.cpp:173
virtual const char * currentLanguage() const =0
virtual size_t endOfCurrentRun() const =0

◆ currentFont()

const SkFont & FontMgrRunIterator::currentFont ( ) const
inlineoverridevirtual

Implements SkShaper::FontRunIterator.

Definition at line 169 of file SkShaper.cpp.

169 {
170 return *fCurrentFont;
171 }

◆ endOfCurrentRun()

size_t FontMgrRunIterator::endOfCurrentRun ( ) const
inlineoverridevirtual

Offset to one past the last (utf8) element in the current run.

Implements SkShaper::RunIterator.

Definition at line 162 of file SkShaper.cpp.

162 {
163 return fCurrent - fBegin;
164 }

The documentation for this class was generated from the following file: