diff options
author | humper <humper@google.com> | 2014-11-19 08:32:19 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-19 08:32:19 -0800 |
commit | ad5e9a53270b96dcbfc9aa678c91157407058449 (patch) | |
tree | 8f3409d1fcb812a26aa738da113389000e8fef54 /src | |
parent | 02bcd9db00ff896a09ac99eb441ee10cfb0ef6c4 (diff) |
add runtime config option to retain stream for custom typefaces
BUG=skia:
Review URL: https://codereview.chromium.org/729973004
Diffstat (limited to 'src')
-rw-r--r-- | src/ports/SkFontHost_linux.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp index 6003c095c1..853416c2f4 100644 --- a/src/ports/SkFontHost_linux.cpp +++ b/src/ports/SkFontHost_linux.cpp @@ -12,6 +12,7 @@ #include "SkDescriptor.h" #include "SkOSFile.h" #include "SkPaint.h" +#include "SkRTConf.h" #include "SkString.h" #include "SkStream.h" #include "SkThread.h" @@ -101,6 +102,13 @@ private: typedef SkTypeface_Custom INHERITED; }; +// This configuration option is useful if we need to open and hold handles to +// all found system font data (e.g., for skfiddle, where the application can't +// access the filesystem to read fonts on demand) + +SK_CONF_DECLARE(bool, c_CustomTypefaceRetain, "fonts.customFont.retainAllData", false, + "Retain the open stream for each found font on the system."); + /** The file SkTypeface implementation for the custom font manager. */ class SkTypeface_File : public SkTypeface_Custom { public: @@ -108,6 +116,7 @@ public: const SkString familyName, const char path[], int index) : INHERITED(style, isFixedPitch, sysFont, familyName, index) , fPath(path) + , fStream(c_CustomTypefaceRetain ? SkStream::NewFromFile(fPath.c_str()) : NULL) { } virtual const char* getUniqueString() const SK_OVERRIDE { @@ -121,11 +130,16 @@ public: protected: virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { *ttcIndex = this->getIndex(); - return SkStream::NewFromFile(fPath.c_str()); + if (fStream.get()) { + return fStream->duplicate(); + } else { + return SkStream::NewFromFile(fPath.c_str()); + } } private: SkString fPath; + const SkAutoTUnref<SkStreamAsset> fStream; typedef SkTypeface_Custom INHERITED; }; |