Index: src/core/SkFontDescriptor.cpp |
diff --git a/src/core/SkFontDescriptor.cpp b/src/core/SkFontDescriptor.cpp |
index 5088ed7687bcec8dae2954ca2c5d3cf4aaa5b43b..7426894b8c8c02c6370868b0f5200b4ab95938dd 100644 |
--- a/src/core/SkFontDescriptor.cpp |
+++ b/src/core/SkFontDescriptor.cpp |
@@ -7,6 +7,7 @@ |
#include "SkFontDescriptor.h" |
#include "SkStream.h" |
+#include <SkData.h> |
enum { |
// these must match the sfnt 'name' enums |
@@ -16,13 +17,12 @@ enum { |
// These count backwards from 0xFF, so as not to collide with the SFNT |
// defines for names in its 'name' table. |
+ kFontIndex = 0xFD, |
kFontFileName = 0xFE, |
kSentinel = 0xFF, |
}; |
-SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) { |
- fStyle = style; |
-} |
+SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) : fFontIndex(0), fStyle(style) { } |
static void read_string(SkStream* stream, SkString* string) { |
const uint32_t length = SkToU32(stream->readPackedUInt()); |
@@ -41,11 +41,20 @@ static void write_string(SkWStream* stream, const SkString& string, |
} |
} |
-SkFontDescriptor::SkFontDescriptor(SkStream* stream) { |
+static size_t read_uint(SkStream* stream) { |
+ return stream->readPackedUInt(); |
+} |
+ |
+static void write_uint(SkWStream* stream, size_t n, uint32_t id) { |
+ stream->writePackedUInt(id); |
+ stream->writePackedUInt(n); |
+} |
+ |
+SkFontDescriptor::SkFontDescriptor(SkStream* stream) : fFontIndex(0) { |
fStyle = (SkTypeface::Style)stream->readPackedUInt(); |
- for (;;) { |
- switch (stream->readPackedUInt()) { |
+ for (size_t id; (id = stream->readPackedUInt()) != kSentinel;) { |
+ switch (id) { |
case kFontFamilyName: |
read_string(stream, &fFamilyName); |
break; |
@@ -55,16 +64,25 @@ SkFontDescriptor::SkFontDescriptor(SkStream* stream) { |
case kPostscriptName: |
read_string(stream, &fPostscriptName); |
break; |
+ case kFontIndex: |
+ fFontIndex = read_uint(stream); |
+ break; |
case kFontFileName: |
read_string(stream, &fFontFileName); |
break; |
- case kSentinel: |
- return; |
default: |
SkDEBUGFAIL("Unknown id used by a font descriptor"); |
return; |
} |
} |
+ |
+ size_t length = stream->readPackedUInt(); |
+ if (length > 0) { |
+ SkAutoTUnref<SkData> data(SkData::NewUninitialized(length)); |
+ if (stream->read(data->writable_data(), length) == length) { |
+ fFontData.reset(SkNEW_ARGS(SkMemoryStream, (data))); |
+ } |
+ } |
} |
void SkFontDescriptor::serialize(SkWStream* stream) { |
@@ -74,6 +92,17 @@ void SkFontDescriptor::serialize(SkWStream* stream) { |
write_string(stream, fFullName, kFullName); |
write_string(stream, fPostscriptName, kPostscriptName); |
write_string(stream, fFontFileName, kFontFileName); |
+ if (fFontIndex) { |
+ write_uint(stream, fFontIndex, kFontIndex); |
+ } |
stream->writePackedUInt(kSentinel); |
+ |
+ if (fFontData) { |
+ size_t length = fFontData->getLength(); |
+ stream->writePackedUInt(length); |
+ stream->writeStream(fFontData, length); |
+ } else { |
+ stream->writePackedUInt(0); |
+ } |
} |