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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 * Like all synthetic information, such information must be passed with the fon
t data. | 58 * Like all synthetic information, such information must be passed with the fon
t data. |
59 */ | 59 */ |
60 | 60 |
61 namespace { | 61 namespace { |
62 | 62 |
63 // Fontconfig is not threadsafe before 2.10.91. Before that, we lock with a glob
al mutex. | 63 // Fontconfig is not threadsafe before 2.10.91. Before that, we lock with a glob
al mutex. |
64 // See http://skbug.com/1497 for background. | 64 // See http://skbug.com/1497 for background. |
65 SK_DECLARE_STATIC_MUTEX(gFCMutex); | 65 SK_DECLARE_STATIC_MUTEX(gFCMutex); |
66 | 66 |
67 #ifdef SK_DEBUG | 67 #ifdef SK_DEBUG |
68 void *CreateThreadFcLocked() { return SkNEW_ARGS(bool, (false)); } | 68 void* CreateThreadFcLocked() { return new bool(false); } |
69 void DeleteThreadFcLocked(void* v) { SkDELETE(static_cast<bool*>(v)); } | 69 void DeleteThreadFcLocked(void* v) { delete static_cast<bool*>(v); } |
70 # define THREAD_FC_LOCKED \ | 70 # define THREAD_FC_LOCKED \ |
71 static_cast<bool*>(SkTLS::Get(CreateThreadFcLocked, DeleteThreadFcLocked
)) | 71 static_cast<bool*>(SkTLS::Get(CreateThreadFcLocked, DeleteThreadFcLocked
)) |
72 #endif | 72 #endif |
73 | 73 |
74 struct FCLocker { | 74 struct FCLocker { |
75 // Assume FcGetVersion() has always been thread safe. | 75 // Assume FcGetVersion() has always been thread safe. |
76 | 76 |
77 FCLocker() { | 77 FCLocker() { |
78 if (FcGetVersion() < 21091) { | 78 if (FcGetVersion() < 21091) { |
79 gFCMutex.acquire(); | 79 gFCMutex.acquire(); |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 private: | 409 private: |
410 const SkAutoTDelete<const SkFontData> fData; | 410 const SkAutoTDelete<const SkFontData> fData; |
411 | 411 |
412 typedef SkTypeface_FreeType INHERITED; | 412 typedef SkTypeface_FreeType INHERITED; |
413 }; | 413 }; |
414 | 414 |
415 class SkTypeface_fontconfig : public SkTypeface_FreeType { | 415 class SkTypeface_fontconfig : public SkTypeface_FreeType { |
416 public: | 416 public: |
417 /** @param pattern takes ownership of the reference. */ | 417 /** @param pattern takes ownership of the reference. */ |
418 static SkTypeface_fontconfig* Create(FcPattern* pattern) { | 418 static SkTypeface_fontconfig* Create(FcPattern* pattern) { |
419 return SkNEW_ARGS(SkTypeface_fontconfig, (pattern)); | 419 return new SkTypeface_fontconfig(pattern); |
420 } | 420 } |
421 mutable SkAutoFcPattern fPattern; | 421 mutable SkAutoFcPattern fPattern; |
422 | 422 |
423 void onGetFamilyName(SkString* familyName) const override { | 423 void onGetFamilyName(SkString* familyName) const override { |
424 *familyName = get_string(fPattern, FC_FAMILY); | 424 *familyName = get_string(fPattern, FC_FAMILY); |
425 } | 425 } |
426 | 426 |
427 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const over
ride { | 427 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const over
ride { |
428 FCLocker lock; | 428 FCLocker lock; |
429 desc->setFamilyName(get_string(fPattern, FC_FAMILY)); | 429 desc->setFamilyName(get_string(fPattern, FC_FAMILY)); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
727 | 727 |
728 return SkNEW_ARGS(StyleSet, (this, matches.detach())); | 728 return new StyleSet(this, matches.detach()); |
729 } | 729 } |
730 | 730 |
731 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], | 731 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], |
732 const SkFontStyle& style) const overr
ide | 732 const SkFontStyle& style) const overr
ide |
733 { | 733 { |
734 FCLocker lock; | 734 FCLocker lock; |
735 | 735 |
736 SkAutoFcPattern pattern; | 736 SkAutoFcPattern pattern; |
737 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); | 737 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); |
738 fcpattern_from_skfontstyle(style, pattern); | 738 fcpattern_from_skfontstyle(style, pattern); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 if (length <= 0 || (1u << 30) < length) { | 823 if (length <= 0 || (1u << 30) < length) { |
824 return NULL; | 824 return NULL; |
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, NULL, &style, &isFixedWidth, NU
LL)) { |
830 return NULL; | 830 return NULL; |
831 } | 831 } |
832 | 832 |
833 return SkNEW_ARGS(SkTypeface_stream, (new SkFontData(stream.detach(), tt
cIndex, NULL, 0), | 833 return new SkTypeface_stream(new SkFontData(stream.detach(), ttcIndex, N
ULL, 0), style, |
834 style, 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(SkNEW_ARGS(SkMemoryStream, (data)), ttcInd
ex); | 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 NULL; |
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, NULL, &style, &isFixedWidth, NU
LL)) { |
856 return NULL; | 856 return NULL; |
857 } | 857 } |
858 | 858 |
859 return SkNEW_ARGS(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(NULL, 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 } |
OLD | NEW |