OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 Google Inc. | 2 * Copyright 2008 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 "SkFontConfigInterface.h" | 8 #include "SkFontConfigInterface.h" |
9 #include "SkFontConfigTypeface.h" | 9 #include "SkFontConfigTypeface.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 Get().add(face, request); | 159 Get().add(face, request); |
160 } | 160 } |
161 | 161 |
162 /** Does not take ownership of request. */ | 162 /** Does not take ownership of request. */ |
163 static SkTypeface* FindAndRef(Request* request) { | 163 static SkTypeface* FindAndRef(Request* request) { |
164 SkAutoMutexAcquire ama(gSkFontHostRequestCacheMutex); | 164 SkAutoMutexAcquire ama(gSkFontHostRequestCacheMutex); |
165 return Get().findAndRef(request); | 165 return Get().findAndRef(request); |
166 } | 166 } |
167 }; | 167 }; |
168 | 168 |
| 169 #ifdef SK_VERY_LEGACY_CREATE_TYPEFACE |
169 SkTypeface* FontConfigTypeface::LegacyCreateTypeface(const char requestedFamilyN
ame[], | 170 SkTypeface* FontConfigTypeface::LegacyCreateTypeface(const char requestedFamilyN
ame[], |
170 SkTypeface::Style requested
OldStyle) | 171 SkTypeface::Style requested
OldStyle) |
171 { | 172 { |
| 173 SkFontStyle requestedStyle = SkFontStyle::FromOldStyle(requestedOldStyle); |
| 174 #else |
| 175 SkTypeface* FontConfigTypeface::LegacyCreateTypeface(const char requestedFamilyN
ame[], |
| 176 SkFontStyle requestedStyle) |
| 177 { |
| 178 #endif |
172 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); | 179 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); |
173 if (nullptr == fci.get()) { | 180 if (nullptr == fci.get()) { |
174 return nullptr; | 181 return nullptr; |
175 } | 182 } |
176 | 183 |
177 // Check if this request is already in the request cache. | 184 // Check if this request is already in the request cache. |
178 using Request = SkFontHostRequestCache::Request; | 185 using Request = SkFontHostRequestCache::Request; |
179 SkFontStyle requestedStyle(requestedOldStyle); | |
180 SkAutoTDelete<Request> request(Request::Create(requestedFamilyName, requeste
dStyle)); | 186 SkAutoTDelete<Request> request(Request::Create(requestedFamilyName, requeste
dStyle)); |
181 SkTypeface* face = SkFontHostRequestCache::FindAndRef(request); | 187 SkTypeface* face = SkFontHostRequestCache::FindAndRef(request); |
182 if (face) { | 188 if (face) { |
183 return face; | 189 return face; |
184 } | 190 } |
185 | 191 |
186 SkFontConfigInterface::FontIdentity identity; | 192 SkFontConfigInterface::FontIdentity identity; |
187 SkString outFamilyName; | 193 SkString outFamilyName; |
188 SkTypeface::Style outOldStyle; | 194 #ifdef SK_VERY_LEGACY_CREATE_TYPEFACE |
| 195 SkTypeface::Style outStyle; |
189 if (!fci->matchFamilyName(requestedFamilyName, requestedOldStyle, | 196 if (!fci->matchFamilyName(requestedFamilyName, requestedOldStyle, |
190 &identity, &outFamilyName, &outOldStyle)) | 197 #else |
| 198 SkFontStyle outStyle; |
| 199 if (!fci->matchFamilyName(requestedFamilyName, requestedStyle, |
| 200 #endif |
| 201 &identity, &outFamilyName, &outStyle)) |
191 { | 202 { |
192 return nullptr; | 203 return nullptr; |
193 } | 204 } |
194 | 205 |
195 // Check if a typeface with this FontIdentity is already in the FontIdentity
cache. | 206 // Check if a typeface with this FontIdentity is already in the FontIdentity
cache. |
196 face = SkTypefaceCache::FindByProcAndRef(find_by_FontIdentity, &identity); | 207 face = SkTypefaceCache::FindByProcAndRef(find_by_FontIdentity, &identity); |
197 if (!face) { | 208 if (!face) { |
198 face = FontConfigTypeface::Create(SkFontStyle(outOldStyle), identity, ou
tFamilyName); | 209 #ifdef SK_VERY_LEGACY_CREATE_TYPEFACE |
| 210 face = FontConfigTypeface::Create(SkFontStyle::FromOldStyle(outStyle), i
dentity, outFamilyName); |
199 // Add this FontIdentity to the FontIdentity cache. | 211 // Add this FontIdentity to the FontIdentity cache. |
200 SkTypefaceCache::Add(face, SkFontStyle(outOldStyle)); | 212 SkTypefaceCache::Add(face, SkFontStyle::FromOldStyle(outStyle)); |
| 213 #else |
| 214 face = FontConfigTypeface::Create(outStyle, identity, outFamilyName); |
| 215 // Add this FontIdentity to the FontIdentity cache. |
| 216 SkTypefaceCache::Add(face, outStyle); |
| 217 #endif |
201 } | 218 } |
202 // Add this request to the request cache. | 219 // Add this request to the request cache. |
203 SkFontHostRequestCache::Add(face, request.release()); | 220 SkFontHostRequestCache::Add(face, request.release()); |
204 | 221 |
205 return face; | 222 return face; |
206 } | 223 } |
207 | 224 |
208 /////////////////////////////////////////////////////////////////////////////// | 225 /////////////////////////////////////////////////////////////////////////////// |
209 | 226 |
210 SkStreamAsset* FontConfigTypeface::onOpenStream(int* ttcIndex) const { | 227 SkStreamAsset* FontConfigTypeface::onOpenStream(int* ttcIndex) const { |
(...skipping 17 matching lines...) Expand all Loading... |
228 *familyName = fFamilyName; | 245 *familyName = fFamilyName; |
229 } | 246 } |
230 | 247 |
231 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, | 248 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
232 bool* isLocalStream) const { | 249 bool* isLocalStream) const { |
233 SkString name; | 250 SkString name; |
234 this->getFamilyName(&name); | 251 this->getFamilyName(&name); |
235 desc->setFamilyName(name.c_str()); | 252 desc->setFamilyName(name.c_str()); |
236 *isLocalStream = SkToBool(this->getLocalStream()); | 253 *isLocalStream = SkToBool(this->getLocalStream()); |
237 } | 254 } |
OLD | NEW |