| Index: src/core/SkTypeface.cpp
|
| diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
|
| index 74dd5d96b91cb67ff7b92f0417baca0a8e179bea..d7da131d13b2db7786efafc33221133eb927aa6d 100644
|
| --- a/src/core/SkTypeface.cpp
|
| +++ b/src/core/SkTypeface.cpp
|
| @@ -147,14 +147,14 @@ SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) {
|
| return fm->matchFaceStyle(family, newStyle);
|
| }
|
|
|
| -SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) {
|
| +SkTypeface* SkTypeface::CreateFromStream(SkStream* stream, int index) {
|
| SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
|
| - return fm->createFromStream(stream);
|
| + return fm->createFromStream(stream, index);
|
| }
|
|
|
| -SkTypeface* SkTypeface::CreateFromFile(const char path[]) {
|
| +SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) {
|
| SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
|
| - return fm->createFromFile(path);
|
| + return fm->createFromFile(path, index);
|
| }
|
|
|
| ///////////////////////////////////////////////////////////////////////////////
|
| @@ -164,45 +164,24 @@ void SkTypeface::serialize(SkWStream* wstream) const {
|
| SkFontDescriptor desc(this->style());
|
| this->onGetFontDescriptor(&desc, &isLocal);
|
|
|
| - desc.serialize(wstream);
|
| - if (isLocal) {
|
| - int ttcIndex; // TODO: write this to the stream?
|
| - SkAutoTUnref<SkStream> rstream(this->openStream(&ttcIndex));
|
| - if (rstream.get()) {
|
| - size_t length = rstream->getLength();
|
| - wstream->writePackedUInt(length);
|
| - wstream->writeStream(rstream, length);
|
| - } else {
|
| - wstream->writePackedUInt(0);
|
| - }
|
| - } else {
|
| - wstream->writePackedUInt(0);
|
| + if (isLocal && NULL == desc.getFontData()) {
|
| + int ttcIndex;
|
| + desc.setFontData(this->onOpenStream(&ttcIndex));
|
| + desc.setFontIndex(ttcIndex);
|
| }
|
| +
|
| + desc.serialize(wstream);
|
| }
|
|
|
| SkTypeface* SkTypeface::Deserialize(SkStream* stream) {
|
| SkFontDescriptor desc(stream);
|
| - size_t length = stream->readPackedUInt();
|
| - if (length > 0) {
|
| - void* addr = sk_malloc_flags(length, 0);
|
| - if (addr) {
|
| - SkAutoTUnref<SkMemoryStream> localStream(SkNEW(SkMemoryStream));
|
| - localStream->setMemoryOwned(addr, length);
|
| -
|
| - if (stream->read(addr, length) == length) {
|
| - return SkTypeface::CreateFromStream(localStream.get());
|
| - } else {
|
| - // Failed to read the full font data, so fall through and try to create from name.
|
| - // If this is because of EOF, all subsequent reads from the stream will be EOF.
|
| - // If this is because of a stream error, the stream is in an error state,
|
| - // do not attempt to skip any remaining bytes.
|
| - }
|
| - } else {
|
| - // failed to allocate, so just skip and create-from-name
|
| - stream->skip(length);
|
| + SkStream* data = desc.getFontData();
|
| + if (data) {
|
| + SkTypeface* typeface = SkTypeface::CreateFromStream(data, desc.getFontIndex());
|
| + if (typeface) {
|
| + return typeface;
|
| }
|
| }
|
| -
|
| return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle());
|
| }
|
|
|
|
|