Chromium Code Reviews| Index: src/core/SkTypeface.cpp |
| =================================================================== |
| --- src/core/SkTypeface.cpp (revision 8346) |
| +++ src/core/SkTypeface.cpp (working copy) |
| @@ -1,4 +1,3 @@ |
| - |
| /* |
| * Copyright 2011 The Android Open Source Project |
| * |
| @@ -6,10 +5,12 @@ |
| * found in the LICENSE file. |
| */ |
| - |
| #include "SkAdvancedTypefaceMetrics.h" |
| +#include "SkFontDescriptor.h" |
| +#include "SkFontHost.h" |
| +#include "SkFontStream.h" |
| +#include "SkStream.h" |
| #include "SkTypeface.h" |
| -#include "SkFontHost.h" |
| SK_DEFINE_INST_COUNT(SkTypeface) |
| @@ -88,19 +89,42 @@ |
| /////////////////////////////////////////////////////////////////////////////// |
| -void SkTypeface::serialize(SkWStream* stream) const { |
| - SkFontHost::Serialize(this, stream); |
| +void SkTypeface::serialize(SkWStream* wstream) const { |
| + bool isLocal = false; |
| + SkFontDescriptor desc(this->style()); |
| + this->onGetFontDescriptor(&desc, &isLocal); |
| + |
| + desc.serialize(wstream); |
| + if (isLocal) { |
| + int ttcIndex; // TODO: write this to the stream? |
|
bungeman-skia
2013/03/22 21:04:05
Yes, we need a issue to track this.
reed1
2013/03/25 12:26:27
Done.
|
| + 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); |
| + } |
| } |
| SkTypeface* SkTypeface::Deserialize(SkStream* stream) { |
| - return SkFontHost::Deserialize(stream); |
| -} |
| + SkFontDescriptor desc(stream); |
| + size_t length = stream->readPackedUInt(); |
| + if (length > 0) { |
| + void* addr = sk_malloc_flags(length, 0); |
| + if (addr) { |
| + SkAutoTUnref<SkStream> localStream(SkNEW_ARGS(SkMemoryStream, |
| + (addr, length, false))); |
| + return SkTypeface::CreateFromStream(localStream.get()); |
|
bungeman-skia
2013/03/22 21:04:05
In the same issue, or maybe here in comment, note
reed1
2013/03/25 12:26:27
Done.
|
| + } |
| + // failed to allocate, so just skip and create-from-name |
| + stream->skip(length); |
| + } |
| -SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics( |
| - SkAdvancedTypefaceMetrics::PerGlyphInfo info, |
| - const uint32_t* glyphIDs, |
| - uint32_t glyphIDsCount) const { |
| - return this->onGetAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount); |
| + return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle()); |
| } |
| /////////////////////////////////////////////////////////////////////////////// |
| @@ -136,11 +160,16 @@ |
| return this->onGetUPEM(); |
| } |
| +SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics( |
| + SkAdvancedTypefaceMetrics::PerGlyphInfo info, |
| + const uint32_t* glyphIDs, |
| + uint32_t glyphIDsCount) const { |
| + return this->onGetAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount); |
| +} |
| + |
| /////////////////////////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////////////////////////// |
| -#include "SkFontDescriptor.h" |
| - |
| int SkTypeface::onGetUPEM() const { |
| int upem = 0; |
| @@ -155,13 +184,6 @@ |
| return upem; |
| } |
| -void SkTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const { |
| - desc->setStyle(this->style()); |
| -} |
| - |
| -#include "SkFontStream.h" |
| -#include "SkStream.h" |
| - |
| int SkTypeface::onGetTableTags(SkFontTableTag tags[]) const { |
| int ttcIndex; |
| SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex)); |
| @@ -176,3 +198,4 @@ |
| ? SkFontStream::GetTableData(stream, ttcIndex, tag, offset, length, data) |
| : 0; |
| } |
| + |