add impls for createfromstream for fontconfig fontmgr
git-svn-id: http://skia.googlecode.com/svn/trunk@10469 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkFontHost.cpp b/src/core/SkFontHost.cpp
index 11f6813..799b95b 100644
--- a/src/core/SkFontHost.cpp
+++ b/src/core/SkFontHost.cpp
@@ -162,14 +162,23 @@
}
SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) {
+ if (NULL == data) {
+ return NULL;
+ }
return this->onCreateFromData(data, ttcIndex);
}
SkTypeface* SkFontMgr::createFromStream(SkStream* stream, int ttcIndex) {
+ if (NULL == stream) {
+ return NULL;
+ }
return this->onCreateFromStream(stream, ttcIndex);
}
SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) {
+ if (NULL == path) {
+ return NULL;
+ }
return this->onCreateFromFile(path, ttcIndex);
}
diff --git a/src/fonts/SkFontMgr_fontconfig.cpp b/src/fonts/SkFontMgr_fontconfig.cpp
index 1c87a72..27b5f31 100644
--- a/src/fonts/SkFontMgr_fontconfig.cpp
+++ b/src/fonts/SkFontMgr_fontconfig.cpp
@@ -262,11 +262,25 @@
const SkFontStyle&) { return NULL; }
virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) { return NULL; }
- virtual SkTypeface* onCreateFromStream(SkStream*, int ttcIndex) {
- return NULL;
+
+ virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) {
+ const size_t length = stream->getLength();
+ if (!length) {
+ return NULL;
+ }
+ if (length >= 1024 * 1024 * 1024) {
+ return NULL; // don't accept too large fonts (>= 1GB) for safety.
+ }
+
+ // TODO should the caller give us the style?
+ SkTypeface::Style style = SkTypeface::kNormal;
+ SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, stream));
+ return face;
}
+
virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) {
- return NULL;
+ SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
+ return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL;
}
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],