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 "SkFontDescriptor.h" | 9 #include "SkFontDescriptor.h" |
10 #include "SkFontHost_FreeType_common.h" | 10 #include "SkFontHost_FreeType_common.h" |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) | 380 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) |
381 , fStream(stream) | 381 , fStream(stream) |
382 , fIndex(index) | 382 , fIndex(index) |
383 { }; | 383 { }; |
384 | 384 |
385 void onGetFamilyName(SkString* familyName) const override { | 385 void onGetFamilyName(SkString* familyName) const override { |
386 familyName->reset(); | 386 familyName->reset(); |
387 } | 387 } |
388 | 388 |
389 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const over
ride { | 389 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const over
ride { |
390 desc->setFontIndex(fIndex); | |
391 *serialize = true; | 390 *serialize = true; |
392 } | 391 } |
393 | 392 |
394 SkStreamAsset* onOpenStream(int* ttcIndex) const override { | 393 SkStreamAsset* onOpenStream(int* ttcIndex) const override { |
395 *ttcIndex = fIndex; | 394 *ttcIndex = fIndex; |
396 return fStream->duplicate(); | 395 return fStream->duplicate(); |
397 } | 396 } |
398 | 397 |
| 398 SkFontData* onCreateFontData() const override { |
| 399 SkFixed axis[1] = { SK_Fixed1 }; |
| 400 return new SkFontData(fStream->duplicate(), fIndex, 1, axis); |
| 401 }; |
| 402 |
399 private: | 403 private: |
400 SkAutoTDelete<SkStreamAsset> fStream; | 404 SkAutoTDelete<SkStreamAsset> fStream; |
401 int fIndex; | 405 int fIndex; |
402 | 406 |
403 typedef SkTypeface_FreeType INHERITED; | 407 typedef SkTypeface_FreeType INHERITED; |
404 }; | 408 }; |
405 | 409 |
406 class SkTypeface_fontconfig : public SkTypeface_FreeType { | 410 class SkTypeface_fontconfig : public SkTypeface_FreeType { |
407 public: | 411 public: |
408 /** @param pattern takes ownership of the reference. */ | 412 /** @param pattern takes ownership of the reference. */ |
409 static SkTypeface_fontconfig* Create(FcPattern* pattern) { | 413 static SkTypeface_fontconfig* Create(FcPattern* pattern) { |
410 return SkNEW_ARGS(SkTypeface_fontconfig, (pattern)); | 414 return SkNEW_ARGS(SkTypeface_fontconfig, (pattern)); |
411 } | 415 } |
412 mutable SkAutoFcPattern fPattern; | 416 mutable SkAutoFcPattern fPattern; |
413 | 417 |
414 void onGetFamilyName(SkString* familyName) const override { | 418 void onGetFamilyName(SkString* familyName) const override { |
415 *familyName = get_string(fPattern, FC_FAMILY); | 419 *familyName = get_string(fPattern, FC_FAMILY); |
416 } | 420 } |
417 | 421 |
418 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const over
ride { | 422 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const over
ride { |
419 FCLocker lock; | 423 FCLocker lock; |
420 desc->setFamilyName(get_string(fPattern, FC_FAMILY)); | 424 desc->setFamilyName(get_string(fPattern, FC_FAMILY)); |
421 desc->setFullName(get_string(fPattern, FC_FULLNAME)); | 425 desc->setFullName(get_string(fPattern, FC_FULLNAME)); |
422 desc->setPostscriptName(get_string(fPattern, FC_POSTSCRIPT_NAME)); | 426 desc->setPostscriptName(get_string(fPattern, FC_POSTSCRIPT_NAME)); |
423 desc->setFontIndex(get_int(fPattern, FC_INDEX, 0)); | |
424 *serialize = false; | 427 *serialize = false; |
425 } | 428 } |
426 | 429 |
427 SkStreamAsset* onOpenStream(int* ttcIndex) const override { | 430 SkStreamAsset* onOpenStream(int* ttcIndex) const override { |
428 FCLocker lock; | 431 FCLocker lock; |
429 *ttcIndex = get_int(fPattern, FC_INDEX, 0); | 432 *ttcIndex = get_int(fPattern, FC_INDEX, 0); |
430 return SkStream::NewFromFile(get_string(fPattern, FC_FILE)); | 433 return SkStream::NewFromFile(get_string(fPattern, FC_FILE)); |
431 } | 434 } |
432 | 435 |
| 436 SkFontData* onCreateFontData() const override { |
| 437 SkFixed axis[1] = { SK_Fixed1 }; |
| 438 return new SkFontData(SkStream::NewFromFile(get_string(fPattern, FC_FILE
)), |
| 439 get_int(fPattern, FC_INDEX, 0), |
| 440 1, axis); |
| 441 }; |
| 442 |
433 virtual ~SkTypeface_fontconfig() { | 443 virtual ~SkTypeface_fontconfig() { |
434 // Hold the lock while unrefing the pattern. | 444 // Hold the lock while unrefing the pattern. |
435 FCLocker lock; | 445 FCLocker lock; |
436 fPattern.reset(); | 446 fPattern.reset(); |
437 } | 447 } |
438 | 448 |
439 private: | 449 private: |
440 /** @param pattern takes ownership of the reference. */ | 450 /** @param pattern takes ownership of the reference. */ |
441 SkTypeface_fontconfig(FcPattern* pattern) | 451 SkTypeface_fontconfig(FcPattern* pattern) |
442 : INHERITED(skfontstyle_from_fcpattern(pattern), | 452 : INHERITED(skfontstyle_from_fcpattern(pattern), |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 | 820 |
811 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { | 821 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { |
812 SkAutoTDelete<SkStreamAsset> stream(bareStream); | 822 SkAutoTDelete<SkStreamAsset> stream(bareStream); |
813 const size_t length = stream->getLength(); | 823 const size_t length = stream->getLength(); |
814 if (length <= 0 || (1u << 30) < length) { | 824 if (length <= 0 || (1u << 30) < length) { |
815 return NULL; | 825 return NULL; |
816 } | 826 } |
817 | 827 |
818 SkFontStyle style; | 828 SkFontStyle style; |
819 bool isFixedWidth = false; | 829 bool isFixedWidth = false; |
820 if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth)) { | 830 if (!fScanner.scanFont(stream, ttcIndex, NULL, 0, NULL, &style, &isFixed
Width, NULL)) { |
821 return NULL; | 831 return NULL; |
822 } | 832 } |
823 | 833 |
824 return SkNEW_ARGS(SkTypeface_stream, (style, isFixedWidth, ttcIndex, | 834 return SkNEW_ARGS(SkTypeface_stream, (style, isFixedWidth, ttcIndex, |
825 static_cast<SkStreamAsset*>(stream
.detach()))); | 835 static_cast<SkStreamAsset*>(stream
.detach()))); |
826 } | 836 } |
827 | 837 |
828 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { | 838 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { |
829 return this->createFromStream(SkNEW_ARGS(SkMemoryStream, (data)), ttcInd
ex); | 839 return this->createFromStream(SkNEW_ARGS(SkMemoryStream, (data)), ttcInd
ex); |
830 } | 840 } |
(...skipping 16 matching lines...) Expand all Loading... |
847 return typeface.detach(); | 857 return typeface.detach(); |
848 } | 858 } |
849 | 859 |
850 return this->matchFamilyStyle(NULL, style); | 860 return this->matchFamilyStyle(NULL, style); |
851 } | 861 } |
852 }; | 862 }; |
853 | 863 |
854 SkFontMgr* SkFontMgr::Factory() { | 864 SkFontMgr* SkFontMgr::Factory() { |
855 return SkNEW(SkFontMgr_fontconfig); | 865 return SkNEW(SkFontMgr_fontconfig); |
856 } | 866 } |
OLD | NEW |