| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkDataTable.h" | 8 #include "SkDataTable.h" |
| 9 #include "SkFontMgr.h" | 9 #include "SkFontMgr.h" |
| 10 #include "SkFontMgr_indirect.h" | 10 #include "SkFontMgr_indirect.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 SkOnce(&fFamilyNamesInited, &fFamilyNamesMutex, SkFontMgr_Indirect::set_up_f
amily_names, this); | 168 SkOnce(&fFamilyNamesInited, &fFamilyNamesMutex, SkFontMgr_Indirect::set_up_f
amily_names, this); |
| 169 if (index >= fFamilyNames->count()) { | 169 if (index >= fFamilyNames->count()) { |
| 170 familyName->reset(); | 170 familyName->reset(); |
| 171 return; | 171 return; |
| 172 } | 172 } |
| 173 familyName->set(fFamilyNames->atStr(index)); | 173 familyName->set(fFamilyNames->atStr(index)); |
| 174 } | 174 } |
| 175 | 175 |
| 176 SkFontStyleSet* SkFontMgr_Indirect::onCreateStyleSet(int index) const { | 176 SkFontStyleSet* SkFontMgr_Indirect::onCreateStyleSet(int index) const { |
| 177 SkRemotableFontIdentitySet* set = fProxy->getIndex(index); | 177 SkRemotableFontIdentitySet* set = fProxy->getIndex(index); |
| 178 if (NULL == set) { | 178 if (nullptr == set) { |
| 179 return NULL; | 179 return nullptr; |
| 180 } | 180 } |
| 181 return new SkStyleSet_Indirect(this, index, set); | 181 return new SkStyleSet_Indirect(this, index, set); |
| 182 } | 182 } |
| 183 | 183 |
| 184 SkFontStyleSet* SkFontMgr_Indirect::onMatchFamily(const char familyName[]) const
{ | 184 SkFontStyleSet* SkFontMgr_Indirect::onMatchFamily(const char familyName[]) const
{ |
| 185 return new SkStyleSet_Indirect(this, -1, fProxy->matchName(familyName)); | 185 return new SkStyleSet_Indirect(this, -1, fProxy->matchName(familyName)); |
| 186 } | 186 } |
| 187 | 187 |
| 188 SkTypeface* SkFontMgr_Indirect::createTypefaceFromFontId(const SkFontIdentity& i
d) const { | 188 SkTypeface* SkFontMgr_Indirect::createTypefaceFromFontId(const SkFontIdentity& i
d) const { |
| 189 if (id.fDataId == SkFontIdentity::kInvalidDataId) { | 189 if (id.fDataId == SkFontIdentity::kInvalidDataId) { |
| 190 return NULL; | 190 return nullptr; |
| 191 } | 191 } |
| 192 | 192 |
| 193 SkAutoMutexAcquire ama(fDataCacheMutex); | 193 SkAutoMutexAcquire ama(fDataCacheMutex); |
| 194 | 194 |
| 195 SkAutoTUnref<SkTypeface> dataTypeface; | 195 SkAutoTUnref<SkTypeface> dataTypeface; |
| 196 int dataTypefaceIndex = 0; | 196 int dataTypefaceIndex = 0; |
| 197 for (int i = 0; i < fDataCache.count(); ++i) { | 197 for (int i = 0; i < fDataCache.count(); ++i) { |
| 198 const DataEntry& entry = fDataCache[i]; | 198 const DataEntry& entry = fDataCache[i]; |
| 199 if (entry.fDataId == id.fDataId) { | 199 if (entry.fDataId == id.fDataId) { |
| 200 if (entry.fTtcIndex == id.fTtcIndex && | 200 if (entry.fTtcIndex == id.fTtcIndex && |
| 201 !entry.fTypeface->weak_expired() && entry.fTypeface->try_ref()) | 201 !entry.fTypeface->weak_expired() && entry.fTypeface->try_ref()) |
| 202 { | 202 { |
| 203 return entry.fTypeface; | 203 return entry.fTypeface; |
| 204 } | 204 } |
| 205 if (dataTypeface.get() == NULL && | 205 if (dataTypeface.get() == nullptr && |
| 206 !entry.fTypeface->weak_expired() && entry.fTypeface->try_ref()) | 206 !entry.fTypeface->weak_expired() && entry.fTypeface->try_ref()) |
| 207 { | 207 { |
| 208 dataTypeface.reset(entry.fTypeface); | 208 dataTypeface.reset(entry.fTypeface); |
| 209 dataTypefaceIndex = entry.fTtcIndex; | 209 dataTypefaceIndex = entry.fTtcIndex; |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 | 212 |
| 213 if (entry.fTypeface->weak_expired()) { | 213 if (entry.fTypeface->weak_expired()) { |
| 214 fDataCache.removeShuffle(i); | 214 fDataCache.removeShuffle(i); |
| 215 --i; | 215 --i; |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 // No exact match, but did find a data match. | 219 // No exact match, but did find a data match. |
| 220 if (dataTypeface.get() != NULL) { | 220 if (dataTypeface.get() != nullptr) { |
| 221 SkAutoTDelete<SkStreamAsset> stream(dataTypeface->openStream(NULL)); | 221 SkAutoTDelete<SkStreamAsset> stream(dataTypeface->openStream(nullptr)); |
| 222 if (stream.get() != NULL) { | 222 if (stream.get() != nullptr) { |
| 223 return fImpl->createFromStream(stream.detach(), dataTypefaceIndex); | 223 return fImpl->createFromStream(stream.detach(), dataTypefaceIndex); |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 | 226 |
| 227 // No data match, request data and add entry. | 227 // No data match, request data and add entry. |
| 228 SkAutoTDelete<SkStreamAsset> stream(fProxy->getData(id.fDataId)); | 228 SkAutoTDelete<SkStreamAsset> stream(fProxy->getData(id.fDataId)); |
| 229 if (stream.get() == NULL) { | 229 if (stream.get() == nullptr) { |
| 230 return NULL; | 230 return nullptr; |
| 231 } | 231 } |
| 232 | 232 |
| 233 SkAutoTUnref<SkTypeface> typeface(fImpl->createFromStream(stream.detach(), i
d.fTtcIndex)); | 233 SkAutoTUnref<SkTypeface> typeface(fImpl->createFromStream(stream.detach(), i
d.fTtcIndex)); |
| 234 if (typeface.get() == NULL) { | 234 if (typeface.get() == nullptr) { |
| 235 return NULL; | 235 return nullptr; |
| 236 } | 236 } |
| 237 | 237 |
| 238 DataEntry& newEntry = fDataCache.push_back(); | 238 DataEntry& newEntry = fDataCache.push_back(); |
| 239 typeface->weak_ref(); | 239 typeface->weak_ref(); |
| 240 newEntry.fDataId = id.fDataId; | 240 newEntry.fDataId = id.fDataId; |
| 241 newEntry.fTtcIndex = id.fTtcIndex; | 241 newEntry.fTtcIndex = id.fTtcIndex; |
| 242 newEntry.fTypeface = typeface.get(); // weak reference passed to new entry. | 242 newEntry.fTypeface = typeface.get(); // weak reference passed to new entry. |
| 243 | 243 |
| 244 return typeface.detach(); | 244 return typeface.detach(); |
| 245 } | 245 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 bool bold = SkToBool(styleBits & SkTypeface::kBold); | 284 bool bold = SkToBool(styleBits & SkTypeface::kBold); |
| 285 bool italic = SkToBool(styleBits & SkTypeface::kItalic); | 285 bool italic = SkToBool(styleBits & SkTypeface::kItalic); |
| 286 SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight | 286 SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight |
| 287 : SkFontStyle::kNormal_Weight, | 287 : SkFontStyle::kNormal_Weight, |
| 288 SkFontStyle::kNormal_Width, | 288 SkFontStyle::kNormal_Width, |
| 289 italic ? SkFontStyle::kItalic_Slant | 289 italic ? SkFontStyle::kItalic_Slant |
| 290 : SkFontStyle::kUpright_Slant); | 290 : SkFontStyle::kUpright_Slant); |
| 291 | 291 |
| 292 SkAutoTUnref<SkTypeface> face(this->matchFamilyStyle(familyName, style)); | 292 SkAutoTUnref<SkTypeface> face(this->matchFamilyStyle(familyName, style)); |
| 293 | 293 |
| 294 if (NULL == face.get()) { | 294 if (nullptr == face.get()) { |
| 295 face.reset(this->matchFamilyStyle(NULL, style)); | 295 face.reset(this->matchFamilyStyle(nullptr, style)); |
| 296 } | 296 } |
| 297 | 297 |
| 298 if (NULL == face.get()) { | 298 if (nullptr == face.get()) { |
| 299 SkFontIdentity fontId = this->fProxy->matchIndexStyle(0, style); | 299 SkFontIdentity fontId = this->fProxy->matchIndexStyle(0, style); |
| 300 face.reset(this->createTypefaceFromFontId(fontId)); | 300 face.reset(this->createTypefaceFromFontId(fontId)); |
| 301 } | 301 } |
| 302 | 302 |
| 303 return face.detach(); | 303 return face.detach(); |
| 304 } | 304 } |
| OLD | NEW |