epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Ben Wagner | fc49734 | 2017-02-24 11:15:26 -0500 | [diff] [blame] | 8 | #include "SkFontArguments.h" |
djsollen@google.com | 9714516 | 2012-05-31 19:55:08 +0000 | [diff] [blame] | 9 | #include "SkFontDescriptor.h" |
bungeman | f20488b | 2015-07-29 11:49:40 -0700 | [diff] [blame] | 10 | #include "SkFontHost_FreeType_common.h" |
bungeman@google.com | b3d154d | 2013-11-11 15:53:29 +0000 | [diff] [blame] | 11 | #include "SkFontMgr.h" |
bungeman | 5cf1949 | 2015-06-15 15:17:21 -0700 | [diff] [blame] | 12 | #include "SkFontMgr_custom.h" |
bungeman | f20488b | 2015-07-29 11:49:40 -0700 | [diff] [blame] | 13 | #include "SkFontStyle.h" |
bungeman | f93d711 | 2016-09-16 06:24:20 -0700 | [diff] [blame] | 14 | #include "SkMakeUnique.h" |
bungeman | f20488b | 2015-07-29 11:49:40 -0700 | [diff] [blame] | 15 | #include "SkRefCnt.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | #include "SkStream.h" |
bungeman | f20488b | 2015-07-29 11:49:40 -0700 | [diff] [blame] | 17 | #include "SkString.h" |
bungeman@google.com | b3d154d | 2013-11-11 15:53:29 +0000 | [diff] [blame] | 18 | #include "SkTArray.h" |
bungeman | f20488b | 2015-07-29 11:49:40 -0700 | [diff] [blame] | 19 | #include "SkTemplates.h" |
| 20 | #include "SkTypeface.h" |
bungeman | f20488b | 2015-07-29 11:49:40 -0700 | [diff] [blame] | 21 | #include "SkTypes.h" |
bungeman@google.com | b3d154d | 2013-11-11 15:53:29 +0000 | [diff] [blame] | 22 | |
| 23 | #include <limits> |
bungeman | 4772bd5 | 2016-06-10 04:14:51 -0700 | [diff] [blame] | 24 | #include <memory> |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | |
bungeman | f20488b | 2015-07-29 11:49:40 -0700 | [diff] [blame] | 26 | class SkData; |
| 27 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 28 | SkTypeface_Custom::SkTypeface_Custom(const SkFontStyle& style, bool isFixedPitch, |
| 29 | bool sysFont, const SkString familyName, int index) |
| 30 | : INHERITED(style, isFixedPitch) |
| 31 | , fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index) |
| 32 | { } |
chudy@google.com | ada4480 | 2012-07-30 12:59:12 +0000 | [diff] [blame] | 33 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 34 | bool SkTypeface_Custom::isSysFont() const { return fIsSysFont; } |
reed@google.com | 292b1d4 | 2013-03-22 17:21:59 +0000 | [diff] [blame] | 35 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 36 | void SkTypeface_Custom::onGetFamilyName(SkString* familyName) const { |
| 37 | *familyName = fFamilyName; |
| 38 | } |
bungeman | b374d6a | 2014-09-17 07:48:59 -0700 | [diff] [blame] | 39 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 40 | void SkTypeface_Custom::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const { |
| 41 | desc->setFamilyName(fFamilyName.c_str()); |
| 42 | desc->setStyle(this->fontStyle()); |
| 43 | *isLocal = !this->isSysFont(); |
| 44 | } |
reed@google.com | 5526ede | 2013-03-25 13:03:37 +0000 | [diff] [blame] | 45 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 46 | int SkTypeface_Custom::getIndex() const { return fIndex; } |
bungeman | d71b757 | 2014-09-18 10:55:32 -0700 | [diff] [blame] | 47 | |
chudy@google.com | ada4480 | 2012-07-30 12:59:12 +0000 | [diff] [blame] | 48 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 49 | SkTypeface_Empty::SkTypeface_Empty() : INHERITED(SkFontStyle(), false, true, SkString(), 0) {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 50 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 51 | SkStreamAsset* SkTypeface_Empty::onOpenStream(int*) const { return nullptr; } |
chudy@google.com | ada4480 | 2012-07-30 12:59:12 +0000 | [diff] [blame] | 52 | |
Bruce Wang | 0ea256c | 2018-06-22 15:44:47 -0400 | [diff] [blame] | 53 | sk_sp<SkTypeface> SkTypeface_Empty::onMakeClone(const SkFontArguments& args) const { |
| 54 | return sk_ref_sp(this); |
| 55 | } |
reed@google.com | 292b1d4 | 2013-03-22 17:21:59 +0000 | [diff] [blame] | 56 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 57 | SkTypeface_Stream::SkTypeface_Stream(std::unique_ptr<SkFontData> fontData, |
| 58 | const SkFontStyle& style, bool isFixedPitch, bool sysFont, |
| 59 | const SkString familyName) |
| 60 | : INHERITED(style, isFixedPitch, sysFont, familyName, fontData->getIndex()) |
| 61 | , fData(std::move(fontData)) |
| 62 | { } |
reed@android.com | f244f1b | 2010-04-16 12:40:08 +0000 | [diff] [blame] | 63 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 64 | SkStreamAsset* SkTypeface_Stream::onOpenStream(int* ttcIndex) const { |
| 65 | *ttcIndex = fData->getIndex(); |
Mike Reed | 98c5d92 | 2017-09-15 21:39:47 -0400 | [diff] [blame] | 66 | return fData->getStream()->duplicate().release(); |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 67 | } |
chudy@google.com | ada4480 | 2012-07-30 12:59:12 +0000 | [diff] [blame] | 68 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 69 | std::unique_ptr<SkFontData> SkTypeface_Stream::onMakeFontData() const { |
| 70 | return skstd::make_unique<SkFontData>(*fData); |
| 71 | } |
bungeman | 4772bd5 | 2016-06-10 04:14:51 -0700 | [diff] [blame] | 72 | |
Bruce Wang | 0ea256c | 2018-06-22 15:44:47 -0400 | [diff] [blame] | 73 | sk_sp<SkTypeface> SkTypeface_Stream::onMakeClone(const SkFontArguments& args) const { |
| 74 | std::unique_ptr<SkFontData> data = this->cloneFontData(args); |
| 75 | if (!data) { |
| 76 | return nullptr; |
| 77 | } |
| 78 | |
| 79 | SkString familyName; |
| 80 | this->getFamilyName(&familyName); |
| 81 | |
| 82 | return sk_make_sp<SkTypeface_Stream>(std::move(data), |
| 83 | this->fontStyle(), |
| 84 | this->isFixedPitch(), |
| 85 | this->isSysFont(), |
| 86 | familyName); |
| 87 | } |
reed@google.com | 292b1d4 | 2013-03-22 17:21:59 +0000 | [diff] [blame] | 88 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 89 | SkTypeface_File::SkTypeface_File(const SkFontStyle& style, bool isFixedPitch, bool sysFont, |
| 90 | const SkString familyName, const char path[], int index) |
| 91 | : INHERITED(style, isFixedPitch, sysFont, familyName, index) |
| 92 | , fPath(path) |
| 93 | { } |
chudy@google.com | ada4480 | 2012-07-30 12:59:12 +0000 | [diff] [blame] | 94 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 95 | SkStreamAsset* SkTypeface_File::onOpenStream(int* ttcIndex) const { |
| 96 | *ttcIndex = this->getIndex(); |
| 97 | return SkStream::MakeFromFile(fPath.c_str()).release(); |
| 98 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 99 | |
Bruce Wang | 0ea256c | 2018-06-22 15:44:47 -0400 | [diff] [blame] | 100 | sk_sp<SkTypeface> SkTypeface_File::onMakeClone(const SkFontArguments& args) const { |
| 101 | std::unique_ptr<SkFontData> data = this->cloneFontData(args); |
| 102 | if (!data) { |
| 103 | return nullptr; |
| 104 | } |
| 105 | |
| 106 | SkString familyName; |
| 107 | this->getFamilyName(&familyName); |
| 108 | |
| 109 | return sk_make_sp<SkTypeface_Stream>(std::move(data), |
| 110 | this->fontStyle(), |
| 111 | this->isFixedPitch(), |
| 112 | this->isSysFont(), |
| 113 | familyName); |
| 114 | } |
| 115 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 116 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 117 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 118 | SkFontStyleSet_Custom::SkFontStyleSet_Custom(const SkString familyName) : fFamilyName(familyName) {} |
bungeman@google.com | b3d154d | 2013-11-11 15:53:29 +0000 | [diff] [blame] | 119 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 120 | void SkFontStyleSet_Custom::appendTypeface(sk_sp<SkTypeface_Custom> typeface) { |
| 121 | fStyles.emplace_back(std::move(typeface)); |
| 122 | } |
| 123 | |
| 124 | int SkFontStyleSet_Custom::count() { |
| 125 | return fStyles.count(); |
| 126 | } |
| 127 | |
| 128 | void SkFontStyleSet_Custom::getStyle(int index, SkFontStyle* style, SkString* name) { |
| 129 | SkASSERT(index < fStyles.count()); |
| 130 | if (style) { |
| 131 | *style = fStyles[index]->fontStyle(); |
bungeman | 5c9fa28 | 2015-03-30 12:53:48 -0700 | [diff] [blame] | 132 | } |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 133 | if (name) { |
| 134 | name->reset(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 135 | } |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 136 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 137 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 138 | SkTypeface* SkFontStyleSet_Custom::createTypeface(int index) { |
| 139 | SkASSERT(index < fStyles.count()); |
| 140 | return SkRef(fStyles[index].get()); |
| 141 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 142 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 143 | SkTypeface* SkFontStyleSet_Custom::matchStyle(const SkFontStyle& pattern) { |
| 144 | return this->matchStyleCSS3(pattern); |
| 145 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 146 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 147 | SkString SkFontStyleSet_Custom::getFamilyName() { return fFamilyName; } |
bungeman@google.com | b3d154d | 2013-11-11 15:53:29 +0000 | [diff] [blame] | 148 | |
bungeman | 5c9fa28 | 2015-03-30 12:53:48 -0700 | [diff] [blame] | 149 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 150 | SkFontMgr_Custom::SkFontMgr_Custom(const SystemFontLoader& loader) : fDefaultFamily(nullptr) { |
| 151 | loader.loadSystemFonts(fScanner, &fFamilies); |
bungeman@google.com | b3d154d | 2013-11-11 15:53:29 +0000 | [diff] [blame] | 152 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 153 | // Try to pick a default font. |
| 154 | static const char* defaultNames[] = { |
| 155 | "Arial", "Verdana", "Times New Roman", "Droid Sans", nullptr |
bungeman | 5c9fa28 | 2015-03-30 12:53:48 -0700 | [diff] [blame] | 156 | }; |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 157 | for (size_t i = 0; i < SK_ARRAY_COUNT(defaultNames); ++i) { |
| 158 | sk_sp<SkFontStyleSet_Custom> set(this->onMatchFamily(defaultNames[i])); |
| 159 | if (nullptr == set) { |
| 160 | continue; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 161 | } |
bungeman | 4772bd5 | 2016-06-10 04:14:51 -0700 | [diff] [blame] | 162 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 163 | sk_sp<SkTypeface> tf(set->matchStyle(SkFontStyle(SkFontStyle::kNormal_Weight, |
| 164 | SkFontStyle::kNormal_Width, |
| 165 | SkFontStyle::kUpright_Slant))); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 166 | if (nullptr == tf) { |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 167 | continue; |
bungeman@google.com | b3d154d | 2013-11-11 15:53:29 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 170 | fDefaultFamily = set.get(); |
| 171 | break; |
bungeman@google.com | 2cf84ec | 2012-09-26 19:16:54 +0000 | [diff] [blame] | 172 | } |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 173 | if (nullptr == fDefaultFamily) { |
| 174 | fDefaultFamily = fFamilies[0].get(); |
| 175 | } |
| 176 | } |
bungeman@google.com | 2cf84ec | 2012-09-26 19:16:54 +0000 | [diff] [blame] | 177 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 178 | int SkFontMgr_Custom::onCountFamilies() const { |
| 179 | return fFamilies.count(); |
| 180 | } |
bungeman@google.com | 2cf84ec | 2012-09-26 19:16:54 +0000 | [diff] [blame] | 181 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 182 | void SkFontMgr_Custom::onGetFamilyName(int index, SkString* familyName) const { |
| 183 | SkASSERT(index < fFamilies.count()); |
| 184 | familyName->set(fFamilies[index]->getFamilyName()); |
| 185 | } |
bungeman | 5c9fa28 | 2015-03-30 12:53:48 -0700 | [diff] [blame] | 186 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 187 | SkFontStyleSet_Custom* SkFontMgr_Custom::onCreateStyleSet(int index) const { |
| 188 | SkASSERT(index < fFamilies.count()); |
| 189 | return SkRef(fFamilies[index].get()); |
| 190 | } |
bungeman | 5c9fa28 | 2015-03-30 12:53:48 -0700 | [diff] [blame] | 191 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 192 | SkFontStyleSet_Custom* SkFontMgr_Custom::onMatchFamily(const char familyName[]) const { |
| 193 | for (int i = 0; i < fFamilies.count(); ++i) { |
| 194 | if (fFamilies[i]->getFamilyName().equals(familyName)) { |
| 195 | return SkRef(fFamilies[i].get()); |
bungeman | 5c9fa28 | 2015-03-30 12:53:48 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 198 | return nullptr; |
| 199 | } |
bungeman | 5c9fa28 | 2015-03-30 12:53:48 -0700 | [diff] [blame] | 200 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 201 | SkTypeface* SkFontMgr_Custom::onMatchFamilyStyle(const char familyName[], |
| 202 | const SkFontStyle& fontStyle) const |
| 203 | { |
| 204 | sk_sp<SkFontStyleSet> sset(this->matchFamily(familyName)); |
| 205 | return sset->matchStyle(fontStyle); |
| 206 | } |
| 207 | |
| 208 | SkTypeface* SkFontMgr_Custom::onMatchFamilyStyleCharacter(const char familyName[], |
| 209 | const SkFontStyle&, |
| 210 | const char* bcp47[], int bcp47Count, |
| 211 | SkUnichar character) const |
| 212 | { |
| 213 | return nullptr; |
| 214 | } |
| 215 | |
| 216 | SkTypeface* SkFontMgr_Custom::onMatchFaceStyle(const SkTypeface* familyMember, |
| 217 | const SkFontStyle& fontStyle) const |
| 218 | { |
| 219 | for (int i = 0; i < fFamilies.count(); ++i) { |
| 220 | for (int j = 0; j < fFamilies[i]->fStyles.count(); ++j) { |
| 221 | if (fFamilies[i]->fStyles[j].get() == familyMember) { |
| 222 | return fFamilies[i]->matchStyle(fontStyle); |
bungeman | 5c9fa28 | 2015-03-30 12:53:48 -0700 | [diff] [blame] | 223 | } |
| 224 | } |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 225 | } |
| 226 | return nullptr; |
| 227 | } |
| 228 | |
Mike Reed | 5922739 | 2017-09-26 09:46:08 -0400 | [diff] [blame] | 229 | sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromData(sk_sp<SkData> data, int ttcIndex) const { |
| 230 | return this->makeFromStream(skstd::make_unique<SkMemoryStream>(std::move(data)), ttcIndex); |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 231 | } |
| 232 | |
Mike Reed | 5922739 | 2017-09-26 09:46:08 -0400 | [diff] [blame] | 233 | sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream, |
| 234 | int ttcIndex) const { |
| 235 | return this->makeFromStream(std::move(stream), SkFontArguments().setCollectionIndex(ttcIndex)); |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 236 | } |
| 237 | |
Mike Reed | 5922739 | 2017-09-26 09:46:08 -0400 | [diff] [blame] | 238 | sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream, |
| 239 | const SkFontArguments& args) const { |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 240 | using Scanner = SkTypeface_FreeType::Scanner; |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 241 | bool isFixedPitch; |
| 242 | SkFontStyle style; |
| 243 | SkString name; |
| 244 | Scanner::AxisDefinitions axisDefinitions; |
Ben Wagner | fc49734 | 2017-02-24 11:15:26 -0500 | [diff] [blame] | 245 | if (!fScanner.scanFont(stream.get(), args.getCollectionIndex(), |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 246 | &name, &style, &isFixedPitch, &axisDefinitions)) |
| 247 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 248 | return nullptr; |
bungeman | 5c9fa28 | 2015-03-30 12:53:48 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Ben Wagner | fc49734 | 2017-02-24 11:15:26 -0500 | [diff] [blame] | 251 | const SkFontArguments::VariationPosition position = args.getVariationDesignPosition(); |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 252 | SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count()); |
Ben Wagner | fc49734 | 2017-02-24 11:15:26 -0500 | [diff] [blame] | 253 | Scanner::computeAxisValues(axisDefinitions, position, axisValues, name); |
bungeman@google.com | b3d154d | 2013-11-11 15:53:29 +0000 | [diff] [blame] | 254 | |
Ben Wagner | fc49734 | 2017-02-24 11:15:26 -0500 | [diff] [blame] | 255 | auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(), |
| 256 | axisValues.get(), axisDefinitions.count()); |
Mike Reed | 5922739 | 2017-09-26 09:46:08 -0400 | [diff] [blame] | 257 | return sk_sp<SkTypeface>(new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name)); |
Ben Wagner | 3546ff1 | 2017-01-03 13:32:36 -0500 | [diff] [blame] | 258 | } |
bungeman | 5cf1949 | 2015-06-15 15:17:21 -0700 | [diff] [blame] | 259 | |
Mike Reed | 5922739 | 2017-09-26 09:46:08 -0400 | [diff] [blame] | 260 | sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromFontData(std::unique_ptr<SkFontData> data) const { |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 261 | bool isFixedPitch; |
| 262 | SkFontStyle style; |
| 263 | SkString name; |
| 264 | if (!fScanner.scanFont(data->getStream(), data->getIndex(), |
Mike Reed | 5922739 | 2017-09-26 09:46:08 -0400 | [diff] [blame] | 265 | &name, &style, &isFixedPitch, nullptr)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 266 | return nullptr; |
bungeman | 5c9fa28 | 2015-03-30 12:53:48 -0700 | [diff] [blame] | 267 | } |
Mike Reed | 5922739 | 2017-09-26 09:46:08 -0400 | [diff] [blame] | 268 | return sk_sp<SkTypeface>(new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name)); |
Ben Wagner | 3546ff1 | 2017-01-03 13:32:36 -0500 | [diff] [blame] | 269 | } |
caryclark | fe7ada7 | 2016-03-21 06:55:52 -0700 | [diff] [blame] | 270 | |
Mike Reed | 5922739 | 2017-09-26 09:46:08 -0400 | [diff] [blame] | 271 | sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromFile(const char path[], int ttcIndex) const { |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 272 | std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path); |
Mike Reed | 5922739 | 2017-09-26 09:46:08 -0400 | [diff] [blame] | 273 | return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr; |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 274 | } |
caryclark | fe7ada7 | 2016-03-21 06:55:52 -0700 | [diff] [blame] | 275 | |
Mike Reed | 5922739 | 2017-09-26 09:46:08 -0400 | [diff] [blame] | 276 | sk_sp<SkTypeface> SkFontMgr_Custom::onLegacyMakeTypeface(const char familyName[], |
| 277 | SkFontStyle style) const { |
| 278 | sk_sp<SkTypeface> tf; |
caryclark | fe7ada7 | 2016-03-21 06:55:52 -0700 | [diff] [blame] | 279 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 280 | if (familyName) { |
Mike Reed | 5922739 | 2017-09-26 09:46:08 -0400 | [diff] [blame] | 281 | tf.reset(this->onMatchFamilyStyle(familyName, style)); |
caryclark | fe7ada7 | 2016-03-21 06:55:52 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 284 | if (nullptr == tf) { |
Mike Reed | 5922739 | 2017-09-26 09:46:08 -0400 | [diff] [blame] | 285 | tf.reset(fDefaultFamily->matchStyle(style)); |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 286 | } |
caryclark | fe7ada7 | 2016-03-21 06:55:52 -0700 | [diff] [blame] | 287 | |
Ben Wagner | 8ab590f | 2017-02-08 17:29:33 -0500 | [diff] [blame] | 288 | return tf; |
Ben Wagner | 3546ff1 | 2017-01-03 13:32:36 -0500 | [diff] [blame] | 289 | } |