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