OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 "SkFontHost.h" | 8 #include "SkFontHost.h" |
9 #include "SkFontHost_FreeType_common.h" | 9 #include "SkFontHost_FreeType_common.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 #ifndef SK_FONT_FILE_PREFIX | 24 #ifndef SK_FONT_FILE_PREFIX |
25 # define SK_FONT_FILE_PREFIX "/usr/share/fonts/truetype/" | 25 # define SK_FONT_FILE_PREFIX "/usr/share/fonts/truetype/" |
26 #endif | 26 #endif |
27 | 27 |
28 /////////////////////////////////////////////////////////////////////////////// | 28 /////////////////////////////////////////////////////////////////////////////// |
29 | 29 |
30 /** The base SkTypeface implementation for the custom font manager. */ | 30 /** The base SkTypeface implementation for the custom font manager. */ |
31 class SkTypeface_Custom : public SkTypeface_FreeType { | 31 class SkTypeface_Custom : public SkTypeface_FreeType { |
32 public: | 32 public: |
33 SkTypeface_Custom(Style style, bool isFixedPitch, bool sysFont, const SkStri
ng familyName) | 33 SkTypeface_Custom(Style style, bool isFixedPitch, |
| 34 bool sysFont, const SkString familyName, int index) |
34 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) | 35 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) |
35 , fIsSysFont(sysFont), fFamilyName(familyName) | 36 , fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index) |
36 { } | 37 { } |
37 | 38 |
38 bool isSysFont() const { return fIsSysFont; } | 39 bool isSysFont() const { return fIsSysFont; } |
39 | 40 |
40 virtual const char* getUniqueString() const = 0; | 41 virtual const char* getUniqueString() const = 0; |
41 | 42 |
42 protected: | 43 protected: |
43 virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) cons
t SK_OVERRIDE { | 44 virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) cons
t SK_OVERRIDE { |
44 desc->setFamilyName(fFamilyName.c_str()); | 45 desc->setFamilyName(fFamilyName.c_str()); |
45 desc->setFontFileName(this->getUniqueString()); | 46 desc->setFontFileName(this->getUniqueString()); |
| 47 desc->setFontFileIndex(fIndex); |
46 *isLocal = !this->isSysFont(); | 48 *isLocal = !this->isSysFont(); |
47 } | 49 } |
48 | 50 |
| 51 int getIndex() const { return fIndex; } |
| 52 |
49 private: | 53 private: |
50 bool fIsSysFont; | 54 const bool fIsSysFont; |
51 SkString fFamilyName; | 55 const SkString fFamilyName; |
| 56 const int fIndex; |
52 | 57 |
53 typedef SkTypeface_FreeType INHERITED; | 58 typedef SkTypeface_FreeType INHERITED; |
54 }; | 59 }; |
55 | 60 |
56 /** The empty SkTypeface implementation for the custom font manager. | 61 /** The empty SkTypeface implementation for the custom font manager. |
57 * Used as the last resort fallback typeface. | 62 * Used as the last resort fallback typeface. |
58 */ | 63 */ |
59 class SkTypeface_Empty : public SkTypeface_Custom { | 64 class SkTypeface_Empty : public SkTypeface_Custom { |
60 public: | 65 public: |
61 SkTypeface_Empty() : INHERITED(SkTypeface::kNormal, false, true, SkString())
{} | 66 SkTypeface_Empty() : INHERITED(SkTypeface::kNormal, false, true, SkString(),
0) {} |
62 | 67 |
63 virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; } | 68 virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; } |
64 | 69 |
65 protected: | 70 protected: |
66 virtual SkStream* onOpenStream(int*) const SK_OVERRIDE { return NULL; } | 71 virtual SkStream* onOpenStream(int*) const SK_OVERRIDE { return NULL; } |
67 | 72 |
68 private: | 73 private: |
69 typedef SkTypeface_Custom INHERITED; | 74 typedef SkTypeface_Custom INHERITED; |
70 }; | 75 }; |
71 | 76 |
72 /** The stream SkTypeface implementation for the custom font manager. */ | 77 /** The stream SkTypeface implementation for the custom font manager. */ |
73 class SkTypeface_Stream : public SkTypeface_Custom { | 78 class SkTypeface_Stream : public SkTypeface_Custom { |
74 public: | 79 public: |
75 SkTypeface_Stream(Style style, bool isFixedPitch, bool sysFont, const SkStri
ng familyName, | 80 SkTypeface_Stream(Style style, bool isFixedPitch, bool sysFont, const SkStri
ng familyName, |
76 SkStream* stream, int ttcIndex) | 81 SkStream* stream, int ttcIndex) |
77 : INHERITED(style, isFixedPitch, sysFont, familyName) | 82 : INHERITED(style, isFixedPitch, sysFont, familyName, ttcIndex) |
78 , fStream(SkRef(stream)), fTtcIndex(ttcIndex) | 83 , fStream(SkRef(stream)) |
79 { } | 84 { } |
80 | 85 |
81 virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; } | 86 virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; } |
82 | 87 |
83 protected: | 88 protected: |
84 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { | 89 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
85 *ttcIndex = 0; | 90 *ttcIndex = this->getIndex(); |
86 return fStream->duplicate(); | 91 return fStream->duplicate(); |
87 } | 92 } |
88 | 93 |
89 private: | 94 private: |
90 SkAutoTUnref<SkStream> fStream; | 95 const SkAutoTUnref<const SkStream> fStream; |
91 int fTtcIndex; | |
92 | 96 |
93 typedef SkTypeface_Custom INHERITED; | 97 typedef SkTypeface_Custom INHERITED; |
94 }; | 98 }; |
95 | 99 |
96 /** The file SkTypeface implementation for the custom font manager. */ | 100 /** The file SkTypeface implementation for the custom font manager. */ |
97 class SkTypeface_File : public SkTypeface_Custom { | 101 class SkTypeface_File : public SkTypeface_Custom { |
98 public: | 102 public: |
99 SkTypeface_File(Style style, bool isFixedPitch, bool sysFont, const SkString
familyName, | 103 SkTypeface_File(Style style, bool isFixedPitch, bool sysFont, const SkString
familyName, |
100 const char path[]) | 104 const char path[], int index) |
101 : INHERITED(style, isFixedPitch, sysFont, familyName) | 105 : INHERITED(style, isFixedPitch, sysFont, familyName, index) |
102 , fPath(path) | 106 , fPath(path) |
103 { } | 107 { } |
104 | 108 |
105 virtual const char* getUniqueString() const SK_OVERRIDE { | 109 virtual const char* getUniqueString() const SK_OVERRIDE { |
106 const char* str = strrchr(fPath.c_str(), '/'); | 110 const char* str = strrchr(fPath.c_str(), '/'); |
107 if (str) { | 111 if (str) { |
108 str += 1; // skip the '/' | 112 str += 1; // skip the '/' |
109 } | 113 } |
110 return str; | 114 return str; |
111 } | 115 } |
112 | 116 |
113 protected: | 117 protected: |
114 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { | 118 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
115 *ttcIndex = 0; | 119 *ttcIndex = this->getIndex(); |
116 return SkStream::NewFromFile(fPath.c_str()); | 120 return SkStream::NewFromFile(fPath.c_str()); |
117 } | 121 } |
118 | 122 |
119 private: | 123 private: |
120 SkString fPath; | 124 SkString fPath; |
121 | 125 |
122 typedef SkTypeface_Custom INHERITED; | 126 typedef SkTypeface_Custom INHERITED; |
123 }; | 127 }; |
124 | 128 |
125 /////////////////////////////////////////////////////////////////////////////// | 129 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 if (!get_name_and_style(filename.c_str(), &realname, &style, &isFixe
dPitch)) { | 336 if (!get_name_and_style(filename.c_str(), &realname, &style, &isFixe
dPitch)) { |
333 SkDebugf("------ can't load <%s> as a font\n", filename.c_str())
; | 337 SkDebugf("------ can't load <%s> as a font\n", filename.c_str())
; |
334 continue; | 338 continue; |
335 } | 339 } |
336 | 340 |
337 SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_File, ( | 341 SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_File, ( |
338 style, | 342 style, |
339 isFixedPitch, | 343 isFixedPitch, |
340 true, // system-font (cannot de
lete) | 344 true, // system-font (cannot de
lete) |
341 realname, | 345 realname, |
342 filename.c_str())); | 346 filename.c_str(), 0)); |
343 | 347 |
344 SkFontStyleSet_Custom* addTo = this->onMatchFamily(realname.c_str())
; | 348 SkFontStyleSet_Custom* addTo = this->onMatchFamily(realname.c_str())
; |
345 if (NULL == addTo) { | 349 if (NULL == addTo) { |
346 addTo = new SkFontStyleSet_Custom(realname); | 350 addTo = new SkFontStyleSet_Custom(realname); |
347 fFamilies.push_back().reset(addTo); | 351 fFamilies.push_back().reset(addTo); |
348 } | 352 } |
349 addTo->appendTypeface(tf); | 353 addTo->appendTypeface(tf); |
350 } | 354 } |
351 | 355 |
352 SkOSFile::Iter dirIter(directory.c_str()); | 356 SkOSFile::Iter dirIter(directory.c_str()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 } | 401 } |
398 | 402 |
399 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; | 403 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; |
400 SkFontStyleSet_Custom* gDefaultFamily; | 404 SkFontStyleSet_Custom* gDefaultFamily; |
401 SkTypeface* gDefaultNormal; | 405 SkTypeface* gDefaultNormal; |
402 }; | 406 }; |
403 | 407 |
404 SkFontMgr* SkFontMgr::Factory() { | 408 SkFontMgr* SkFontMgr::Factory() { |
405 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); | 409 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); |
406 } | 410 } |
OLD | NEW |