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 "SkLazyPtr.h" | 10 #include "SkLazyPtr.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 { |
21 SkDEBUGFAIL("SkFontStyleSet::getStyle called on empty set"); | 21 SkDEBUGFAIL("SkFontStyleSet::getStyle called on empty set"); |
22 } | 22 } |
23 SkTypeface* createTypeface(int index) override { | 23 SkTypeface* createTypeface(int index) override { |
24 SkDEBUGFAIL("SkFontStyleSet::createTypeface called on empty set"); | 24 SkDEBUGFAIL("SkFontStyleSet::createTypeface called on empty set"); |
25 return NULL; | 25 return nullptr; |
26 } | 26 } |
27 SkTypeface* matchStyle(const SkFontStyle&) override { | 27 SkTypeface* matchStyle(const SkFontStyle&) override { |
28 return NULL; | 28 return nullptr; |
29 } | 29 } |
30 }; | 30 }; |
31 | 31 |
32 SkFontStyleSet* SkFontStyleSet::CreateEmpty() { return new SkEmptyFontStyleSet;
} | 32 SkFontStyleSet* SkFontStyleSet::CreateEmpty() { return new SkEmptyFontStyleSet;
} |
33 | 33 |
34 /////////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////////// |
35 | 35 |
36 class SkEmptyFontMgr : public SkFontMgr { | 36 class SkEmptyFontMgr : public SkFontMgr { |
37 protected: | 37 protected: |
38 int onCountFamilies() const override { | 38 int onCountFamilies() const override { |
39 return 0; | 39 return 0; |
40 } | 40 } |
41 void onGetFamilyName(int index, SkString* familyName) const override { | 41 void onGetFamilyName(int index, SkString* familyName) const override { |
42 SkDEBUGFAIL("onGetFamilyName called with bad index"); | 42 SkDEBUGFAIL("onGetFamilyName called with bad index"); |
43 } | 43 } |
44 SkFontStyleSet* onCreateStyleSet(int index) const override { | 44 SkFontStyleSet* onCreateStyleSet(int index) const override { |
45 SkDEBUGFAIL("onCreateStyleSet called with bad index"); | 45 SkDEBUGFAIL("onCreateStyleSet called with bad index"); |
46 return NULL; | 46 return nullptr; |
47 } | 47 } |
48 SkFontStyleSet* onMatchFamily(const char[]) const override { | 48 SkFontStyleSet* onMatchFamily(const char[]) const override { |
49 return SkFontStyleSet::CreateEmpty(); | 49 return SkFontStyleSet::CreateEmpty(); |
50 } | 50 } |
51 | 51 |
52 virtual SkTypeface* onMatchFamilyStyle(const char[], | 52 virtual SkTypeface* onMatchFamilyStyle(const char[], |
53 const SkFontStyle&) const override { | 53 const SkFontStyle&) const override { |
54 return NULL; | 54 return nullptr; |
55 } | 55 } |
56 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], | 56 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], |
57 const SkFontStyle& style, | 57 const SkFontStyle& style, |
58 const char* bcp47[], | 58 const char* bcp47[], |
59 int bcp47Count, | 59 int bcp47Count, |
60 SkUnichar character) const o
verride { | 60 SkUnichar character) const o
verride { |
61 return NULL; | 61 return nullptr; |
62 } | 62 } |
63 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, | 63 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, |
64 const SkFontStyle&) const override { | 64 const SkFontStyle&) const override { |
65 return NULL; | 65 return nullptr; |
66 } | 66 } |
67 SkTypeface* onCreateFromData(SkData*, int) const override { | 67 SkTypeface* onCreateFromData(SkData*, int) const override { |
68 return NULL; | 68 return nullptr; |
69 } | 69 } |
70 SkTypeface* onCreateFromStream(SkStreamAsset* stream, int) const override { | 70 SkTypeface* onCreateFromStream(SkStreamAsset* stream, int) const override { |
71 delete stream; | 71 delete stream; |
72 return NULL; | 72 return nullptr; |
73 } | 73 } |
74 SkTypeface* onCreateFromFile(const char[], int) const override { | 74 SkTypeface* onCreateFromFile(const char[], int) const override { |
75 return NULL; | 75 return nullptr; |
76 } | 76 } |
77 SkTypeface* onLegacyCreateTypeface(const char [], unsigned) const override { | 77 SkTypeface* onLegacyCreateTypeface(const char [], unsigned) const override { |
78 return NULL; | 78 return nullptr; |
79 } | 79 } |
80 }; | 80 }; |
81 | 81 |
82 static SkFontStyleSet* emptyOnNull(SkFontStyleSet* fsset) { | 82 static SkFontStyleSet* emptyOnNull(SkFontStyleSet* fsset) { |
83 if (NULL == fsset) { | 83 if (nullptr == fsset) { |
84 fsset = SkFontStyleSet::CreateEmpty(); | 84 fsset = SkFontStyleSet::CreateEmpty(); |
85 } | 85 } |
86 return fsset; | 86 return fsset; |
87 } | 87 } |
88 | 88 |
89 int SkFontMgr::countFamilies() const { | 89 int SkFontMgr::countFamilies() const { |
90 return this->onCountFamilies(); | 90 return this->onCountFamilies(); |
91 } | 91 } |
92 | 92 |
93 void SkFontMgr::getFamilyName(int index, SkString* familyName) const { | 93 void SkFontMgr::getFamilyName(int index, SkString* familyName) const { |
(...skipping 18 matching lines...) Expand all Loading... |
112 SkUnichar character) const { | 112 SkUnichar character) const { |
113 return this->onMatchFamilyStyleCharacter(familyName, style, bcp47, bcp47Coun
t, character); | 113 return this->onMatchFamilyStyleCharacter(familyName, style, bcp47, bcp47Coun
t, character); |
114 } | 114 } |
115 | 115 |
116 SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face, | 116 SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face, |
117 const SkFontStyle& fs) const { | 117 const SkFontStyle& fs) const { |
118 return this->onMatchFaceStyle(face, fs); | 118 return this->onMatchFaceStyle(face, fs); |
119 } | 119 } |
120 | 120 |
121 SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) const { | 121 SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) const { |
122 if (NULL == data) { | 122 if (nullptr == data) { |
123 return NULL; | 123 return nullptr; |
124 } | 124 } |
125 return this->onCreateFromData(data, ttcIndex); | 125 return this->onCreateFromData(data, ttcIndex); |
126 } | 126 } |
127 | 127 |
128 SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* stream, int ttcIndex) con
st { | 128 SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* stream, int ttcIndex) con
st { |
129 if (NULL == stream) { | 129 if (nullptr == stream) { |
130 return NULL; | 130 return nullptr; |
131 } | 131 } |
132 return this->onCreateFromStream(stream, ttcIndex); | 132 return this->onCreateFromStream(stream, ttcIndex); |
133 } | 133 } |
134 | 134 |
135 SkTypeface* SkFontMgr::createFromFontData(SkFontData* data) const { | 135 SkTypeface* SkFontMgr::createFromFontData(SkFontData* data) const { |
136 if (NULL == data) { | 136 if (nullptr == data) { |
137 return NULL; | 137 return nullptr; |
138 } | 138 } |
139 return this->onCreateFromFontData(data); | 139 return this->onCreateFromFontData(data); |
140 } | 140 } |
141 | 141 |
142 // This implementation is temporary until it can be made pure virtual. | 142 // This implementation is temporary until it can be made pure virtual. |
143 SkTypeface* SkFontMgr::onCreateFromFontData(SkFontData* data) const { | 143 SkTypeface* SkFontMgr::onCreateFromFontData(SkFontData* data) const { |
144 SkTypeface* ret = this->createFromStream(data->detachStream(), data->getInde
x()); | 144 SkTypeface* ret = this->createFromStream(data->detachStream(), data->getInde
x()); |
145 delete data; | 145 delete data; |
146 return ret; | 146 return ret; |
147 } | 147 } |
148 | 148 |
149 SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const { | 149 SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const { |
150 if (NULL == path) { | 150 if (nullptr == path) { |
151 return NULL; | 151 return nullptr; |
152 } | 152 } |
153 return this->onCreateFromFile(path, ttcIndex); | 153 return this->onCreateFromFile(path, ttcIndex); |
154 } | 154 } |
155 | 155 |
156 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], | 156 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], |
157 unsigned styleBits) const { | 157 unsigned styleBits) const { |
158 return this->onLegacyCreateTypeface(familyName, styleBits); | 158 return this->onLegacyCreateTypeface(familyName, styleBits); |
159 } | 159 } |
160 | 160 |
161 // As a template argument this must have external linkage. | 161 // As a template argument this must have external linkage. |
162 SkFontMgr* sk_fontmgr_create_default() { | 162 SkFontMgr* sk_fontmgr_create_default() { |
163 SkFontMgr* fm = SkFontMgr::Factory(); | 163 SkFontMgr* fm = SkFontMgr::Factory(); |
164 return fm ? fm : new SkEmptyFontMgr; | 164 return fm ? fm : new SkEmptyFontMgr; |
165 } | 165 } |
166 | 166 |
167 SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, sk_fontmgr_create_default); | 167 SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, sk_fontmgr_create_default); |
168 | 168 |
169 SkFontMgr* SkFontMgr::RefDefault() { | 169 SkFontMgr* SkFontMgr::RefDefault() { |
170 return SkRef(singleton.get()); | 170 return SkRef(singleton.get()); |
171 } | 171 } |
OLD | NEW |