Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: src/ports/SkFontMgr_android.cpp

Issue 427293003: Implement SkFontMgr_Android::onMatchFamilyStyleCharacter. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: First thing that works. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "SkFontConfigParser_android.h" 8 #include "SkFontConfigParser_android.h"
9 #include "SkFontDescriptor.h" 9 #include "SkFontDescriptor.h"
10 #include "SkFontHost_FreeType_common.h" 10 #include "SkFontHost_FreeType_common.h"
(...skipping 15 matching lines...) Expand all
26 #ifndef SK_DEBUG_FONTS 26 #ifndef SK_DEBUG_FONTS
27 #define SK_DEBUG_FONTS 0 27 #define SK_DEBUG_FONTS 0
28 #endif 28 #endif
29 29
30 #if SK_DEBUG_FONTS 30 #if SK_DEBUG_FONTS
31 # define DEBUG_FONT(args) SkDebugf args 31 # define DEBUG_FONT(args) SkDebugf args
32 #else 32 #else
33 # define DEBUG_FONT(args) 33 # define DEBUG_FONT(args)
34 #endif 34 #endif
35 35
36 //SkTypeface* SkAndroidNextLogicalTypeface(SkFontID, SkFontID, SkPaintOptionsAnd roid const&) {
37 // return NULL;
38 //}
bungeman-skia 2014/07/30 17:00:07 I'll remove this block soon. I've commented out th
39
36 class SkTypeface_Android : public SkTypeface_FreeType { 40 class SkTypeface_Android : public SkTypeface_FreeType {
37 public: 41 public:
38 SkTypeface_Android(int index, 42 SkTypeface_Android(int index,
39 Style style, 43 Style style,
40 bool isFixedPitch, 44 bool isFixedPitch,
41 const SkString familyName) 45 const SkString familyName)
42 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) 46 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
43 , fIndex(index) 47 , fIndex(index)
44 , fFamilyName(familyName) { } 48 , fFamilyName(familyName) { }
45 49
46 const SkString& name() const { return fFamilyName; } 50 const SkString& name() const { return fFamilyName; }
47 51
48 protected: 52 protected:
49 int fIndex; 53 int fIndex;
50 SkString fFamilyName; 54 SkString fFamilyName;
51 55
52 private: 56 private:
53 typedef SkTypeface_FreeType INHERITED; 57 typedef SkTypeface_FreeType INHERITED;
54 }; 58 };
55 59
56 class SkTypeface_AndroidSystem : public SkTypeface_Android { 60 class SkTypeface_AndroidSystem : public SkTypeface_Android {
57 public: 61 public:
58 SkTypeface_AndroidSystem(const SkString pathName, 62 SkTypeface_AndroidSystem(const SkString pathName,
59 int index, 63 int index,
60 Style style, 64 Style style,
61 bool isFixedPitch, 65 bool isFixedPitch,
62 const SkString familyName) 66 const SkString familyName,
67 const SkLanguage& lang,
68 bool useInFallback)
tomhudson 2014/07/30 17:54:58 You pass "is accepted fallback variant" to "use in
bungeman-skia 2014/07/30 23:03:28 Removed.
63 : INHERITED(index, style, isFixedPitch, familyName) 69 : INHERITED(index, style, isFixedPitch, familyName)
64 , fPathName(pathName) { } 70 , fPathName(pathName)
71 , fLang(lang)
72 , fUseInFallback(useInFallback)
bungeman-skia 2014/07/30 17:00:07 For the moment I'm sticking this on the typeface s
73 { }
tomhudson 2014/07/30 17:54:58 Nit: Skia style?
bungeman-skia 2014/07/30 23:03:28 Hmm, we do this in a number of other places, Skia
65 74
66 virtual void onGetFontDescriptor(SkFontDescriptor* desc, 75 virtual void onGetFontDescriptor(SkFontDescriptor* desc,
67 bool* serialize) const SK_OVERRIDE { 76 bool* serialize) const SK_OVERRIDE {
68 SkASSERT(desc); 77 SkASSERT(desc);
69 SkASSERT(serialize); 78 SkASSERT(serialize);
70 desc->setFamilyName(fFamilyName.c_str()); 79 desc->setFamilyName(fFamilyName.c_str());
71 desc->setFontFileName(fPathName.c_str()); 80 desc->setFontFileName(fPathName.c_str());
72 *serialize = false; 81 *serialize = false;
73 } 82 }
74 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { 83 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE {
75 *ttcIndex = fIndex; 84 *ttcIndex = fIndex;
76 return SkStream::NewFromFile(fPathName.c_str()); 85 return SkStream::NewFromFile(fPathName.c_str());
77 } 86 }
78 87
79 private: 88 private:
80 SkString fPathName; 89 const SkString fPathName;
81 90
91 public:
djsollen 2014/07/30 17:31:43 seems like having 2 getters makes more sense than
tomhudson 2014/07/30 17:54:58 Acknowledged.
bungeman-skia 2014/07/30 23:03:28 You Java people and your gratuitous setters and ge
92 const SkLanguage fLang;
93 const bool fUseInFallback;
94
95 private:
82 typedef SkTypeface_Android INHERITED; 96 typedef SkTypeface_Android INHERITED;
83 }; 97 };
84 98
85 class SkTypeface_AndroidStream : public SkTypeface_Android { 99 class SkTypeface_AndroidStream : public SkTypeface_Android {
86 public: 100 public:
87 SkTypeface_AndroidStream(SkStream* stream, 101 SkTypeface_AndroidStream(SkStream* stream,
88 int index, 102 int index,
89 Style style, 103 Style style,
90 bool isFixedPitch, 104 bool isFixedPitch,
91 const SkString familyName) 105 const SkString familyName)
(...skipping 21 matching lines...) Expand all
113 }; 127 };
114 128
115 void get_path_for_sys_fonts(SkString* full, const SkString& name) { 129 void get_path_for_sys_fonts(SkString* full, const SkString& name) {
116 full->set(getenv("ANDROID_ROOT")); 130 full->set(getenv("ANDROID_ROOT"));
117 full->append(SK_FONT_FILE_PREFIX); 131 full->append(SK_FONT_FILE_PREFIX);
118 full->append(name); 132 full->append(name);
119 } 133 }
120 134
121 class SkFontStyleSet_Android : public SkFontStyleSet { 135 class SkFontStyleSet_Android : public SkFontStyleSet {
122 public: 136 public:
123 explicit SkFontStyleSet_Android(FontFamily* family) : fFontFamily(family) { 137 explicit SkFontStyleSet_Android(FontFamily* family, SkString* name) {
124 // TODO? make this lazy 138 // TODO? make this lazy
125 for (int i = 0; i < family->fFontFiles.count(); ++i) { 139 for (int i = 0; i < family->fFontFiles.count(); ++i) {
126 const SkString& fileName = family->fFontFiles[i].fFileName; 140 const SkString& fileName = family->fFontFiles[i].fFileName;
127 141
128 SkString pathName; 142 SkString pathName;
129 get_path_for_sys_fonts(&pathName, fileName); 143 get_path_for_sys_fonts(&pathName, fileName);
130 144
131 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(pathName.c_str() )); 145 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(pathName.c_str() ));
132 if (!stream.get()) { 146 if (!stream.get()) {
133 DEBUG_FONT(("---- SystemFonts[%d] file=%s (NOT EXIST)", i, fileN ame.c_str())); 147 DEBUG_FONT(("---- SystemFonts[%d] file=%s (NOT EXIST)", i, fileN ame.c_str()));
134 continue; 148 continue;
135 } 149 }
136 150
151 int ttcIndex = family->fFontFiles[i].fIndex;
djsollen 2014/07/30 17:31:43 const int
bungeman-skia 2014/07/30 23:03:28 Done.
137 SkString fontName; 152 SkString fontName;
138 SkTypeface::Style style; 153 SkTypeface::Style style;
139 bool isFixedWidth; 154 bool isFixedWidth;
140 if (!SkTypeface_FreeType::ScanFont(stream.get(), family->fFontFiles[ i].fIndex, 155 if (!SkTypeface_FreeType::ScanFont(stream.get(), ttcIndex,
141 &fontName, &style, &isFixedWidth) ) { 156 &fontName, &style, &isFixedWidth) ) {
142 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, fileNam e.c_str())); 157 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, fileNam e.c_str()));
143 continue; 158 continue;
144 } 159 }
145 160
161 static int32_t acceptedVariants = SkPaintOptionsAndroid::kDefault_Va riant |
djsollen 2014/07/30 17:31:43 let's document why we do this. The compact varian
tomhudson 2014/07/30 17:54:58 Acknowledged.
bungeman-skia 2014/07/30 23:03:28 Moved all the way over to the parser.
162 SkPaintOptionsAndroid::kElegant_Va riant;
163 bool isAcceptedFallbackVariant = SkToBool(
164 family->fFontFiles[i].fPaintOptions.getFontVariant() & acceptedV ariants);
165
166 const SkLanguage& lang = family->fFontFiles[i].fPaintOptions.getLang uage();
167
168 if (name != NULL) {
169 fontName = *name;
170 }
171
146 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem, 172 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem,
147 (pathName, 0, 173 (pathName, ttcIndex,
148 style, isFixedWidth, fontName) )); 174 style, isFixedWidth, fontName,
175 lang, isAcceptedFallbackVarian t)));
149 } 176 }
150 } 177 }
151 178
152 virtual int count() SK_OVERRIDE { 179 virtual int count() SK_OVERRIDE {
153 return fStyles.count(); 180 return fStyles.count();
154 } 181 }
155 virtual void getStyle(int index, SkFontStyle* style, SkString* name) SK_OVER RIDE { 182 virtual void getStyle(int index, SkFontStyle* style, SkString* name) SK_OVER RIDE {
156 if (index < 0 || fStyles.count() <= index) { 183 if (index < 0 || fStyles.count() <= index) {
157 return; 184 return;
158 } 185 }
159 if (style) { 186 if (style) {
160 *style = this->style(index); 187 *style = this->style(index);
161 } 188 }
162 if (name) { 189 if (name) {
163 name->reset(); 190 name->reset();
164 } 191 }
165 } 192 }
166 virtual SkTypeface* createTypeface(int index) SK_OVERRIDE { 193 virtual SkTypeface_AndroidSystem* createTypeface(int index) SK_OVERRIDE {
167 if (index < 0 || fStyles.count() <= index) { 194 if (index < 0 || fStyles.count() <= index) {
168 return NULL; 195 return NULL;
169 } 196 }
170 return SkRef(fStyles[index].get()); 197 return SkRef(fStyles[index].get());
171 } 198 }
172 199
173 /** Find the typeface in this style set that most closely matches the given pattern. 200 /** Find the typeface in this style set that most closely matches the given pattern.
174 * TODO: consider replacing with SkStyleSet_Indirect::matchStyle(); 201 * TODO: consider replacing with SkStyleSet_Indirect::matchStyle();
175 * this simpler version using match_score() passes all our tests. 202 * this simpler version using match_score() passes all our tests.
176 */ 203 */
177 virtual SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE { 204 virtual SkTypeface_AndroidSystem* matchStyle(const SkFontStyle& pattern) SK_ OVERRIDE {
178 if (0 == fStyles.count()) { 205 if (0 == fStyles.count()) {
179 return NULL; 206 return NULL;
180 } 207 }
181 SkTypeface* closest = fStyles[0]; 208 SkTypeface_AndroidSystem* closest = fStyles[0];
182 int minScore = std::numeric_limits<int>::max(); 209 int minScore = std::numeric_limits<int>::max();
183 for (int i = 0; i < fStyles.count(); ++i) { 210 for (int i = 0; i < fStyles.count(); ++i) {
184 SkFontStyle style = this->style(i); 211 SkFontStyle style = this->style(i);
185 int score = match_score(pattern, style); 212 int score = match_score(pattern, style);
186 if (score < minScore) { 213 if (score < minScore) {
187 closest = fStyles[i]; 214 closest = fStyles[i];
188 minScore = score; 215 minScore = score;
189 } 216 }
190 } 217 }
191 return SkRef(closest); 218 return SkRef(closest);
(...skipping 14 matching lines...) Expand all
206 } 233 }
207 static int match_score(const SkFontStyle& pattern, const SkFontStyle& candid ate) { 234 static int match_score(const SkFontStyle& pattern, const SkFontStyle& candid ate) {
208 int score = 0; 235 int score = 0;
209 score += abs((pattern.width() - candidate.width()) * 100); 236 score += abs((pattern.width() - candidate.width()) * 100);
210 score += abs((pattern.isItalic() == candidate.isItalic()) ? 0 : 1000); 237 score += abs((pattern.isItalic() == candidate.isItalic()) ? 0 : 1000);
211 score += abs(pattern.weight() - candidate.weight()); 238 score += abs(pattern.weight() - candidate.weight());
212 return score; 239 return score;
213 } 240 }
214 241
215 242
216 FontFamily* fFontFamily; 243 SkTArray<SkAutoTUnref<SkTypeface_AndroidSystem>, true> fStyles;
217 SkTArray<SkAutoTUnref<SkTypeface>, true> fStyles;
218 244
219 friend struct NameToFamily; 245 friend struct NameToFamily;
220 friend class SkFontMgr_Android; 246 friend class SkFontMgr_Android;
221 247
222 typedef SkFontStyleSet INHERITED; 248 typedef SkFontStyleSet INHERITED;
223 }; 249 };
224 250
225 /** On Android a single family can have many names, but our API assumes unique n ames. 251 /** On Android a single family can have many names, but our API assumes unique n ames.
226 * Map names to the back end so that all names for a given family refer to the same 252 * Map names to the back end so that all names for a given family refer to the same
227 * (non-replicated) set of typefaces. 253 * (non-replicated) set of typefaces.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVER RIDE { 293 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVER RIDE {
268 if (!familyName) { 294 if (!familyName) {
269 return NULL; 295 return NULL;
270 } 296 }
271 SkAutoAsciiToLC tolc(familyName); 297 SkAutoAsciiToLC tolc(familyName);
272 for (int i = 0; i < fNameToFamilyMap.count(); ++i) { 298 for (int i = 0; i < fNameToFamilyMap.count(); ++i) {
273 if (fNameToFamilyMap[i].name.equals(tolc.lc())) { 299 if (fNameToFamilyMap[i].name.equals(tolc.lc())) {
274 return SkRef(fNameToFamilyMap[i].styleSet); 300 return SkRef(fNameToFamilyMap[i].styleSet);
275 } 301 }
276 } 302 }
303 // TODO: eventually we should not need to name fallback families.
304 for (int i = 0; i < fFallbackNameToFamilyMap.count(); ++i) {
305 if (fFallbackNameToFamilyMap[i].name.equals(tolc.lc())) {
306 return SkRef(fFallbackNameToFamilyMap[i].styleSet);
307 }
308 }
277 return NULL; 309 return NULL;
278 } 310 }
279 311
280 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], 312 virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
281 const SkFontStyle& style) const SK_OV ERRIDE { 313 const SkFontStyle& style) const SK_OV ERRIDE {
282 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName)); 314 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName));
283 return sset->matchStyle(style); 315 return sset->matchStyle(style);
284 } 316 }
285 317
286 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* typeface, 318 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* typeface,
287 const SkFontStyle& style) const SK_OVER RIDE { 319 const SkFontStyle& style) const SK_OVER RIDE {
288 for (int i = 0; i < fFontStyleSets.count(); ++i) { 320 for (int i = 0; i < fFontStyleSets.count(); ++i) {
289 for (int j = 0; j < fFontStyleSets[i]->fStyles.count(); ++j) { 321 for (int j = 0; j < fFontStyleSets[i]->fStyles.count(); ++j) {
290 if (fFontStyleSets[i]->fStyles[j] == typeface) { 322 if (fFontStyleSets[i]->fStyles[j] == typeface) {
291 return fFontStyleSets[i]->matchStyle(style); 323 return fFontStyleSets[i]->matchStyle(style);
292 } 324 }
293 } 325 }
294 } 326 }
295 return NULL; 327 return NULL;
296 } 328 }
297 329
330 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
331 const SkFontStyle& style,
332 const char bpc47[],
333 uint32_t character) const SK _OVERRIDE
334 {
335 SkLanguage lang(bpc47);
336 do {
337 const SkString& langTag = lang.getTag();
338 for (int i = 0; i < fFallbackNameToFamilyMap.count(); ++i) {
339 SkFontStyleSet_Android* family = fFallbackNameToFamilyMap[i].sty leSet;
340 SkAutoTUnref<SkTypeface_AndroidSystem> face(family->matchStyle(s tyle));
341
342 if (!face->fUseInFallback ||
343 (!langTag.isEmpty() && langTag != face->fLang.getTag())) {
344 continue;
345 }
346
347 SkPaint paint;
348 paint.setTypeface(face);
349 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
350
351 uint16_t glyphID;
352 paint.textToGlyphs(&character, sizeof(character), &glyphID);
353 if (glyphID != 0) {
354 return face.detach();
355 }
356 }
357 } while (!lang.getTag().isEmpty() && (lang = lang.getParent(), true));
358 return NULL;
359 }
360
298 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OV ERRIDE { 361 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OV ERRIDE {
299 SkAutoTUnref<SkStream> stream(new SkMemoryStream(data)); 362 SkAutoTUnref<SkStream> stream(new SkMemoryStream(data));
300 return this->createFromStream(stream, ttcIndex); 363 return this->createFromStream(stream, ttcIndex);
301 } 364 }
302 365
303 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE { 366 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE {
304 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 367 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
305 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; 368 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL;
306 } 369 }
307 370
(...skipping 14 matching lines...) Expand all
322 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], 385 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
323 unsigned styleBits) const SK_OVER RIDE { 386 unsigned styleBits) const SK_OVER RIDE {
324 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits; 387 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits;
325 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold 388 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold
326 ? SkFontStyle::kBold_Weight 389 ? SkFontStyle::kBold_Weight
327 : SkFontStyle::kNormal_Weight, 390 : SkFontStyle::kNormal_Weight,
328 SkFontStyle::kNormal_Width, 391 SkFontStyle::kNormal_Width,
329 oldStyle & SkTypeface::kItalic 392 oldStyle & SkTypeface::kItalic
330 ? SkFontStyle::kItalic_Slant 393 ? SkFontStyle::kItalic_Slant
331 : SkFontStyle::kUpright_Slant); 394 : SkFontStyle::kUpright_Slant);
332 SkTypeface* tf = NULL;
333 395
334 if (NULL != familyName) { 396 if (NULL != familyName) {
335 // On Android, we must return NULL when we can't find the requested 397 // On Android, we must return NULL when we can't find the requested
336 // named typeface so that the system/app can provide their own recov ery 398 // named typeface so that the system/app can provide their own recov ery
337 // mechanism. On other platforms we'd provide a typeface from the 399 // mechanism. On other platforms we'd provide a typeface from the
338 // default family instead. 400 // default family instead.
339 tf = this->onMatchFamilyStyle(familyName, style); 401 return this->onMatchFamilyStyle(familyName, style);
340 } else {
341 tf = fDefaultFamily->matchStyle(style);
342 } 402 }
343 403 return fDefaultFamily->matchStyle(style);
344 // TODO: double ref? qv matchStyle()
345 return SkSafeRef(tf);
346 } 404 }
347 405
348 406
349 private: 407 private:
350 408
351 SkTArray<SkAutoTUnref<SkFontStyleSet_Android>, true> fFontStyleSets; 409 SkTArray<SkAutoTUnref<SkFontStyleSet_Android>, true> fFontStyleSets;
352 SkFontStyleSet* fDefaultFamily; 410 SkFontStyleSet* fDefaultFamily;
353 SkTypeface* fDefaultTypeface; 411 SkTypeface* fDefaultTypeface;
354 412
355 SkTDArray<NameToFamily> fNameToFamilyMap; 413 SkTDArray<NameToFamily> fNameToFamilyMap;
414 SkTDArray<NameToFamily> fFallbackNameToFamilyMap;
356 415
357 void buildNameToFamilyMap(SkTDArray<FontFamily*> families) { 416 void buildNameToFamilyMap(SkTDArray<FontFamily*> families) {
358 for (int i = 0; i < families.count(); i++) { 417 for (int i = 0; i < families.count(); i++) {
359 fFontStyleSets.push_back().reset( 418 if (families[i]->fIsFallbackFont) {
djsollen 2014/07/30 17:31:43 in general this if/else block is very dense and ha
tomhudson 2014/07/30 17:54:58 Acknowledged.
bungeman-skia 2014/07/30 23:03:28 Made it much different now.
360 SkNEW_ARGS(SkFontStyleSet_Android, (families[i]))); 419 SkString fallbackName;
361 for (int j = 0; j < families[i]->fNames.count(); j++) { 420 fallbackName.printf("%.2x##fallback", i);
362 NameToFamily* nextEntry = fNameToFamilyMap.append(); 421 NameToFamily* nextEntry = fFallbackNameToFamilyMap.append();
363 SkNEW_PLACEMENT_ARGS(&nextEntry->name, SkString, (families[i]->f Names[j])); 422 SkNEW_PLACEMENT_ARGS(&nextEntry->name, SkString, (fallbackName)) ;
364 nextEntry->styleSet = fFontStyleSets.back().get(); 423 nextEntry->styleSet = fFontStyleSets.push_back().reset(
424 SkNEW_ARGS(SkFontStyleSet_Android, (families[i], &fallbackNa me)));
425 } else {
426 SkString* cannonicalName = NULL;
427 if (families[i]->fNames.count() > 0) {
428 cannonicalName = &families[i]->fNames[0];
429 }
430 SkFontStyleSet_Android* newSet = fFontStyleSets.push_back().rese t(
431 SkNEW_ARGS(SkFontStyleSet_Android, (families[i], cannonicalN ame)));
432 for (int j = 0; j < families[i]->fNames.count(); j++) {
433 NameToFamily* nextEntry = fNameToFamilyMap.append();
434 SkNEW_PLACEMENT_ARGS(&nextEntry->name, SkString, (families[i ]->fNames[j]));
435 nextEntry->styleSet = newSet;
436 }
365 } 437 }
366 } 438 }
367 } 439 }
368 440
369 void findDefaultFont() { 441 void findDefaultFont() {
370 SkASSERT(!fFontStyleSets.empty()); 442 SkASSERT(!fFontStyleSets.empty());
371 443
372 static const char* gDefaultNames[] = { "sans-serif" }; 444 static const char* gDefaultNames[] = { "sans-serif" };
373 for (size_t i = 0; i < SK_ARRAY_COUNT(gDefaultNames); ++i) { 445 for (size_t i = 0; i < SK_ARRAY_COUNT(gDefaultNames); ++i) {
374 SkFontStyleSet* set = this->onMatchFamily(gDefaultNames[i]); 446 SkFontStyleSet* set = this->onMatchFamily(gDefaultNames[i]);
(...skipping 17 matching lines...) Expand all
392 } 464 }
393 465
394 typedef SkFontMgr INHERITED; 466 typedef SkFontMgr INHERITED;
395 }; 467 };
396 468
397 /////////////////////////////////////////////////////////////////////////////// 469 ///////////////////////////////////////////////////////////////////////////////
398 470
399 SkFontMgr* SkFontMgr::Factory() { 471 SkFontMgr* SkFontMgr::Factory() {
400 return SkNEW(SkFontMgr_Android); 472 return SkNEW(SkFontMgr_Android);
401 } 473 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698