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

Side by Side Diff: src/fonts/SkFontMgr_fontconfig.cpp

Issue 382053003: Update find_name_and_attributes to take ttc index. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move find_name_and_attributes to SkTypeface_FreeType::ScanFont. Created 6 years, 5 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 | src/ports/SkFontConfigInterface_android.cpp » ('j') | 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 2013 Google Inc. 2 * Copyright 2013 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 "SkFontMgr.h" 8 #include "SkFontMgr.h"
9 #include "SkFontStyle.h" 9 #include "SkFontStyle.h"
10 #include "SkFontConfigInterface.h" 10 #include "SkFontConfigInterface.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 gFCMutex.release(); 43 gFCMutex.release();
44 } 44 }
45 } 45 }
46 46
47 private: 47 private:
48 bool fUnlock; 48 bool fUnlock;
49 }; 49 };
50 50
51 } // namespace 51 } // namespace
52 52
53
54 // Defined in SkFontHost_FreeType.cpp
55 bool find_name_and_attributes(SkStream* stream, SkString* name,
56 SkTypeface::Style* style, bool* isFixedWidth);
57
58 // borrow this global from SkFontHost_fontconfig. eventually that file should 53 // borrow this global from SkFontHost_fontconfig. eventually that file should
59 // go away, and be replaced with this one. 54 // go away, and be replaced with this one.
60 extern SkFontConfigInterface* SkFontHost_fontconfig_ref_global(); 55 extern SkFontConfigInterface* SkFontHost_fontconfig_ref_global();
61 static SkFontConfigInterface* RefFCI() { 56 static SkFontConfigInterface* RefFCI() {
62 return SkFontHost_fontconfig_ref_global(); 57 return SkFontHost_fontconfig_ref_global();
63 } 58 }
64 59
65 // look for the last substring after a '/' and return that, or return null. 60 // look for the last substring after a '/' and return that, or return null.
66 static const char* find_just_name(const char* str) { 61 static const char* find_just_name(const char* str) {
67 const char* last = strrchr(str, '/'); 62 const char* last = strrchr(str, '/');
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 if (!length) { 295 if (!length) {
301 return NULL; 296 return NULL;
302 } 297 }
303 if (length >= 1024 * 1024 * 1024) { 298 if (length >= 1024 * 1024 * 1024) {
304 return NULL; // don't accept too large fonts (>= 1GB) for safety. 299 return NULL; // don't accept too large fonts (>= 1GB) for safety.
305 } 300 }
306 301
307 // TODO should the caller give us the style or should we get it from fre etype? 302 // TODO should the caller give us the style or should we get it from fre etype?
308 SkTypeface::Style style = SkTypeface::kNormal; 303 SkTypeface::Style style = SkTypeface::kNormal;
309 bool isFixedWidth = false; 304 bool isFixedWidth = false;
310 if (!find_name_and_attributes(stream, NULL, &style, &isFixedWidth)) { 305 if (!SkTypeface_FreeType::ScanFont(stream, 0, NULL, &style, &isFixedWidt h)) {
311 return NULL; 306 return NULL;
312 } 307 }
313 308
314 SkTypeface* face = FontConfigTypeface::Create(style, isFixedWidth, strea m); 309 SkTypeface* face = FontConfigTypeface::Create(style, isFixedWidth, strea m);
315 return face; 310 return face;
316 } 311 }
317 312
318 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE { 313 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE {
319 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 314 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
320 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; 315 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL;
321 } 316 }
322 317
323 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], 318 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
324 unsigned styleBits) const SK_OVER RIDE { 319 unsigned styleBits) const SK_OVER RIDE {
325 FCLocker lock; 320 FCLocker lock;
326 return FontConfigTypeface::LegacyCreateTypeface(NULL, familyName, 321 return FontConfigTypeface::LegacyCreateTypeface(NULL, familyName,
327 (SkTypeface::Style)styleBits); 322 (SkTypeface::Style)styleBits);
328 } 323 }
329 }; 324 };
330 325
331 SkFontMgr* SkFontMgr::Factory() { 326 SkFontMgr* SkFontMgr::Factory() {
332 SkFontConfigInterface* fci = RefFCI(); 327 SkFontConfigInterface* fci = RefFCI();
333 return fci ? SkNEW_ARGS(SkFontMgr_fontconfig, (fci)) : NULL; 328 return fci ? SkNEW_ARGS(SkFontMgr_fontconfig, (fci)) : NULL;
334 } 329 }
OLDNEW
« no previous file with comments | « no previous file | src/ports/SkFontConfigInterface_android.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698