Chromium Code Reviews| Index: src/core/SkTypeface.cpp |
| diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp |
| index 0f5d70b1a8ccbe28ce2c51252223e2e70f11ed31..6d9759f42c4c536aec4492d9da24ea938a6bef66 100644 |
| --- a/src/core/SkTypeface.cpp |
| +++ b/src/core/SkTypeface.cpp |
| @@ -143,6 +143,11 @@ SkTypeface* SkTypeface::CreateFromStream(SkStreamAsset* stream, int index) { |
| return fm->createFromStream(stream, index); |
| } |
| +SkTypeface* SkTypeface::CreateFromFontData(SkFontData* data) { |
| + SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| + return fm->createFromFontData(data); |
| +} |
| + |
| SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) { |
| SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| return fm->createFromFile(path, index); |
| @@ -156,10 +161,8 @@ void SkTypeface::serialize(SkWStream* wstream) const { |
| this->onGetFontDescriptor(&desc, &isLocal); |
| // Embed font data if it's a local font. |
| - if (isLocal && !desc.hasFontData()) { |
| - int ttcIndex; |
| - desc.setFontData(this->onOpenStream(&ttcIndex)); |
| - desc.setFontIndex(ttcIndex); |
| + if (!desc.hasFontData()) { |
|
bungeman-skia
2015/05/13 23:04:44
Whoops, meant to leave the isLocal. It shouldn't m
|
| + desc.setFontData(this->onCreateFontData()); |
| } |
| desc.serialize(wstream); |
| } |
| @@ -171,18 +174,16 @@ void SkTypeface::serializeForcingEmbedding(SkWStream* wstream) const { |
| // Always embed font data. |
| if (!desc.hasFontData()) { |
| - int ttcIndex; |
| - desc.setFontData(this->onOpenStream(&ttcIndex)); |
| - desc.setFontIndex(ttcIndex); |
| + desc.setFontData(this->onCreateFontData()); |
| } |
| desc.serialize(wstream); |
| } |
| SkTypeface* SkTypeface::Deserialize(SkStream* stream) { |
| SkFontDescriptor desc(stream); |
| - SkStreamAsset* data = desc.transferFontData(); |
| + SkFontData* data = desc.detachFontData(); |
| if (data) { |
| - SkTypeface* typeface = SkTypeface::CreateFromStream(data, desc.getFontIndex()); |
| + SkTypeface* typeface = SkTypeface::CreateFromFontData(data); |
| if (typeface) { |
| return typeface; |
| } |
| @@ -218,6 +219,17 @@ SkStreamAsset* SkTypeface::openStream(int* ttcIndex) const { |
| return this->onOpenStream(ttcIndex); |
| } |
| +SkFontData* SkTypeface::createFontData() const { |
| + return this->onCreateFontData(); |
| +} |
| + |
| +// This implementation is temporary until this method can be made pure virtual. |
| +SkFontData* SkTypeface::onCreateFontData() const { |
| + int index; |
| + SkAutoTDelete<SkStreamAsset> stream(this->onOpenStream(&index)); |
| + return new SkFontData(stream.detach(), index, NULL, 0); |
| +}; |
| + |
| int SkTypeface::charsToGlyphs(const void* chars, Encoding encoding, |
| uint16_t glyphs[], int glyphCount) const { |
| if (glyphCount <= 0) { |