Chromium Code Reviews| Index: src/core/SkFontDescriptor.cpp |
| diff --git a/src/core/SkFontDescriptor.cpp b/src/core/SkFontDescriptor.cpp |
| index b2622d930007849b69782e003f5bec43d3c52d0d..84b40e3946a055c8d1feebb767487afe8bdb403e 100644 |
| --- a/src/core/SkFontDescriptor.cpp |
| +++ b/src/core/SkFontDescriptor.cpp |
| @@ -17,12 +17,13 @@ enum { |
| // These count backwards from 0xFF, so as not to collide with the SFNT |
| // defines for names in its 'name' table. |
| + kFontAxes = 0xFC, |
| kFontIndex = 0xFD, |
| - kFontFileName = 0xFE, |
| + kFontFileName = 0xFE, // Deprecated |
| kSentinel = 0xFF, |
| }; |
| -SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) : fFontIndex(0), fStyle(style) { } |
| +SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) : fStyle(style) { } |
| static void read_string(SkStream* stream, SkString* string) { |
| const uint32_t length = SkToU32(stream->readPackedUInt()); |
| @@ -32,8 +33,7 @@ static void read_string(SkStream* stream, SkString* string) { |
| } |
| } |
| -static void write_string(SkWStream* stream, const SkString& string, |
| - uint32_t id) { |
| +static void write_string(SkWStream* stream, const SkString& string, uint32_t id) { |
| if (!string.isEmpty()) { |
| stream->writePackedUInt(id); |
| stream->writePackedUInt(string.size()); |
| @@ -50,9 +50,12 @@ static void write_uint(SkWStream* stream, size_t n, uint32_t id) { |
| stream->writePackedUInt(n); |
| } |
| -SkFontDescriptor::SkFontDescriptor(SkStream* stream) : fFontIndex(0) { |
| +SkFontDescriptor::SkFontDescriptor(SkStream* stream) { |
| fStyle = (SkTypeface::Style)stream->readPackedUInt(); |
| + SkAutoSTMalloc<4, SkFixed> axis; |
|
bungeman-skia
2015/04/01 20:38:28
It would be nice to break up the serialization of
|
| + size_t axisCount = 0; |
| + size_t index = 0; |
| for (size_t id; (id = stream->readPackedUInt()) != kSentinel;) { |
| switch (id) { |
| case kFontFamilyName: |
| @@ -64,12 +67,21 @@ SkFontDescriptor::SkFontDescriptor(SkStream* stream) : fFontIndex(0) { |
| case kPostscriptName: |
| read_string(stream, &fPostscriptName); |
| break; |
| + case kFontAxes: |
| + axisCount = read_uint(stream); |
| + axis.reset(axisCount); |
| + for (size_t i = 0; i < axisCount; ++i) { |
| + axis[i] = read_uint(stream); |
| + } |
| + break; |
| case kFontIndex: |
| - fFontIndex = read_uint(stream); |
| + index = read_uint(stream); |
| break; |
| - case kFontFileName: |
| - read_string(stream, &fFontFileName); |
| + case kFontFileName: { |
| + SkString fontFileName; |
| + read_string(stream, &fontFileName); |
| break; |
| + } |
| default: |
| SkDEBUGFAIL("Unknown id used by a font descriptor"); |
| return; |
| @@ -80,7 +92,8 @@ SkFontDescriptor::SkFontDescriptor(SkStream* stream) : fFontIndex(0) { |
| if (length > 0) { |
| SkAutoTUnref<SkData> data(SkData::NewUninitialized(length)); |
| if (stream->read(data->writable_data(), length) == length) { |
| - fFontData.reset(SkNEW_ARGS(SkMemoryStream, (data))); |
| + fFontData.reset(new SkFontData(SkNEW_ARGS(SkMemoryStream, (data)), index, |
| + axisCount, axis)); |
| } |
| } |
| } |
| @@ -91,17 +104,23 @@ void SkFontDescriptor::serialize(SkWStream* stream) { |
| write_string(stream, fFamilyName, kFontFamilyName); |
| write_string(stream, fFullName, kFullName); |
| write_string(stream, fPostscriptName, kPostscriptName); |
| - write_string(stream, fFontFileName, kFontFileName); |
| - if (fFontIndex) { |
| - write_uint(stream, fFontIndex, kFontIndex); |
| + if (fFontData->getIndex()) { |
|
bungeman-skia
2015/04/01 20:38:28
Might not have a fontData here.
|
| + write_uint(stream, fFontData->getIndex(), kFontIndex); |
| + } |
| + if (fFontData->getAxisCount()) { |
| + write_uint(stream, fFontData->getAxisCount(), kFontAxes); |
| + for (int i = 0; i < fFontData->getAxisCount(); ++i) { |
| + stream->writePackedUInt(fFontData->getAxis()[i]); |
| + } |
| } |
| stream->writePackedUInt(kSentinel); |
| - if (fFontData) { |
| - size_t length = fFontData->getLength(); |
| + if (fFontData->hasStream()) { |
| + SkAutoTDelete<SkStreamAsset> fontData(fFontData->transferStream()); |
| + size_t length = fontData->getLength(); |
| stream->writePackedUInt(length); |
| - stream->writeStream(fFontData, length); |
| + stream->writeStream(fontData, length); |
| } else { |
| stream->writePackedUInt(0); |
| } |