OLD | NEW |
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" |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { | 289 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { |
290 SkAutoTDelete<SkStreamAsset> stream(bareStream); | 290 SkAutoTDelete<SkStreamAsset> stream(bareStream); |
291 if (nullptr == stream || stream->getLength() <= 0) { | 291 if (nullptr == stream || stream->getLength() <= 0) { |
292 return nullptr; | 292 return nullptr; |
293 } | 293 } |
294 | 294 |
295 bool isFixedPitch; | 295 bool isFixedPitch; |
296 SkFontStyle style; | 296 SkFontStyle style; |
297 SkString name; | 297 SkString name; |
298 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, nu
llptr)) { | 298 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, nu
llptr)) { |
299 return new SkTypeface_Stream(style, isFixedPitch, false, name, strea
m.detach(), | 299 return new SkTypeface_Stream(style, isFixedPitch, false, name, strea
m.release(), |
300 ttcIndex); | 300 ttcIndex); |
301 } else { | 301 } else { |
302 return nullptr; | 302 return nullptr; |
303 } | 303 } |
304 } | 304 } |
305 | 305 |
306 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ | 306 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ |
307 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); | 307 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); |
308 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex)
: nullptr; | 308 return stream.get() ? this->createFromStream(stream.release(), ttcIndex)
: nullptr; |
309 } | 309 } |
310 | 310 |
311 SkTypeface* onLegacyCreateTypeface(const char familyName[], unsigned styleBi
ts) const override { | 311 SkTypeface* onLegacyCreateTypeface(const char familyName[], unsigned styleBi
ts) const override { |
312 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits; | 312 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits; |
313 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold | 313 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold |
314 ? SkFontStyle::kBold_Weight | 314 ? SkFontStyle::kBold_Weight |
315 : SkFontStyle::kNormal_Weight, | 315 : SkFontStyle::kNormal_Weight, |
316 SkFontStyle::kNormal_Width, | 316 SkFontStyle::kNormal_Width, |
317 oldStyle & SkTypeface::kItalic | 317 oldStyle & SkTypeface::kItalic |
318 ? SkFontStyle::kItalic_Slant | 318 ? SkFontStyle::kItalic_Slant |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 bool isFixedPitch; | 482 bool isFixedPitch; |
483 SkString realname; | 483 SkString realname; |
484 SkFontStyle style = SkFontStyle(); // avoid uninitialized warning | 484 SkFontStyle style = SkFontStyle(); // avoid uninitialized warning |
485 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixed
Pitch, nullptr)) { | 485 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixed
Pitch, nullptr)) { |
486 SkDebugf("---- failed to open <%d> <%d> as a font\n", index, fac
eIndex); | 486 SkDebugf("---- failed to open <%d> <%d> as a font\n", index, fac
eIndex); |
487 return; | 487 return; |
488 } | 488 } |
489 | 489 |
490 SkTypeface_Custom* tf = | 490 SkTypeface_Custom* tf = |
491 new SkTypeface_Stream(style, isFixedPitch, true, // system-
font (cannot delete) | 491 new SkTypeface_Stream(style, isFixedPitch, true, // system-
font (cannot delete) |
492 realname, stream.detach(), faceIndex); | 492 realname, stream.release(), faceIndex)
; |
493 | 493 |
494 SkFontStyleSet_Custom* addTo = find_family(*families, realname.c_str
()); | 494 SkFontStyleSet_Custom* addTo = find_family(*families, realname.c_str
()); |
495 if (nullptr == addTo) { | 495 if (nullptr == addTo) { |
496 addTo = new SkFontStyleSet_Custom(realname); | 496 addTo = new SkFontStyleSet_Custom(realname); |
497 families->push_back().reset(addTo); | 497 families->push_back().reset(addTo); |
498 } | 498 } |
499 addTo->appendTypeface(tf); | 499 addTo->appendTypeface(tf); |
500 } | 500 } |
501 } | 501 } |
502 | 502 |
503 const SkEmbeddedResourceHeader* fHeader; | 503 const SkEmbeddedResourceHeader* fHeader; |
504 }; | 504 }; |
505 | 505 |
506 SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header)
{ | 506 SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header)
{ |
507 return new SkFontMgr_Custom(EmbeddedSystemFontLoader(header)); | 507 return new SkFontMgr_Custom(EmbeddedSystemFontLoader(header)); |
508 } | 508 } |
OLD | NEW |