OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkFontDescriptor.h" | 8 #include "SkFontDescriptor.h" |
9 #include "SkFontMgr.h" | 9 #include "SkFontMgr.h" |
10 #include "SkOncePtr.h" | 10 #include "SkOnce.h" |
11 #include "SkStream.h" | 11 #include "SkStream.h" |
12 #include "SkTypes.h" | 12 #include "SkTypes.h" |
13 | 13 |
14 class SkFontStyle; | 14 class SkFontStyle; |
15 class SkTypeface; | 15 class SkTypeface; |
16 | 16 |
17 class SkEmptyFontStyleSet : public SkFontStyleSet { | 17 class SkEmptyFontStyleSet : public SkFontStyleSet { |
18 public: | 18 public: |
19 int count() override { return 0; } | 19 int count() override { return 0; } |
20 void getStyle(int, SkFontStyle*, SkString*) override { | 20 void getStyle(int, SkFontStyle*, SkString*) override { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 if (nullptr == path) { | 162 if (nullptr == path) { |
163 return nullptr; | 163 return nullptr; |
164 } | 164 } |
165 return this->onCreateFromFile(path, ttcIndex); | 165 return this->onCreateFromFile(path, ttcIndex); |
166 } | 166 } |
167 | 167 |
168 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], SkFontStyle
style) const { | 168 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], SkFontStyle
style) const { |
169 return this->onLegacyCreateTypeface(familyName, style); | 169 return this->onLegacyCreateTypeface(familyName, style); |
170 } | 170 } |
171 | 171 |
172 SK_DECLARE_STATIC_ONCE_PTR(SkFontMgr, singleton); | |
173 SkFontMgr* SkFontMgr::RefDefault() { | 172 SkFontMgr* SkFontMgr::RefDefault() { |
174 return SkRef(singleton.get([]{ | 173 static SkOnce once; |
| 174 static SkFontMgr* singleton; |
| 175 |
| 176 once([]{ |
175 SkFontMgr* fm = SkFontMgr::Factory(); | 177 SkFontMgr* fm = SkFontMgr::Factory(); |
176 return fm ? fm : new SkEmptyFontMgr; | 178 singleton = fm ? fm : new SkEmptyFontMgr; |
177 })); | 179 }); |
| 180 return SkRef(singleton); |
178 } | 181 } |
179 | 182 |
180 /** | 183 /** |
181 * Width has the greatest priority. | 184 * Width has the greatest priority. |
182 * If the value of pattern.width is 5 (normal) or less, | 185 * If the value of pattern.width is 5 (normal) or less, |
183 * narrower width values are checked first, then wider values. | 186 * narrower width values are checked first, then wider values. |
184 * If the value of pattern.width is greater than 5 (normal), | 187 * If the value of pattern.width is greater than 5 (normal), |
185 * wider values are checked first, followed by narrower values. | 188 * wider values are checked first, followed by narrower values. |
186 * | 189 * |
187 * Italic/Oblique has the next highest priority. | 190 * Italic/Oblique has the next highest priority. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } | 288 } |
286 } | 289 } |
287 | 290 |
288 if (maxScore < currentScore) { | 291 if (maxScore < currentScore) { |
289 maxScore = currentScore; | 292 maxScore = currentScore; |
290 } | 293 } |
291 } | 294 } |
292 | 295 |
293 return this->createTypeface(maxScore.index); | 296 return this->createTypeface(maxScore.index); |
294 } | 297 } |
OLD | NEW |