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 "SkFixed.h" | 9 #include "SkFixed.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 : INHERITED(skfontstyle_from_fcpattern(pattern), | 496 : INHERITED(skfontstyle_from_fcpattern(pattern), |
497 FC_PROPORTIONAL != get_int(pattern, FC_SPACING, FC_PROPORTIO
NAL)) | 497 FC_PROPORTIONAL != get_int(pattern, FC_SPACING, FC_PROPORTIO
NAL)) |
498 , fPattern(pattern) | 498 , fPattern(pattern) |
499 { }; | 499 { }; |
500 | 500 |
501 typedef SkTypeface_FreeType INHERITED; | 501 typedef SkTypeface_FreeType INHERITED; |
502 }; | 502 }; |
503 | 503 |
504 class SkFontMgr_fontconfig : public SkFontMgr { | 504 class SkFontMgr_fontconfig : public SkFontMgr { |
505 mutable SkAutoFcConfig fFC; | 505 mutable SkAutoFcConfig fFC; |
506 SkAutoTUnref<SkDataTable> fFamilyNames; | 506 sk_sp<SkDataTable> fFamilyNames; |
507 SkTypeface_FreeType::Scanner fScanner; | 507 SkTypeface_FreeType::Scanner fScanner; |
508 | 508 |
509 class StyleSet : public SkFontStyleSet { | 509 class StyleSet : public SkFontStyleSet { |
510 public: | 510 public: |
511 /** @param parent does not take ownership of the reference. | 511 /** @param parent does not take ownership of the reference. |
512 * @param fontSet takes ownership of the reference. | 512 * @param fontSet takes ownership of the reference. |
513 */ | 513 */ |
514 StyleSet(const SkFontMgr_fontconfig* parent, FcFontSet* fontSet) | 514 StyleSet(const SkFontMgr_fontconfig* parent, FcFontSet* fontSet) |
515 : fFontMgr(SkRef(parent)), fFontSet(fontSet) | 515 : fFontMgr(SkRef(parent)), fFontSet(fontSet) |
516 { } | 516 { } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 static bool FindName(const SkTDArray<const char*>& list, const char* str) { | 572 static bool FindName(const SkTDArray<const char*>& list, const char* str) { |
573 int count = list.count(); | 573 int count = list.count(); |
574 for (int i = 0; i < count; ++i) { | 574 for (int i = 0; i < count; ++i) { |
575 if (!strcmp(list[i], str)) { | 575 if (!strcmp(list[i], str)) { |
576 return true; | 576 return true; |
577 } | 577 } |
578 } | 578 } |
579 return false; | 579 return false; |
580 } | 580 } |
581 | 581 |
582 static SkDataTable* GetFamilyNames(FcConfig* fcconfig) { | 582 static sk_sp<SkDataTable> GetFamilyNames(FcConfig* fcconfig) { |
583 FCLocker lock; | 583 FCLocker lock; |
584 | 584 |
585 SkTDArray<const char*> names; | 585 SkTDArray<const char*> names; |
586 SkTDArray<size_t> sizes; | 586 SkTDArray<size_t> sizes; |
587 | 587 |
588 static const FcSetName fcNameSet[] = { FcSetSystem, FcSetApplication }; | 588 static const FcSetName fcNameSet[] = { FcSetSystem, FcSetApplication }; |
589 for (int setIndex = 0; setIndex < (int)SK_ARRAY_COUNT(fcNameSet); ++setI
ndex) { | 589 for (int setIndex = 0; setIndex < (int)SK_ARRAY_COUNT(fcNameSet); ++setI
ndex) { |
590 // Return value of FcConfigGetFonts must not be destroyed. | 590 // Return value of FcConfigGetFonts must not be destroyed. |
591 FcFontSet* allFonts(FcConfigGetFonts(fcconfig, fcNameSet[setIndex]))
; | 591 FcFontSet* allFonts(FcConfigGetFonts(fcconfig, fcNameSet[setIndex]))
; |
592 if (nullptr == allFonts) { | 592 if (nullptr == allFonts) { |
(...skipping 13 matching lines...) Expand all Loading... |
606 } | 606 } |
607 const char* familyName = reinterpret_cast<const char*>(fcFam
ilyName); | 607 const char* familyName = reinterpret_cast<const char*>(fcFam
ilyName); |
608 if (familyName && !FindName(names, familyName)) { | 608 if (familyName && !FindName(names, familyName)) { |
609 *names.append() = familyName; | 609 *names.append() = familyName; |
610 *sizes.append() = strlen(familyName) + 1; | 610 *sizes.append() = strlen(familyName) + 1; |
611 } | 611 } |
612 } | 612 } |
613 } | 613 } |
614 } | 614 } |
615 | 615 |
616 return SkDataTable::NewCopyArrays((void const *const *)names.begin(), | 616 return SkDataTable::MakeCopyArrays((void const *const *)names.begin(), |
617 sizes.begin(), names.count()); | 617 sizes.begin(), names.count()); |
618 } | 618 } |
619 | 619 |
620 static bool FindByFcPattern(SkTypeface* cached, void* ctx) { | 620 static bool FindByFcPattern(SkTypeface* cached, void* ctx) { |
621 SkTypeface_fontconfig* cshFace = static_cast<SkTypeface_fontconfig*>(cac
hed); | 621 SkTypeface_fontconfig* cshFace = static_cast<SkTypeface_fontconfig*>(cac
hed); |
622 FcPattern* ctxPattern = static_cast<FcPattern*>(ctx); | 622 FcPattern* ctxPattern = static_cast<FcPattern*>(ctx); |
623 return FcTrue == FcPatternEqual(cshFace->fPattern, ctxPattern); | 623 return FcTrue == FcPatternEqual(cshFace->fPattern, ctxPattern); |
624 } | 624 } |
625 | 625 |
626 mutable SkMutex fTFCacheMutex; | 626 mutable SkMutex fTFCacheMutex; |
627 mutable SkTypefaceCache fTFCache; | 627 mutable SkTypefaceCache fTFCache; |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 return typeface.release(); | 933 return typeface.release(); |
934 } | 934 } |
935 | 935 |
936 return this->matchFamilyStyle(nullptr, style); | 936 return this->matchFamilyStyle(nullptr, style); |
937 } | 937 } |
938 }; | 938 }; |
939 | 939 |
940 SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc) { | 940 SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc) { |
941 return new SkFontMgr_fontconfig(fc); | 941 return new SkFontMgr_fontconfig(fc); |
942 } | 942 } |
OLD | NEW |