| 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 "SkFontMgr.h" | 9 #include "SkFontMgr.h" |
| 9 #include "SkLazyPtr.h" | 10 #include "SkLazyPtr.h" |
| 10 #include "SkStream.h" | 11 #include "SkStream.h" |
| 11 #include "SkTypes.h" | 12 #include "SkTypes.h" |
| 12 | 13 |
| 13 class SkFontStyle; | 14 class SkFontStyle; |
| 14 class SkTypeface; | 15 class SkTypeface; |
| 15 | 16 |
| 16 class SkEmptyFontStyleSet : public SkFontStyleSet { | 17 class SkEmptyFontStyleSet : public SkFontStyleSet { |
| 17 public: | 18 public: |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 return this->onCreateFromData(data, ttcIndex); | 127 return this->onCreateFromData(data, ttcIndex); |
| 127 } | 128 } |
| 128 | 129 |
| 129 SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* stream, int ttcIndex) con
st { | 130 SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* stream, int ttcIndex) con
st { |
| 130 if (NULL == stream) { | 131 if (NULL == stream) { |
| 131 return NULL; | 132 return NULL; |
| 132 } | 133 } |
| 133 return this->onCreateFromStream(stream, ttcIndex); | 134 return this->onCreateFromStream(stream, ttcIndex); |
| 134 } | 135 } |
| 135 | 136 |
| 137 SkTypeface* SkFontMgr::createFromFontData(SkFontData* data) const { |
| 138 if (NULL == data) { |
| 139 return NULL; |
| 140 } |
| 141 return this->onCreateFromFontData(data); |
| 142 } |
| 143 |
| 144 // This implementation is temporary until it can be made pure virtual. |
| 145 SkTypeface* SkFontMgr::onCreateFromFontData(SkFontData* data) const { |
| 146 SkTypeface* ret = this->createFromStream(data->detachStream(), data->getInde
x()); |
| 147 delete data; |
| 148 return ret; |
| 149 } |
| 150 |
| 136 SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const { | 151 SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const { |
| 137 if (NULL == path) { | 152 if (NULL == path) { |
| 138 return NULL; | 153 return NULL; |
| 139 } | 154 } |
| 140 return this->onCreateFromFile(path, ttcIndex); | 155 return this->onCreateFromFile(path, ttcIndex); |
| 141 } | 156 } |
| 142 | 157 |
| 143 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], | 158 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], |
| 144 unsigned styleBits) const { | 159 unsigned styleBits) const { |
| 145 return this->onLegacyCreateTypeface(familyName, styleBits); | 160 return this->onLegacyCreateTypeface(familyName, styleBits); |
| 146 } | 161 } |
| 147 | 162 |
| 148 // As a template argument this must have external linkage. | 163 // As a template argument this must have external linkage. |
| 149 SkFontMgr* sk_fontmgr_create_default() { | 164 SkFontMgr* sk_fontmgr_create_default() { |
| 150 SkFontMgr* fm = SkFontMgr::Factory(); | 165 SkFontMgr* fm = SkFontMgr::Factory(); |
| 151 return fm ? fm : SkNEW(SkEmptyFontMgr); | 166 return fm ? fm : SkNEW(SkEmptyFontMgr); |
| 152 } | 167 } |
| 153 | 168 |
| 154 SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, sk_fontmgr_create_default); | 169 SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, sk_fontmgr_create_default); |
| 155 | 170 |
| 156 SkFontMgr* SkFontMgr::RefDefault() { | 171 SkFontMgr* SkFontMgr::RefDefault() { |
| 157 return SkRef(singleton.get()); | 172 return SkRef(singleton.get()); |
| 158 } | 173 } |
| OLD | NEW |