add impls for createfromstream for fontconfig fontmgr

git-svn-id: http://skia.googlecode.com/svn/trunk@10469 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2013-07-31 18:49:33 +00:00
parent cde269a6a6
commit b6bd24d31f
2 changed files with 26 additions and 3 deletions

View File

@ -162,14 +162,23 @@ SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face,
}
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);
}

View File

@ -262,11 +262,25 @@ protected:
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[],