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

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

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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 | « src/ports/SkFontMgr_empty_factory.cpp ('k') | src/ports/SkFontMgr_fontconfig_factory.cpp » ('j') | 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 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 template<typename T, void (*D)(T*)> void FcTDestroy(T* t) { 107 template<typename T, void (*D)(T*)> void FcTDestroy(T* t) {
108 FCLocker::AssertHeld(); 108 FCLocker::AssertHeld();
109 D(t); 109 D(t);
110 } 110 }
111 template <typename T, T* (*C)(), void (*D)(T*)> class SkAutoFc 111 template <typename T, T* (*C)(), void (*D)(T*)> class SkAutoFc
112 : public SkAutoTCallVProc<T, FcTDestroy<T, D> > { 112 : public SkAutoTCallVProc<T, FcTDestroy<T, D> > {
113 public: 113 public:
114 SkAutoFc() : SkAutoTCallVProc<T, FcTDestroy<T, D> >(C()) { 114 SkAutoFc() : SkAutoTCallVProc<T, FcTDestroy<T, D> >(C()) {
115 T* obj = this->operator T*(); 115 T* obj = this->operator T*();
116 SK_ALWAYSBREAK(NULL != obj); 116 SK_ALWAYSBREAK(nullptr != obj);
117 } 117 }
118 explicit SkAutoFc(T* obj) : SkAutoTCallVProc<T, FcTDestroy<T, D> >(obj) {} 118 explicit SkAutoFc(T* obj) : SkAutoTCallVProc<T, FcTDestroy<T, D> >(obj) {}
119 }; 119 };
120 120
121 typedef SkAutoFc<FcCharSet, FcCharSetCreate, FcCharSetDestroy> SkAutoFcCharSet; 121 typedef SkAutoFc<FcCharSet, FcCharSetCreate, FcCharSetDestroy> SkAutoFcCharSet;
122 typedef SkAutoFc<FcConfig, FcConfigCreate, FcConfigDestroy> SkAutoFcConfig; 122 typedef SkAutoFc<FcConfig, FcConfigCreate, FcConfigDestroy> SkAutoFcConfig;
123 typedef SkAutoFc<FcFontSet, FcFontSetCreate, FcFontSetDestroy> SkAutoFcFontSet; 123 typedef SkAutoFc<FcFontSet, FcFontSetCreate, FcFontSetDestroy> SkAutoFcFontSet;
124 typedef SkAutoFc<FcLangSet, FcLangSetCreate, FcLangSetDestroy> SkAutoFcLangSet; 124 typedef SkAutoFc<FcLangSet, FcLangSetCreate, FcLangSetDestroy> SkAutoFcLangSet;
125 typedef SkAutoFc<FcObjectSet, FcObjectSetCreate, FcObjectSetDestroy> SkAutoFcObj ectSet; 125 typedef SkAutoFc<FcObjectSet, FcObjectSetCreate, FcObjectSetDestroy> SkAutoFcObj ectSet;
126 typedef SkAutoFc<FcPattern, FcPatternCreate, FcPatternDestroy> SkAutoFcPattern; 126 typedef SkAutoFc<FcPattern, FcPatternCreate, FcPatternDestroy> SkAutoFcPattern;
(...skipping 28 matching lines...) Expand all
155 * A element with the weak bit is scored after FC_LANG, without the weak bit is scored before. 155 * A element with the weak bit is scored after FC_LANG, without the weak bit is scored before.
156 * Note that the weak bit is stored on the element, not on the value it holds. 156 * Note that the weak bit is stored on the element, not on the value it holds.
157 */ 157 */
158 static SkWeakReturn is_weak(FcPattern* pattern, const char object[], int id) { 158 static SkWeakReturn is_weak(FcPattern* pattern, const char object[], int id) {
159 FCLocker::AssertHeld(); 159 FCLocker::AssertHeld();
160 160
161 FcResult result; 161 FcResult result;
162 162
163 // Create a copy of the pattern with only the value 'pattern'['object'['id'] ] in it. 163 // Create a copy of the pattern with only the value 'pattern'['object'['id'] ] in it.
164 // Internally, FontConfig pattern objects are linked lists, so faster to rem ove from head. 164 // Internally, FontConfig pattern objects are linked lists, so faster to rem ove from head.
165 SkAutoFcObjectSet requestedObjectOnly(FcObjectSetBuild(object, NULL)); 165 SkAutoFcObjectSet requestedObjectOnly(FcObjectSetBuild(object, nullptr));
166 SkAutoFcPattern minimal(FcPatternFilter(pattern, requestedObjectOnly)); 166 SkAutoFcPattern minimal(FcPatternFilter(pattern, requestedObjectOnly));
167 FcBool hasId = true; 167 FcBool hasId = true;
168 for (int i = 0; hasId && i < id; ++i) { 168 for (int i = 0; hasId && i < id; ++i) {
169 hasId = FcPatternRemove(minimal, object, 0); 169 hasId = FcPatternRemove(minimal, object, 0);
170 } 170 }
171 if (!hasId) { 171 if (!hasId) {
172 return kNoId_WeakReturn; 172 return kNoId_WeakReturn;
173 } 173 }
174 FcValue value; 174 FcValue value;
175 result = FcPatternGet(minimal, object, 0, &value); 175 result = FcPatternGet(minimal, object, 0, &value);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 ? kIsWeak_WeakReturn : kIsStrong_WeakReturn; 219 ? kIsWeak_WeakReturn : kIsStrong_WeakReturn;
220 } 220 }
221 221
222 /** Removes weak elements from either FC_FAMILY or FC_POSTSCRIPT_NAME objects in the property. 222 /** Removes weak elements from either FC_FAMILY or FC_POSTSCRIPT_NAME objects in the property.
223 * This can be quite expensive, and should not be used more than once per font lookup. 223 * This can be quite expensive, and should not be used more than once per font lookup.
224 * This removes all of the weak elements after the last strong element. 224 * This removes all of the weak elements after the last strong element.
225 */ 225 */
226 static void remove_weak(FcPattern* pattern, const char object[]) { 226 static void remove_weak(FcPattern* pattern, const char object[]) {
227 FCLocker::AssertHeld(); 227 FCLocker::AssertHeld();
228 228
229 SkAutoFcObjectSet requestedObjectOnly(FcObjectSetBuild(object, NULL)); 229 SkAutoFcObjectSet requestedObjectOnly(FcObjectSetBuild(object, nullptr));
230 SkAutoFcPattern minimal(FcPatternFilter(pattern, requestedObjectOnly)); 230 SkAutoFcPattern minimal(FcPatternFilter(pattern, requestedObjectOnly));
231 231
232 int lastStrongId = -1; 232 int lastStrongId = -1;
233 int numIds; 233 int numIds;
234 SkWeakReturn result; 234 SkWeakReturn result;
235 for (int id = 0; ; ++id) { 235 for (int id = 0; ; ++id) {
236 result = is_weak(minimal, object, 0); 236 result = is_weak(minimal, object, 0);
237 if (kNoId_WeakReturn == result) { 237 if (kNoId_WeakReturn == result) {
238 numIds = id; 238 numIds = id;
239 break; 239 break;
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 SkAutoFcPattern pattern; 505 SkAutoFcPattern pattern;
506 fcpattern_from_skfontstyle(style, pattern); 506 fcpattern_from_skfontstyle(style, pattern);
507 FcConfigSubstitute(fFontMgr->fFC, pattern, FcMatchPattern); 507 FcConfigSubstitute(fFontMgr->fFC, pattern, FcMatchPattern);
508 FcDefaultSubstitute(pattern); 508 FcDefaultSubstitute(pattern);
509 509
510 FcResult result; 510 FcResult result;
511 FcFontSet* fontSets[1] = { fFontSet }; 511 FcFontSet* fontSets[1] = { fFontSet };
512 SkAutoFcPattern match(FcFontSetMatch(fFontMgr->fFC, 512 SkAutoFcPattern match(FcFontSetMatch(fFontMgr->fFC,
513 fontSets, SK_ARRAY_COUNT(fontSe ts), 513 fontSets, SK_ARRAY_COUNT(fontSe ts),
514 pattern, &result)); 514 pattern, &result));
515 if (NULL == match) { 515 if (nullptr == match) {
516 return NULL; 516 return nullptr;
517 } 517 }
518 518
519 return fFontMgr->createTypefaceFromFcPattern(match); 519 return fFontMgr->createTypefaceFromFcPattern(match);
520 } 520 }
521 521
522 private: 522 private:
523 SkAutoTUnref<const SkFontMgr_fontconfig> fFontMgr; 523 SkAutoTUnref<const SkFontMgr_fontconfig> fFontMgr;
524 SkAutoFcFontSet fFontSet; 524 SkAutoFcFontSet fFontSet;
525 }; 525 };
526 526
(...skipping 10 matching lines...) Expand all
537 static SkDataTable* GetFamilyNames(FcConfig* fcconfig) { 537 static SkDataTable* GetFamilyNames(FcConfig* fcconfig) {
538 FCLocker lock; 538 FCLocker lock;
539 539
540 SkTDArray<const char*> names; 540 SkTDArray<const char*> names;
541 SkTDArray<size_t> sizes; 541 SkTDArray<size_t> sizes;
542 542
543 static const FcSetName fcNameSet[] = { FcSetSystem, FcSetApplication }; 543 static const FcSetName fcNameSet[] = { FcSetSystem, FcSetApplication };
544 for (int setIndex = 0; setIndex < (int)SK_ARRAY_COUNT(fcNameSet); ++setI ndex) { 544 for (int setIndex = 0; setIndex < (int)SK_ARRAY_COUNT(fcNameSet); ++setI ndex) {
545 // Return value of FcConfigGetFonts must not be destroyed. 545 // Return value of FcConfigGetFonts must not be destroyed.
546 FcFontSet* allFonts(FcConfigGetFonts(fcconfig, fcNameSet[setIndex])) ; 546 FcFontSet* allFonts(FcConfigGetFonts(fcconfig, fcNameSet[setIndex])) ;
547 if (NULL == allFonts) { 547 if (nullptr == allFonts) {
548 continue; 548 continue;
549 } 549 }
550 550
551 for (int fontIndex = 0; fontIndex < allFonts->nfont; ++fontIndex) { 551 for (int fontIndex = 0; fontIndex < allFonts->nfont; ++fontIndex) {
552 FcPattern* current = allFonts->fonts[fontIndex]; 552 FcPattern* current = allFonts->fonts[fontIndex];
553 for (int id = 0; ; ++id) { 553 for (int id = 0; ; ++id) {
554 FcChar8* fcFamilyName; 554 FcChar8* fcFamilyName;
555 FcResult result = FcPatternGetString(current, FC_FAMILY, id, &fcFamilyName); 555 FcResult result = FcPatternGetString(current, FC_FAMILY, id, &fcFamilyName);
556 if (FcResultNoId == result) { 556 if (FcResultNoId == result) {
557 break; 557 break;
(...skipping 22 matching lines...) Expand all
580 580
581 mutable SkMutex fTFCacheMutex; 581 mutable SkMutex fTFCacheMutex;
582 mutable SkTypefaceCache fTFCache; 582 mutable SkTypefaceCache fTFCache;
583 /** Creates a typeface using a typeface cache. 583 /** Creates a typeface using a typeface cache.
584 * @param pattern a complete pattern from FcFontRenderPrepare. 584 * @param pattern a complete pattern from FcFontRenderPrepare.
585 */ 585 */
586 SkTypeface* createTypefaceFromFcPattern(FcPattern* pattern) const { 586 SkTypeface* createTypefaceFromFcPattern(FcPattern* pattern) const {
587 FCLocker::AssertHeld(); 587 FCLocker::AssertHeld();
588 SkAutoMutexAcquire ama(fTFCacheMutex); 588 SkAutoMutexAcquire ama(fTFCacheMutex);
589 SkTypeface* face = fTFCache.findByProcAndRef(FindByFcPattern, pattern); 589 SkTypeface* face = fTFCache.findByProcAndRef(FindByFcPattern, pattern);
590 if (NULL == face) { 590 if (nullptr == face) {
591 FcPatternReference(pattern); 591 FcPatternReference(pattern);
592 face = SkTypeface_fontconfig::Create(pattern); 592 face = SkTypeface_fontconfig::Create(pattern);
593 if (face) { 593 if (face) {
594 fTFCache.add(face, SkFontStyle()); 594 fTFCache.add(face, SkFontStyle());
595 } 595 }
596 } 596 }
597 return face; 597 return face;
598 } 598 }
599 599
600 public: 600 public:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 if (0 == FcStrCmpIgnoreCase(patternString, fontString)) { 651 if (0 == FcStrCmpIgnoreCase(patternString, fontString)) {
652 return true; 652 return true;
653 } 653 }
654 } 654 }
655 } 655 }
656 return false; 656 return false;
657 } 657 }
658 658
659 static bool FontAccessible(FcPattern* font) { 659 static bool FontAccessible(FcPattern* font) {
660 // FontConfig can return fonts which are unreadable. 660 // FontConfig can return fonts which are unreadable.
661 const char* filename = get_string(font, FC_FILE, NULL); 661 const char* filename = get_string(font, FC_FILE, nullptr);
662 if (NULL == filename) { 662 if (nullptr == filename) {
663 return false; 663 return false;
664 } 664 }
665 return sk_exists(filename, kRead_SkFILE_Flag); 665 return sk_exists(filename, kRead_SkFILE_Flag);
666 } 666 }
667 667
668 static bool FontFamilyNameMatches(FcPattern* font, FcPattern* pattern) { 668 static bool FontFamilyNameMatches(FcPattern* font, FcPattern* pattern) {
669 return AnyMatching(font, pattern, FC_FAMILY); 669 return AnyMatching(font, pattern, FC_FAMILY);
670 } 670 }
671 671
672 static bool FontContainsCharacter(FcPattern* font, uint32_t character) { 672 static bool FontContainsCharacter(FcPattern* font, uint32_t character) {
(...skipping 16 matching lines...) Expand all
689 689
690 SkFontStyleSet* onMatchFamily(const char familyName[]) const override { 690 SkFontStyleSet* onMatchFamily(const char familyName[]) const override {
691 FCLocker lock; 691 FCLocker lock;
692 692
693 SkAutoFcPattern pattern; 693 SkAutoFcPattern pattern;
694 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); 694 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName);
695 FcConfigSubstitute(fFC, pattern, FcMatchPattern); 695 FcConfigSubstitute(fFC, pattern, FcMatchPattern);
696 FcDefaultSubstitute(pattern); 696 FcDefaultSubstitute(pattern);
697 697
698 FcPattern* matchPattern; 698 FcPattern* matchPattern;
699 SkAutoFcPattern strongPattern(NULL); 699 SkAutoFcPattern strongPattern(nullptr);
700 if (familyName) { 700 if (familyName) {
701 strongPattern.reset(FcPatternDuplicate(pattern)); 701 strongPattern.reset(FcPatternDuplicate(pattern));
702 remove_weak(strongPattern, FC_FAMILY); 702 remove_weak(strongPattern, FC_FAMILY);
703 matchPattern = strongPattern; 703 matchPattern = strongPattern;
704 } else { 704 } else {
705 matchPattern = pattern; 705 matchPattern = pattern;
706 } 706 }
707 707
708 SkAutoFcFontSet matches; 708 SkAutoFcFontSet matches;
709 // TODO: Some families have 'duplicates' due to symbolic links. 709 // TODO: Some families have 'duplicates' due to symbolic links.
710 // The patterns are exactly the same except for the FC_FILE. 710 // The patterns are exactly the same except for the FC_FILE.
711 // It should be possible to collapse these patterns by normalizing. 711 // It should be possible to collapse these patterns by normalizing.
712 static const FcSetName fcNameSet[] = { FcSetSystem, FcSetApplication }; 712 static const FcSetName fcNameSet[] = { FcSetSystem, FcSetApplication };
713 for (int setIndex = 0; setIndex < (int)SK_ARRAY_COUNT(fcNameSet); ++setI ndex) { 713 for (int setIndex = 0; setIndex < (int)SK_ARRAY_COUNT(fcNameSet); ++setI ndex) {
714 // Return value of FcConfigGetFonts must not be destroyed. 714 // Return value of FcConfigGetFonts must not be destroyed.
715 FcFontSet* allFonts(FcConfigGetFonts(fFC, fcNameSet[setIndex])); 715 FcFontSet* allFonts(FcConfigGetFonts(fFC, fcNameSet[setIndex]));
716 if (NULL == allFonts) { 716 if (nullptr == allFonts) {
717 continue; 717 continue;
718 } 718 }
719 719
720 for (int fontIndex = 0; fontIndex < allFonts->nfont; ++fontIndex) { 720 for (int fontIndex = 0; fontIndex < allFonts->nfont; ++fontIndex) {
721 FcPattern* font = allFonts->fonts[fontIndex]; 721 FcPattern* font = allFonts->fonts[fontIndex];
722 if (FontAccessible(font) && FontFamilyNameMatches(font, matchPat tern)) { 722 if (FontAccessible(font) && FontFamilyNameMatches(font, matchPat tern)) {
723 FcFontSetAdd(matches, FcFontRenderPrepare(fFC, pattern, font )); 723 FcFontSetAdd(matches, FcFontRenderPrepare(fFC, pattern, font ));
724 } 724 }
725 } 725 }
726 } 726 }
(...skipping 14 matching lines...) Expand all
741 741
742 // We really want to match strong (prefered) and same (acceptable) only here. 742 // We really want to match strong (prefered) and same (acceptable) only here.
743 // If a family name was specified, assume that any weak matches after th e last strong match 743 // If a family name was specified, assume that any weak matches after th e last strong match
744 // are weak (default) and ignore them. 744 // are weak (default) and ignore them.
745 // The reason for is that after substitution the pattern for 'sans-serif ' looks like 745 // The reason for is that after substitution the pattern for 'sans-serif ' looks like
746 // "wwwwwwwwwwwwwwswww" where there are many weak but preferred names, f ollowed by defaults. 746 // "wwwwwwwwwwwwwwswww" where there are many weak but preferred names, f ollowed by defaults.
747 // So it is possible to have weakly matching but preferred names. 747 // So it is possible to have weakly matching but preferred names.
748 // In aliases, bindings are weak by default, so this is easy and common. 748 // In aliases, bindings are weak by default, so this is easy and common.
749 // If no family name was specified, we'll probably only get weak matches , but that's ok. 749 // If no family name was specified, we'll probably only get weak matches , but that's ok.
750 FcPattern* matchPattern; 750 FcPattern* matchPattern;
751 SkAutoFcPattern strongPattern(NULL); 751 SkAutoFcPattern strongPattern(nullptr);
752 if (familyName) { 752 if (familyName) {
753 strongPattern.reset(FcPatternDuplicate(pattern)); 753 strongPattern.reset(FcPatternDuplicate(pattern));
754 remove_weak(strongPattern, FC_FAMILY); 754 remove_weak(strongPattern, FC_FAMILY);
755 matchPattern = strongPattern; 755 matchPattern = strongPattern;
756 } else { 756 } else {
757 matchPattern = pattern; 757 matchPattern = pattern;
758 } 758 }
759 759
760 FcResult result; 760 FcResult result;
761 SkAutoFcPattern font(FcFontMatch(fFC, pattern, &result)); 761 SkAutoFcPattern font(FcFontMatch(fFC, pattern, &result));
762 if (NULL == font || !FontAccessible(font) || !FontFamilyNameMatches(font , matchPattern)) { 762 if (nullptr == font || !FontAccessible(font) || !FontFamilyNameMatches(f ont, matchPattern)) {
763 return NULL; 763 return nullptr;
764 } 764 }
765 765
766 return createTypefaceFromFcPattern(font); 766 return createTypefaceFromFcPattern(font);
767 } 767 }
768 768
769 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], 769 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
770 const SkFontStyle& style, 770 const SkFontStyle& style,
771 const char* bcp47[], 771 const char* bcp47[],
772 int bcp47Count, 772 int bcp47Count,
773 SkUnichar character) const o verride 773 SkUnichar character) const o verride
(...skipping 20 matching lines...) Expand all
794 FcLangSetAdd(langSet, (const FcChar8*)bcp47[i]); 794 FcLangSetAdd(langSet, (const FcChar8*)bcp47[i]);
795 } 795 }
796 FcPatternAddLangSet(pattern, FC_LANG, langSet); 796 FcPatternAddLangSet(pattern, FC_LANG, langSet);
797 } 797 }
798 798
799 FcConfigSubstitute(fFC, pattern, FcMatchPattern); 799 FcConfigSubstitute(fFC, pattern, FcMatchPattern);
800 FcDefaultSubstitute(pattern); 800 FcDefaultSubstitute(pattern);
801 801
802 FcResult result; 802 FcResult result;
803 SkAutoFcPattern font(FcFontMatch(fFC, pattern, &result)); 803 SkAutoFcPattern font(FcFontMatch(fFC, pattern, &result));
804 if (NULL == font || !FontAccessible(font) || !FontContainsCharacter(font , character)) { 804 if (nullptr == font || !FontAccessible(font) || !FontContainsCharacter(f ont, character)) {
805 return NULL; 805 return nullptr;
806 } 806 }
807 807
808 return createTypefaceFromFcPattern(font); 808 return createTypefaceFromFcPattern(font);
809 } 809 }
810 810
811 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* typeface, 811 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* typeface,
812 const SkFontStyle& style) const overrid e 812 const SkFontStyle& style) const overrid e
813 { 813 {
814 //TODO: should the SkTypeface_fontconfig know its family? 814 //TODO: should the SkTypeface_fontconfig know its family?
815 const SkTypeface_fontconfig* fcTypeface = 815 const SkTypeface_fontconfig* fcTypeface =
816 static_cast<const SkTypeface_fontconfig*>(typeface); 816 static_cast<const SkTypeface_fontconfig*>(typeface);
817 return this->matchFamilyStyle(get_string(fcTypeface->fPattern, FC_FAMILY ), style); 817 return this->matchFamilyStyle(get_string(fcTypeface->fPattern, FC_FAMILY ), style);
818 } 818 }
819 819
820 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override { 820 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override {
821 SkAutoTDelete<SkStreamAsset> stream(bareStream); 821 SkAutoTDelete<SkStreamAsset> stream(bareStream);
822 const size_t length = stream->getLength(); 822 const size_t length = stream->getLength();
823 if (length <= 0 || (1u << 30) < length) { 823 if (length <= 0 || (1u << 30) < length) {
824 return NULL; 824 return nullptr;
825 } 825 }
826 826
827 SkFontStyle style; 827 SkFontStyle style;
828 bool isFixedWidth = false; 828 bool isFixedWidth = false;
829 if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth, NU LL)) { 829 if (!fScanner.scanFont(stream, ttcIndex, nullptr, &style, &isFixedWidth, nullptr)) {
830 return NULL; 830 return nullptr;
831 } 831 }
832 832
833 return new SkTypeface_stream(new SkFontData(stream.detach(), ttcIndex, N ULL, 0), style, 833 return new SkTypeface_stream(new SkFontData(stream.detach(), ttcIndex, n ullptr, 0), style,
834 isFixedWidth); 834 isFixedWidth);
835 } 835 }
836 836
837 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { 837 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
838 return this->createFromStream(new SkMemoryStream(data), ttcIndex); 838 return this->createFromStream(new SkMemoryStream(data), ttcIndex);
839 } 839 }
840 840
841 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override { 841 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
842 return this->createFromStream(SkStream::NewFromFile(path), ttcIndex); 842 return this->createFromStream(SkStream::NewFromFile(path), ttcIndex);
843 } 843 }
844 844
845 SkTypeface* onCreateFromFontData(SkFontData* fontData) const override { 845 SkTypeface* onCreateFromFontData(SkFontData* fontData) const override {
846 SkStreamAsset* stream(fontData->getStream()); 846 SkStreamAsset* stream(fontData->getStream());
847 const size_t length = stream->getLength(); 847 const size_t length = stream->getLength();
848 if (length <= 0 || (1u << 30) < length) { 848 if (length <= 0 || (1u << 30) < length) {
849 return NULL; 849 return nullptr;
850 } 850 }
851 851
852 const int ttcIndex = fontData->getIndex(); 852 const int ttcIndex = fontData->getIndex();
853 SkFontStyle style; 853 SkFontStyle style;
854 bool isFixedWidth = false; 854 bool isFixedWidth = false;
855 if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth, NU LL)) { 855 if (!fScanner.scanFont(stream, ttcIndex, nullptr, &style, &isFixedWidth, nullptr)) {
856 return NULL; 856 return nullptr;
857 } 857 }
858 858
859 return new SkTypeface_stream(fontData, style, isFixedWidth); 859 return new SkTypeface_stream(fontData, style, isFixedWidth);
860 } 860 }
861 861
862 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], 862 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
863 unsigned styleBits) const overrid e { 863 unsigned styleBits) const overrid e {
864 bool bold = styleBits & SkTypeface::kBold; 864 bool bold = styleBits & SkTypeface::kBold;
865 bool italic = styleBits & SkTypeface::kItalic; 865 bool italic = styleBits & SkTypeface::kItalic;
866 SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight 866 SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight
867 : SkFontStyle::kNormal_Weight, 867 : SkFontStyle::kNormal_Weight,
868 SkFontStyle::kNormal_Width, 868 SkFontStyle::kNormal_Width,
869 italic ? SkFontStyle::kItalic_Slant 869 italic ? SkFontStyle::kItalic_Slant
870 : SkFontStyle::kUpright_Slant); 870 : SkFontStyle::kUpright_Slant);
871 SkAutoTUnref<SkTypeface> typeface(this->matchFamilyStyle(familyName, sty le)); 871 SkAutoTUnref<SkTypeface> typeface(this->matchFamilyStyle(familyName, sty le));
872 if (typeface.get()) { 872 if (typeface.get()) {
873 return typeface.detach(); 873 return typeface.detach();
874 } 874 }
875 875
876 return this->matchFamilyStyle(NULL, style); 876 return this->matchFamilyStyle(nullptr, style);
877 } 877 }
878 }; 878 };
879 879
880 SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc) { 880 SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc) {
881 return new SkFontMgr_fontconfig(fc); 881 return new SkFontMgr_fontconfig(fc);
882 } 882 }
OLDNEW
« no previous file with comments | « src/ports/SkFontMgr_empty_factory.cpp ('k') | src/ports/SkFontMgr_fontconfig_factory.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698