Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
SkFontStyleSet Class Referenceabstract

#include <SkFontMgr.h>

Inheritance diagram for SkFontStyleSet:
SkRefCnt SkRefCntBase OneFontStyleSet SkEmptyFontStyleSet SkFontStyleSet_Custom SkFontStyleSet_FCI SkFontStyleSet_Fuchsia flutter::AssetManagerFontStyleSet skia::textlayout::TypefaceFontStyleSet txt::TypefaceFontStyleSet

Public Member Functions

virtual int count ()=0
 
virtual void getStyle (int index, SkFontStyle *, SkString *style)=0
 
virtual sk_sp< SkTypefacecreateTypeface (int index)=0
 
virtual sk_sp< SkTypefacematchStyle (const SkFontStyle &pattern)=0
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< SkFontStyleSetCreateEmpty ()
 

Protected Member Functions

sk_sp< SkTypefacematchStyleCSS3 (const SkFontStyle &pattern)
 

Detailed Description

Definition at line 23 of file SkFontMgr.h.

Member Function Documentation

◆ count()

virtual int SkFontStyleSet::count ( )
pure virtual

◆ CreateEmpty()

sk_sp< SkFontStyleSet > SkFontStyleSet::CreateEmpty ( )
static

◆ createTypeface()

virtual sk_sp< SkTypeface > SkFontStyleSet::createTypeface ( int  index)
pure virtual

◆ getStyle()

virtual void SkFontStyleSet::getStyle ( int  index,
SkFontStyle ,
SkString style 
)
pure virtual

◆ matchStyle()

virtual sk_sp< SkTypeface > SkFontStyleSet::matchStyle ( const SkFontStyle pattern)
pure virtual

◆ matchStyleCSS3()

sk_sp< SkTypeface > SkFontStyleSet::matchStyleCSS3 ( const SkFontStyle pattern)
protected

Width has the greatest priority. If the value of pattern.width is 5 (normal) or less, narrower width values are checked first, then wider values. If the value of pattern.width is greater than 5 (normal), wider values are checked first, followed by narrower values.

Italic/Oblique has the next highest priority. If italic requested and there is some italic font, use it. If oblique requested and there is some oblique font, use it. If italic requested and there is some oblique font, use it. If oblique requested and there is some italic font, use it.

Exact match. If pattern.weight < 400, weights below pattern.weight are checked in descending order followed by weights above pattern.weight in ascending order until a match is found. If pattern.weight > 500, weights above pattern.weight are checked in ascending order followed by weights below pattern.weight in descending order until a match is found. If pattern.weight is 400, 500 is checked first and then the rule for pattern.weight < 400 is used. If pattern.weight is 500, 400 is checked first and then the rule for pattern.weight < 400 is used.

Definition at line 184 of file SkFontMgr.cpp.

184 {
185 int count = this->count();
186 if (0 == count) {
187 return nullptr;
188 }
189
190 struct Score {
191 int score;
192 int index;
193 Score& operator +=(int rhs) { this->score += rhs; return *this; }
194 Score& operator <<=(int rhs) { this->score <<= rhs; return *this; }
195 bool operator <(const Score& that) { return this->score < that.score; }
196 };
197
198 Score maxScore = { 0, 0 };
199 for (int i = 0; i < count; ++i) {
200 SkFontStyle current;
201 this->getStyle(i, &current, nullptr);
202 Score currentScore = { 0, i };
203
204 // CSS stretch / SkFontStyle::Width
205 // Takes priority over everything else.
206 if (pattern.width() <= SkFontStyle::kNormal_Width) {
207 if (current.width() <= pattern.width()) {
208 currentScore += 10 - pattern.width() + current.width();
209 } else {
210 currentScore += 10 - current.width();
211 }
212 } else {
213 if (current.width() > pattern.width()) {
214 currentScore += 10 + pattern.width() - current.width();
215 } else {
216 currentScore += current.width();
217 }
218 }
219 currentScore <<= 8;
220
221 // CSS style (normal, italic, oblique) / SkFontStyle::Slant (upright, italic, oblique)
222 // Takes priority over all valid weights.
223 static_assert(SkFontStyle::kUpright_Slant == 0 &&
226 "SkFontStyle::Slant values not as required.");
227 SkASSERT(0 <= pattern.slant() && pattern.slant() <= 2 &&
228 0 <= current.slant() && current.slant() <= 2);
229 static const int score[3][3] = {
230 /* Upright Italic Oblique [current]*/
231 /* Upright */ { 3 , 1 , 2 },
232 /* Italic */ { 1 , 3 , 2 },
233 /* Oblique */ { 1 , 2 , 3 },
234 /* [pattern] */
235 };
236 currentScore += score[pattern.slant()][current.slant()];
237 currentScore <<= 8;
238
239 // Synthetics (weight, style) [no stretch synthetic?]
240
241 // CSS weight / SkFontStyle::Weight
242 // The 'closer' to the target weight, the higher the score.
243 // 1000 is the 'heaviest' recognized weight
244 if (pattern.weight() == current.weight()) {
245 currentScore += 1000;
246 // less than 400 prefer lighter weights
247 } else if (pattern.weight() < 400) {
248 if (current.weight() <= pattern.weight()) {
249 currentScore += 1000 - pattern.weight() + current.weight();
250 } else {
251 currentScore += 1000 - current.weight();
252 }
253 // between 400 and 500 prefer heavier up to 500, then lighter weights
254 } else if (pattern.weight() <= 500) {
255 if (current.weight() >= pattern.weight() && current.weight() <= 500) {
256 currentScore += 1000 + pattern.weight() - current.weight();
257 } else if (current.weight() <= pattern.weight()) {
258 currentScore += 500 + current.weight();
259 } else {
260 currentScore += 1000 - current.weight();
261 }
262 // greater than 500 prefer heavier weights
263 } else if (pattern.weight() > 500) {
264 if (current.weight() > pattern.weight()) {
265 currentScore += 1000 + pattern.weight() - current.weight();
266 } else {
267 currentScore += current.weight();
268 }
269 }
270
271 if (maxScore < currentScore) {
272 maxScore = currentScore;
273 }
274 }
275
276 return this->createTypeface(maxScore.index);
277}
#define SkASSERT(cond)
Definition: SkAssert.h:116
virtual sk_sp< SkTypeface > createTypeface(int index)=0
virtual int count()=0
virtual void getStyle(int index, SkFontStyle *, SkString *style)=0
Slant slant() const
Definition: SkFontStyle.h:64
int width() const
Definition: SkFontStyle.h:63
int weight() const
Definition: SkFontStyle.h:62
constexpr bool operator<(const EnumType &lhs, const Mask< EnumType > &rhs)
Definition: mask.h:188
SINT Vec< N, T > & operator+=(Vec< N, T > &x, const Vec< N, T > &y)
Definition: SkVx.h:450
SINT Vec< N, T > & operator<<=(Vec< N, T > &x, int bits)
Definition: SkVx.h:466

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