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

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

Issue 729973004: add runtime config option to retain stream for custom typefaces (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Ben comments" Created 6 years, 1 month 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 | « no previous file | no next file » | 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 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
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)
119 , fStream(c_CustomTypefaceRetain ? SkStream::NewFromFile(fPath.c_str()) : NULL)
111 { } 120 { }
112 121
113 virtual const char* getUniqueString() const SK_OVERRIDE { 122 virtual const char* getUniqueString() const SK_OVERRIDE {
114 const char* str = strrchr(fPath.c_str(), '/'); 123 const char* str = strrchr(fPath.c_str(), '/');
115 if (str) { 124 if (str) {
116 str += 1; // skip the '/' 125 str += 1; // skip the '/'
117 } 126 }
118 return str; 127 return str;
119 } 128 }
120 129
121 protected: 130 protected:
122 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { 131 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE {
123 *ttcIndex = this->getIndex(); 132 *ttcIndex = this->getIndex();
124 return SkStream::NewFromFile(fPath.c_str()); 133 if (fStream.get()) {
134 return fStream->duplicate();
135 } else {
136 return SkStream::NewFromFile(fPath.c_str());
137 }
125 } 138 }
126 139
127 private: 140 private:
128 SkString fPath; 141 SkString fPath;
142 const SkAutoTUnref<SkStreamAsset> fStream;
129 143
130 typedef SkTypeface_Custom INHERITED; 144 typedef SkTypeface_Custom INHERITED;
131 }; 145 };
132 146
133 /////////////////////////////////////////////////////////////////////////////// 147 ///////////////////////////////////////////////////////////////////////////////
134 148
135 /** 149 /**
136 * SkFontStyleSet_Custom 150 * SkFontStyleSet_Custom
137 * 151 *
138 * This class is used by SkFontMgr_Custom to hold SkTypeface_Custom families. 152 * This class is used by SkFontMgr_Custom to hold SkTypeface_Custom families.
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 431
418 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; 432 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies;
419 SkFontStyleSet_Custom* gDefaultFamily; 433 SkFontStyleSet_Custom* gDefaultFamily;
420 SkTypeface* gDefaultNormal; 434 SkTypeface* gDefaultNormal;
421 SkTypeface_FreeType::Scanner fScanner; 435 SkTypeface_FreeType::Scanner fScanner;
422 }; 436 };
423 437
424 SkFontMgr* SkFontMgr::Factory() { 438 SkFontMgr* SkFontMgr::Factory() {
425 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); 439 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX);
426 } 440 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698