Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(843)

Side by Side Diff: src/ports/SkFontMgr_custom.cpp

Issue 2053903003: Implement all onCreateFromStream overloads. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkFontDescriptor.h"
9 #include "SkFontHost_FreeType_common.h" 9 #include "SkFontHost_FreeType_common.h"
10 #include "SkFontMgr.h" 10 #include "SkFontMgr.h"
11 #include "SkFontMgr_custom.h" 11 #include "SkFontMgr_custom.h"
12 #include "SkFontStyle.h" 12 #include "SkFontStyle.h"
13 #include "SkOSFile.h" 13 #include "SkOSFile.h"
14 #include "SkRefCnt.h" 14 #include "SkRefCnt.h"
15 #include "SkStream.h" 15 #include "SkStream.h"
16 #include "SkString.h" 16 #include "SkString.h"
17 #include "SkTArray.h" 17 #include "SkTArray.h"
18 #include "SkTemplates.h" 18 #include "SkTemplates.h"
19 #include "SkTypeface.h" 19 #include "SkTypeface.h"
20 #include "SkTypefaceCache.h" 20 #include "SkTypefaceCache.h"
21 #include "SkTypes.h" 21 #include "SkTypes.h"
22 22
23 #include <limits> 23 #include <limits>
24 #include <memory>
24 25
25 class SkData; 26 class SkData;
26 27
27 /** The base SkTypeface implementation for the custom font manager. */ 28 /** The base SkTypeface implementation for the custom font manager. */
28 class SkTypeface_Custom : public SkTypeface_FreeType { 29 class SkTypeface_Custom : public SkTypeface_FreeType {
29 public: 30 public:
30 SkTypeface_Custom(const SkFontStyle& style, bool isFixedPitch, 31 SkTypeface_Custom(const SkFontStyle& style, bool isFixedPitch,
31 bool sysFont, const SkString familyName, int index) 32 bool sysFont, const SkString familyName, int index)
32 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) 33 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
33 , fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index) 34 , fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 protected: 66 protected:
66 SkStreamAsset* onOpenStream(int*) const override { return nullptr; } 67 SkStreamAsset* onOpenStream(int*) const override { return nullptr; }
67 68
68 private: 69 private:
69 typedef SkTypeface_Custom INHERITED; 70 typedef SkTypeface_Custom INHERITED;
70 }; 71 };
71 72
72 /** The stream SkTypeface implementation for the custom font manager. */ 73 /** The stream SkTypeface implementation for the custom font manager. */
73 class SkTypeface_Stream : public SkTypeface_Custom { 74 class SkTypeface_Stream : public SkTypeface_Custom {
74 public: 75 public:
75 SkTypeface_Stream(const SkFontStyle& style, bool isFixedPitch, bool sysFont, 76 SkTypeface_Stream(std::unique_ptr<SkFontData> fontData,
76 const SkString familyName, SkStreamAsset* stream, int inde x) 77 const SkFontStyle& style, bool isFixedPitch, bool sysFont,
77 : INHERITED(style, isFixedPitch, sysFont, familyName, index) 78 const SkString familyName)
78 , fStream(stream) 79 : INHERITED(style, isFixedPitch, sysFont, familyName, fontData->getIndex ())
80 , fData(std::move(fontData))
79 { } 81 { }
80 82
81 protected: 83 protected:
82 SkStreamAsset* onOpenStream(int* ttcIndex) const override { 84 SkStreamAsset* onOpenStream(int* ttcIndex) const override {
83 *ttcIndex = this->getIndex(); 85 *ttcIndex = fData->getIndex();
84 return fStream->duplicate(); 86 return fData->duplicateStream();
87 }
88
89 SkFontData* onCreateFontData() const override {
90 return new SkFontData(*fData.get());
85 } 91 }
86 92
87 private: 93 private:
88 const SkAutoTDelete<const SkStreamAsset> fStream; 94 std::unique_ptr<const SkFontData> fData;
89 95
90 typedef SkTypeface_Custom INHERITED; 96 typedef SkTypeface_Custom INHERITED;
91 }; 97 };
92 98
93 /** The file SkTypeface implementation for the custom font manager. */ 99 /** The file SkTypeface implementation for the custom font manager. */
94 class SkTypeface_File : public SkTypeface_Custom { 100 class SkTypeface_File : public SkTypeface_Custom {
95 public: 101 public:
96 SkTypeface_File(const SkFontStyle& style, bool isFixedPitch, bool sysFont, 102 SkTypeface_File(const SkFontStyle& style, bool isFixedPitch, bool sysFont,
97 const SkString familyName, const char path[], int index) 103 const SkString familyName, const char path[], int index)
98 : INHERITED(style, isFixedPitch, sysFont, familyName, index) 104 : INHERITED(style, isFixedPitch, sysFont, familyName, index)
(...skipping 17 matching lines...) Expand all
116 /** 122 /**
117 * SkFontStyleSet_Custom 123 * SkFontStyleSet_Custom
118 * 124 *
119 * This class is used by SkFontMgr_Custom to hold SkTypeface_Custom families. 125 * This class is used by SkFontMgr_Custom to hold SkTypeface_Custom families.
120 */ 126 */
121 class SkFontStyleSet_Custom : public SkFontStyleSet { 127 class SkFontStyleSet_Custom : public SkFontStyleSet {
122 public: 128 public:
123 explicit SkFontStyleSet_Custom(const SkString familyName) : fFamilyName(fami lyName) { } 129 explicit SkFontStyleSet_Custom(const SkString familyName) : fFamilyName(fami lyName) { }
124 130
125 /** Should only be called during the inital build phase. */ 131 /** Should only be called during the inital build phase. */
126 void appendTypeface(SkTypeface_Custom* typeface) { 132 void appendTypeface(sk_sp<SkTypeface_Custom> typeface) {
127 fStyles.push_back().reset(typeface); 133 fStyles.emplace_back(std::move(typeface));
128 } 134 }
129 135
130 int count() override { 136 int count() override {
131 return fStyles.count(); 137 return fStyles.count();
132 } 138 }
133 139
134 void getStyle(int index, SkFontStyle* style, SkString* name) override { 140 void getStyle(int index, SkFontStyle* style, SkString* name) override {
135 SkASSERT(index < fStyles.count()); 141 SkASSERT(index < fStyles.count());
136 if (style) { 142 if (style) {
137 *style = fStyles[index]->fontStyle(); 143 *style = fStyles[index]->fontStyle();
138 } 144 }
139 if (name) { 145 if (name) {
140 name->reset(); 146 name->reset();
141 } 147 }
142 } 148 }
143 149
144 SkTypeface* createTypeface(int index) override { 150 SkTypeface* createTypeface(int index) override {
145 SkASSERT(index < fStyles.count()); 151 SkASSERT(index < fStyles.count());
146 return SkRef(fStyles[index].get()); 152 return SkRef(fStyles[index].get());
147 } 153 }
148 154
149 SkTypeface* matchStyle(const SkFontStyle& pattern) override { 155 SkTypeface* matchStyle(const SkFontStyle& pattern) override {
150 return this->matchStyleCSS3(pattern); 156 return this->matchStyleCSS3(pattern);
151 } 157 }
152 158
153 SkString getFamilyName() { return fFamilyName; } 159 SkString getFamilyName() { return fFamilyName; }
154 160
155 private: 161 private:
156 SkTArray<SkAutoTUnref<SkTypeface_Custom>, true> fStyles; 162 SkTArray<sk_sp<SkTypeface_Custom>> fStyles;
157 SkString fFamilyName; 163 SkString fFamilyName;
158 164
159 friend class SkFontMgr_Custom; 165 friend class SkFontMgr_Custom;
160 }; 166 };
161 167
162 /** 168 /**
163 * SkFontMgr_Custom 169 * SkFontMgr_Custom
164 * 170 *
165 * This class is essentially a collection of SkFontStyleSet_Custom, 171 * This class is essentially a collection of SkFontStyleSet_Custom,
166 * one SkFontStyleSet_Custom for each family. This class may be modified 172 * one SkFontStyleSet_Custom for each family. This class may be modified
167 * to load fonts from any source by changing the initialization. 173 * to load fonts from any source by changing the initialization.
168 */ 174 */
169 class SkFontMgr_Custom : public SkFontMgr { 175 class SkFontMgr_Custom : public SkFontMgr {
170 public: 176 public:
171 typedef SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> Families; 177 typedef SkTArray<sk_sp<SkFontStyleSet_Custom>> Families;
172 class SystemFontLoader { 178 class SystemFontLoader {
173 public: 179 public:
174 virtual ~SystemFontLoader() { } 180 virtual ~SystemFontLoader() { }
175 virtual void loadSystemFonts(const SkTypeface_FreeType::Scanner&, Famili es*) const = 0; 181 virtual void loadSystemFonts(const SkTypeface_FreeType::Scanner&, Famili es*) const = 0;
176 }; 182 };
177 explicit SkFontMgr_Custom(const SystemFontLoader& loader) : fDefaultFamily(n ullptr) { 183 explicit SkFontMgr_Custom(const SystemFontLoader& loader) : fDefaultFamily(n ullptr) {
178 loader.loadSystemFonts(fScanner, &fFamilies); 184 loader.loadSystemFonts(fScanner, &fFamilies);
179 185
180 // Try to pick a default font. 186 // Try to pick a default font.
181 static const char* defaultNames[] = { 187 static const char* defaultNames[] = {
182 "Arial", "Verdana", "Times New Roman", "Droid Sans", nullptr 188 "Arial", "Verdana", "Times New Roman", "Droid Sans", nullptr
183 }; 189 };
184 for (size_t i = 0; i < SK_ARRAY_COUNT(defaultNames); ++i) { 190 for (size_t i = 0; i < SK_ARRAY_COUNT(defaultNames); ++i) {
185 SkFontStyleSet_Custom* set = this->onMatchFamily(defaultNames[i]); 191 sk_sp<SkFontStyleSet_Custom> set(this->onMatchFamily(defaultNames[i] ));
186 if (nullptr == set) { 192 if (nullptr == set) {
187 continue; 193 continue;
188 } 194 }
189 195
190 SkTypeface* tf = set->matchStyle(SkFontStyle(SkFontStyle::kNormal_We ight, 196 sk_sp<SkTypeface> tf(set->matchStyle(SkFontStyle(SkFontStyle::kNorma l_Weight,
191 SkFontStyle::kNormal_Wi dth, 197 SkFontStyle::kNorma l_Width,
192 SkFontStyle::kUpright_S lant)); 198 SkFontStyle::kUprig ht_Slant)));
193 if (nullptr == tf) { 199 if (nullptr == tf) {
194 continue; 200 continue;
195 } 201 }
196 202
197 fDefaultFamily = set; 203 fDefaultFamily = set.get();
198 break; 204 break;
199 } 205 }
200 if (nullptr == fDefaultFamily) { 206 if (nullptr == fDefaultFamily) {
201 fDefaultFamily = fFamilies[0]; 207 fDefaultFamily = fFamilies[0].get();
202 } 208 }
203 } 209 }
204 210
205 protected: 211 protected:
206 int onCountFamilies() const override { 212 int onCountFamilies() const override {
207 return fFamilies.count(); 213 return fFamilies.count();
208 } 214 }
209 215
210 void onGetFamilyName(int index, SkString* familyName) const override { 216 void onGetFamilyName(int index, SkString* familyName) const override {
211 SkASSERT(index < fFamilies.count()); 217 SkASSERT(index < fFamilies.count());
(...skipping 26 matching lines...) Expand all
238 SkUnichar character) const override 244 SkUnichar character) const override
239 { 245 {
240 return nullptr; 246 return nullptr;
241 } 247 }
242 248
243 SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, 249 SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
244 const SkFontStyle& fontStyle) const override 250 const SkFontStyle& fontStyle) const override
245 { 251 {
246 for (int i = 0; i < fFamilies.count(); ++i) { 252 for (int i = 0; i < fFamilies.count(); ++i) {
247 for (int j = 0; j < fFamilies[i]->fStyles.count(); ++j) { 253 for (int j = 0; j < fFamilies[i]->fStyles.count(); ++j) {
248 if (fFamilies[i]->fStyles[j] == familyMember) { 254 if (fFamilies[i]->fStyles[j].get() == familyMember) {
249 return fFamilies[i]->matchStyle(fontStyle); 255 return fFamilies[i]->matchStyle(fontStyle);
250 } 256 }
251 } 257 }
252 } 258 }
253 return nullptr; 259 return nullptr;
254 } 260 }
255 261
256 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { 262 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
257 return this->createFromStream(new SkMemoryStream(data), ttcIndex); 263 return this->createFromStream(new SkMemoryStream(data), ttcIndex);
258 } 264 }
259 265
260 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override { 266 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override {
261 SkAutoTDelete<SkStreamAsset> stream(bareStream); 267 return this->createFromStream(bareStream, FontParameters().setCollection Index(ttcIndex));
262 if (nullptr == stream || stream->getLength() <= 0) { 268 }
269
270 SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& param s) const override {
271 using Scanner = SkTypeface_FreeType::Scanner;
272 SkAutoTDelete<SkStreamAsset> stream(s);
273 bool isFixedPitch;
274 SkFontStyle style;
275 SkString name;
276 Scanner::AxisDefinitions axisDefinitions;
277 if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &styl e, &isFixedPitch,
278 &axisDefinitions))
279 {
263 return nullptr; 280 return nullptr;
264 } 281 }
265 282
266 bool isFixedPitch; 283 int paramAxisCount;
267 SkFontStyle style; 284 const FontParameters::Axis* paramAxes = params.getAxes(&paramAxisCount);
268 SkString name; 285 SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
269 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, nu llptr)) { 286 Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, a xisValues, name);
270 return new SkTypeface_Stream(style, isFixedPitch, false, name, strea m.release(), 287
271 ttcIndex); 288 std::unique_ptr<SkFontData> data(new SkFontData(stream.release(),
272 } else { 289 params.getCollectionInde x(),
273 return nullptr; 290 axisValues.get(), axisDe finitions.count()));
274 } 291 return new SkTypeface_Stream(std::move(data), style, isFixedPitch, false , name);
275 } 292 }
276 293
277 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override { 294 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
278 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); 295 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path));
279 return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr; 296 return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
280 } 297 }
281 298
282 SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle styl e) const override { 299 SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle styl e) const override {
283 SkTypeface* tf = nullptr; 300 SkTypeface* tf = nullptr;
284 301
285 if (familyName) { 302 if (familyName) {
286 tf = this->onMatchFamilyStyle(familyName, style); 303 tf = this->onMatchFamilyStyle(familyName, style);
287 } 304 }
288 305
289 if (nullptr == tf) { 306 if (nullptr == tf) {
290 tf = fDefaultFamily->matchStyle(style); 307 tf = fDefaultFamily->matchStyle(style);
291 } 308 }
292 309
293 return SkSafeRef(tf); 310 return tf;
bungeman-skia 2016/06/10 00:18:48 Like in the SkFontMgr_Custom constructor, this lea
294 } 311 }
295 312
296 private: 313 private:
297 Families fFamilies; 314 Families fFamilies;
298 SkFontStyleSet_Custom* fDefaultFamily; 315 SkFontStyleSet_Custom* fDefaultFamily;
299 SkTypeface_FreeType::Scanner fScanner; 316 SkTypeface_FreeType::Scanner fScanner;
300 }; 317 };
301 318
302 /////////////////////////////////////////////////////////////////////////////// 319 ///////////////////////////////////////////////////////////////////////////////
303 320
304 class DirectorySystemFontLoader : public SkFontMgr_Custom::SystemFontLoader { 321 class DirectorySystemFontLoader : public SkFontMgr_Custom::SystemFontLoader {
305 public: 322 public:
306 DirectorySystemFontLoader(const char* dir) : fBaseDirectory(dir) { } 323 DirectorySystemFontLoader(const char* dir) : fBaseDirectory(dir) { }
307 324
308 void loadSystemFonts(const SkTypeface_FreeType::Scanner& scanner, 325 void loadSystemFonts(const SkTypeface_FreeType::Scanner& scanner,
309 SkFontMgr_Custom::Families* families) const override 326 SkFontMgr_Custom::Families* families) const override
310 { 327 {
311 load_directory_fonts(scanner, fBaseDirectory, ".ttf", families); 328 load_directory_fonts(scanner, fBaseDirectory, ".ttf", families);
312 load_directory_fonts(scanner, fBaseDirectory, ".ttc", families); 329 load_directory_fonts(scanner, fBaseDirectory, ".ttc", families);
313 load_directory_fonts(scanner, fBaseDirectory, ".otf", families); 330 load_directory_fonts(scanner, fBaseDirectory, ".otf", families);
314 load_directory_fonts(scanner, fBaseDirectory, ".pfb", families); 331 load_directory_fonts(scanner, fBaseDirectory, ".pfb", families);
315 332
316 if (families->empty()) { 333 if (families->empty()) {
317 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString() ); 334 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString() );
318 families->push_back().reset(family); 335 families->push_back().reset(family);
319 family->appendTypeface(new SkTypeface_Empty); 336 family->appendTypeface(sk_make_sp<SkTypeface_Empty>());
320 } 337 }
321 } 338 }
322 339
323 private: 340 private:
324 static SkFontStyleSet_Custom* find_family(SkFontMgr_Custom::Families& famili es, 341 static SkFontStyleSet_Custom* find_family(SkFontMgr_Custom::Families& famili es,
325 const char familyName[]) 342 const char familyName[])
326 { 343 {
327 for (int i = 0; i < families.count(); ++i) { 344 for (int i = 0; i < families.count(); ++i) {
328 if (families[i]->getFamilyName().equals(familyName)) { 345 if (families[i]->getFamilyName().equals(familyName)) {
329 return families[i].get(); 346 return families[i].get();
(...skipping 26 matching lines...) Expand all
356 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) { 373 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) {
357 bool isFixedPitch; 374 bool isFixedPitch;
358 SkString realname; 375 SkString realname;
359 SkFontStyle style = SkFontStyle(); // avoid uninitialized warnin g 376 SkFontStyle style = SkFontStyle(); // avoid uninitialized warnin g
360 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isF ixedPitch, nullptr)) { 377 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isF ixedPitch, nullptr)) {
361 SkDebugf("---- failed to open <%s> <%d> as a font\n", 378 SkDebugf("---- failed to open <%s> <%d> as a font\n",
362 filename.c_str(), faceIndex); 379 filename.c_str(), faceIndex);
363 continue; 380 continue;
364 } 381 }
365 382
366 SkTypeface_Custom* tf = new SkTypeface_File(style, isFixedPitch,
367 true, // system-fon t (cannot delete)
368 realname, filename.c _str(), faceIndex);
369
370 SkFontStyleSet_Custom* addTo = find_family(*families, realname.c _str()); 383 SkFontStyleSet_Custom* addTo = find_family(*families, realname.c _str());
371 if (nullptr == addTo) { 384 if (nullptr == addTo) {
372 addTo = new SkFontStyleSet_Custom(realname); 385 addTo = new SkFontStyleSet_Custom(realname);
373 families->push_back().reset(addTo); 386 families->push_back().reset(addTo);
374 } 387 }
375 addTo->appendTypeface(tf); 388 addTo->appendTypeface(sk_make_sp<SkTypeface_File>(style, isFixed Pitch, true,
389 realname, file name.c_str(),
390 faceIndex));
376 } 391 }
377 } 392 }
378 393
379 SkOSFile::Iter dirIter(directory.c_str()); 394 SkOSFile::Iter dirIter(directory.c_str());
380 while (dirIter.next(&name, true)) { 395 while (dirIter.next(&name, true)) {
381 if (name.startsWith(".")) { 396 if (name.startsWith(".")) {
382 continue; 397 continue;
383 } 398 }
384 SkString dirname(SkOSPath::Join(directory.c_str(), name.c_str())); 399 SkString dirname(SkOSPath::Join(directory.c_str(), name.c_str()));
385 load_directory_fonts(scanner, dirname, suffix, families); 400 load_directory_fonts(scanner, dirname, suffix, families);
(...skipping 20 matching lines...) Expand all
406 SkFontMgr_Custom::Families* families) const override 421 SkFontMgr_Custom::Families* families) const override
407 { 422 {
408 for (int i = 0; i < fHeader->count; ++i) { 423 for (int i = 0; i < fHeader->count; ++i) {
409 const SkEmbeddedResource& fontEntry = fHeader->entries[i]; 424 const SkEmbeddedResource& fontEntry = fHeader->entries[i];
410 load_embedded_font(scanner, fontEntry.data, fontEntry.size, i, famil ies); 425 load_embedded_font(scanner, fontEntry.data, fontEntry.size, i, famil ies);
411 } 426 }
412 427
413 if (families->empty()) { 428 if (families->empty()) {
414 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString() ); 429 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString() );
415 families->push_back().reset(family); 430 families->push_back().reset(family);
416 family->appendTypeface(new SkTypeface_Empty); 431 family->appendTypeface(sk_make_sp<SkTypeface_Empty>());
417 } 432 }
418 } 433 }
419 434
420 private: 435 private:
421 static SkFontStyleSet_Custom* find_family(SkFontMgr_Custom::Families& famili es, 436 static SkFontStyleSet_Custom* find_family(SkFontMgr_Custom::Families& famili es,
422 const char familyName[]) 437 const char familyName[])
423 { 438 {
424 for (int i = 0; i < families.count(); ++i) { 439 for (int i = 0; i < families.count(); ++i) {
425 if (families[i]->getFamilyName().equals(familyName)) { 440 if (families[i]->getFamilyName().equals(familyName)) {
426 return families[i].get(); 441 return families[i].get();
(...skipping 16 matching lines...) Expand all
443 458
444 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) { 459 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) {
445 bool isFixedPitch; 460 bool isFixedPitch;
446 SkString realname; 461 SkString realname;
447 SkFontStyle style = SkFontStyle(); // avoid uninitialized warning 462 SkFontStyle style = SkFontStyle(); // avoid uninitialized warning
448 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixed Pitch, nullptr)) { 463 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixed Pitch, nullptr)) {
449 SkDebugf("---- failed to open <%d> <%d> as a font\n", index, fac eIndex); 464 SkDebugf("---- failed to open <%d> <%d> as a font\n", index, fac eIndex);
450 return; 465 return;
451 } 466 }
452 467
453 SkTypeface_Custom* tf =
454 new SkTypeface_Stream(style, isFixedPitch, true, // system- font (cannot delete)
455 realname, stream.release(), faceIndex) ;
456
457 SkFontStyleSet_Custom* addTo = find_family(*families, realname.c_str ()); 468 SkFontStyleSet_Custom* addTo = find_family(*families, realname.c_str ());
458 if (nullptr == addTo) { 469 if (nullptr == addTo) {
459 addTo = new SkFontStyleSet_Custom(realname); 470 addTo = new SkFontStyleSet_Custom(realname);
460 families->push_back().reset(addTo); 471 families->push_back().reset(addTo);
461 } 472 }
462 addTo->appendTypeface(tf); 473 std::unique_ptr<SkFontData> data(
474 new SkFontData(stream.release(), faceIndex, nullptr, 0));
475 addTo->appendTypeface(sk_make_sp<SkTypeface_Stream>(std::move(data),
476 style, isFixedPi tch,
477 true, realname)) ;
463 } 478 }
464 } 479 }
465 480
466 const SkEmbeddedResourceHeader* fHeader; 481 const SkEmbeddedResourceHeader* fHeader;
467 }; 482 };
468 483
469 SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header) { 484 SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header) {
470 return new SkFontMgr_Custom(EmbeddedSystemFontLoader(header)); 485 return new SkFontMgr_Custom(EmbeddedSystemFontLoader(header));
471 } 486 }
472 487
473 /////////////////////////////////////////////////////////////////////////////// 488 ///////////////////////////////////////////////////////////////////////////////
474 489
475 class EmptyFontLoader : public SkFontMgr_Custom::SystemFontLoader { 490 class EmptyFontLoader : public SkFontMgr_Custom::SystemFontLoader {
476 public: 491 public:
477 EmptyFontLoader() { } 492 EmptyFontLoader() { }
478 493
479 void loadSystemFonts(const SkTypeface_FreeType::Scanner& scanner, 494 void loadSystemFonts(const SkTypeface_FreeType::Scanner& scanner,
480 SkFontMgr_Custom::Families* families) const override 495 SkFontMgr_Custom::Families* families) const override
481 { 496 {
482 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString()); 497 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString());
483 families->push_back().reset(family); 498 families->push_back().reset(family);
484 family->appendTypeface(new SkTypeface_Empty); 499 family->appendTypeface(sk_make_sp<SkTypeface_Empty>());
485 } 500 }
486 501
487 }; 502 };
488 503
489 SK_API SkFontMgr* SkFontMgr_New_Custom_Empty() { 504 SK_API SkFontMgr* SkFontMgr_New_Custom_Empty() {
490 return new SkFontMgr_Custom(EmptyFontLoader()); 505 return new SkFontMgr_Custom(EmptyFontLoader());
491 } 506 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698