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 "SkFontHost.h" | 8 #include "SkFontHost.h" |
9 #include "SkFontHost_FreeType_common.h" | 9 #include "SkFontHost_FreeType_common.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
11 #include "SkFontMgr.h" | 11 #include "SkFontMgr.h" |
12 #include "SkDescriptor.h" | 12 #include "SkDescriptor.h" |
13 #include "SkOSFile.h" | 13 #include "SkOSFile.h" |
14 #include "SkPaint.h" | 14 #include "SkPaint.h" |
15 #include "SkRTConf.h" | |
15 #include "SkString.h" | 16 #include "SkString.h" |
16 #include "SkStream.h" | 17 #include "SkStream.h" |
17 #include "SkThread.h" | 18 #include "SkThread.h" |
18 #include "SkTSearch.h" | 19 #include "SkTSearch.h" |
19 #include "SkTypefaceCache.h" | 20 #include "SkTypefaceCache.h" |
20 #include "SkTArray.h" | 21 #include "SkTArray.h" |
21 | 22 |
22 #include <limits> | 23 #include <limits> |
23 | 24 |
24 #ifndef SK_FONT_FILE_PREFIX | 25 #ifndef SK_FONT_FILE_PREFIX |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 *ttcIndex = this->getIndex(); | 95 *ttcIndex = this->getIndex(); |
95 return fStream->duplicate(); | 96 return fStream->duplicate(); |
96 } | 97 } |
97 | 98 |
98 private: | 99 private: |
99 const SkAutoTUnref<const SkStream> fStream; | 100 const SkAutoTUnref<const SkStream> fStream; |
100 | 101 |
101 typedef SkTypeface_Custom INHERITED; | 102 typedef SkTypeface_Custom INHERITED; |
102 }; | 103 }; |
103 | 104 |
105 // This configuration option is useful if we need to open and hold handles to | |
106 // all found system font data (e.g., for skfiddle, where the application can't | |
107 // access the filesystem to read fonts on demand) | |
108 | |
109 SK_CONF_DECLARE(bool, c_CustomTypefaceRetain, "fonts.customFont.retainAllData", false, | |
110 "Retain the open stream for each found font on the system."); | |
111 | |
104 /** The file SkTypeface implementation for the custom font manager. */ | 112 /** The file SkTypeface implementation for the custom font manager. */ |
105 class SkTypeface_File : public SkTypeface_Custom { | 113 class SkTypeface_File : public SkTypeface_Custom { |
106 public: | 114 public: |
107 SkTypeface_File(const SkFontStyle& style, bool isFixedPitch, bool sysFont, | 115 SkTypeface_File(const SkFontStyle& style, bool isFixedPitch, bool sysFont, |
108 const SkString familyName, const char path[], int index) | 116 const SkString familyName, const char path[], int index) |
109 : INHERITED(style, isFixedPitch, sysFont, familyName, index) | 117 : INHERITED(style, isFixedPitch, sysFont, familyName, index) |
110 , fPath(path) | 118 , fPath(path) |
111 { } | 119 , fStream(NULL) |
bungeman-skia
2014/11/19 15:14:13
I prefer the form
, fStream(c_CustomTypefaceRetai
| |
120 { | |
121 if (c_CustomTypefaceRetain) { | |
122 fStream = SkStream::NewFromFile(fPath.c_str()); | |
123 } | |
124 } | |
112 | 125 |
113 virtual const char* getUniqueString() const SK_OVERRIDE { | 126 virtual const char* getUniqueString() const SK_OVERRIDE { |
114 const char* str = strrchr(fPath.c_str(), '/'); | 127 const char* str = strrchr(fPath.c_str(), '/'); |
115 if (str) { | 128 if (str) { |
116 str += 1; // skip the '/' | 129 str += 1; // skip the '/' |
117 } | 130 } |
118 return str; | 131 return str; |
119 } | 132 } |
120 | 133 |
121 protected: | 134 protected: |
122 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { | 135 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
123 *ttcIndex = this->getIndex(); | 136 *ttcIndex = this->getIndex(); |
124 return SkStream::NewFromFile(fPath.c_str()); | 137 if (NULL != fStream) { |
bungeman-skia
2014/11/19 15:14:14
I think we're just using
if (fStream.get()) {
th
| |
138 return fStream->duplicate(); | |
139 } else { | |
140 return SkStream::NewFromFile(fPath.c_str()); | |
141 } | |
125 } | 142 } |
126 | 143 |
127 private: | 144 private: |
128 SkString fPath; | 145 SkString fPath; |
146 SkAutoTUnref<SkStream> fStream; | |
bungeman-skia
2014/11/19 15:14:13
Above (in SkTypeface_Stream) this is
const SkAuto
| |
129 | 147 |
130 typedef SkTypeface_Custom INHERITED; | 148 typedef SkTypeface_Custom INHERITED; |
131 }; | 149 }; |
132 | 150 |
133 /////////////////////////////////////////////////////////////////////////////// | 151 /////////////////////////////////////////////////////////////////////////////// |
134 | 152 |
135 /** | 153 /** |
136 * SkFontStyleSet_Custom | 154 * SkFontStyleSet_Custom |
137 * | 155 * |
138 * This class is used by SkFontMgr_Custom to hold SkTypeface_Custom families. | 156 * This class is used by SkFontMgr_Custom to hold SkTypeface_Custom families. |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 | 435 |
418 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; | 436 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; |
419 SkFontStyleSet_Custom* gDefaultFamily; | 437 SkFontStyleSet_Custom* gDefaultFamily; |
420 SkTypeface* gDefaultNormal; | 438 SkTypeface* gDefaultNormal; |
421 SkTypeface_FreeType::Scanner fScanner; | 439 SkTypeface_FreeType::Scanner fScanner; |
422 }; | 440 }; |
423 | 441 |
424 SkFontMgr* SkFontMgr::Factory() { | 442 SkFontMgr* SkFontMgr::Factory() { |
425 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); | 443 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); |
426 } | 444 } |
OLD | NEW |