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