OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkFontDescriptor.h" | 8 #include "SkFontDescriptor.h" |
9 #include "SkStream.h" | 9 #include "SkStream.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) : fFontIndex(0), fSt yle(style) { } | 25 SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) : fFontIndex(0), fSt yle(style) { } |
26 | 26 |
27 static void read_string(SkStream* stream, SkString* string) { | 27 static void read_string(SkStream* stream, SkString* string) { |
28 const uint32_t length = SkToU32(stream->readPackedUInt()); | 28 const uint32_t length = SkToU32(stream->readPackedUInt()); |
29 if (length > 0) { | 29 if (length > 0) { |
30 string->resize(length); | 30 string->resize(length); |
31 stream->read(string->writable_str(), length); | 31 stream->read(string->writable_str(), length); |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 static void skip_string(SkStream* stream) { | |
36 const uint32_t length = SkToU32(stream->readPackedUInt()); | |
37 if (length > 0) { | |
38 stream->skip(length); | |
39 } | |
40 } | |
41 | |
35 static void write_string(SkWStream* stream, const SkString& string, | 42 static void write_string(SkWStream* stream, const SkString& string, |
36 uint32_t id) { | 43 uint32_t id) { |
37 if (!string.isEmpty()) { | 44 if (!string.isEmpty()) { |
38 stream->writePackedUInt(id); | 45 stream->writePackedUInt(id); |
39 stream->writePackedUInt(string.size()); | 46 stream->writePackedUInt(string.size()); |
40 stream->write(string.c_str(), string.size()); | 47 stream->write(string.c_str(), string.size()); |
41 } | 48 } |
42 } | 49 } |
43 | 50 |
44 static size_t read_uint(SkStream* stream) { | 51 static size_t read_uint(SkStream* stream) { |
(...skipping 16 matching lines...) Expand all Loading... | |
61 case kFullName: | 68 case kFullName: |
62 read_string(stream, &fFullName); | 69 read_string(stream, &fFullName); |
63 break; | 70 break; |
64 case kPostscriptName: | 71 case kPostscriptName: |
65 read_string(stream, &fPostscriptName); | 72 read_string(stream, &fPostscriptName); |
66 break; | 73 break; |
67 case kFontIndex: | 74 case kFontIndex: |
68 fFontIndex = read_uint(stream); | 75 fFontIndex = read_uint(stream); |
69 break; | 76 break; |
70 case kFontFileName: | 77 case kFontFileName: |
71 read_string(stream, &fFontFileName); | 78 skip_string(stream); |
72 break; | 79 break; |
mtklein
2015/04/17 17:00:46
Why do we keep this around? For serialized pictur
bungeman-skia
2015/04/17 17:44:51
Added assert to SkPicture.h and comments here.
| |
73 default: | 80 default: |
74 SkDEBUGFAIL("Unknown id used by a font descriptor"); | 81 SkDEBUGFAIL("Unknown id used by a font descriptor"); |
75 return; | 82 return; |
76 } | 83 } |
77 } | 84 } |
78 | 85 |
79 size_t length = stream->readPackedUInt(); | 86 size_t length = stream->readPackedUInt(); |
80 if (length > 0) { | 87 if (length > 0) { |
81 SkAutoTUnref<SkData> data(SkData::NewUninitialized(length)); | 88 SkAutoTUnref<SkData> data(SkData::NewUninitialized(length)); |
82 if (stream->read(data->writable_data(), length) == length) { | 89 if (stream->read(data->writable_data(), length) == length) { |
83 fFontData.reset(SkNEW_ARGS(SkMemoryStream, (data))); | 90 fFontData.reset(SkNEW_ARGS(SkMemoryStream, (data))); |
84 } | 91 } |
85 } | 92 } |
86 } | 93 } |
87 | 94 |
88 void SkFontDescriptor::serialize(SkWStream* stream) { | 95 void SkFontDescriptor::serialize(SkWStream* stream) { |
89 stream->writePackedUInt(fStyle); | 96 stream->writePackedUInt(fStyle); |
90 | 97 |
91 write_string(stream, fFamilyName, kFontFamilyName); | 98 write_string(stream, fFamilyName, kFontFamilyName); |
92 write_string(stream, fFullName, kFullName); | 99 write_string(stream, fFullName, kFullName); |
93 write_string(stream, fPostscriptName, kPostscriptName); | 100 write_string(stream, fPostscriptName, kPostscriptName); |
94 write_string(stream, fFontFileName, kFontFileName); | |
95 if (fFontIndex) { | 101 if (fFontIndex) { |
96 write_uint(stream, fFontIndex, kFontIndex); | 102 write_uint(stream, fFontIndex, kFontIndex); |
97 } | 103 } |
98 | 104 |
99 stream->writePackedUInt(kSentinel); | 105 stream->writePackedUInt(kSentinel); |
100 | 106 |
101 if (fFontData) { | 107 if (fFontData) { |
102 size_t length = fFontData->getLength(); | 108 size_t length = fFontData->getLength(); |
103 stream->writePackedUInt(length); | 109 stream->writePackedUInt(length); |
104 stream->writeStream(fFontData, length); | 110 stream->writeStream(fFontData, length); |
105 } else { | 111 } else { |
106 stream->writePackedUInt(0); | 112 stream->writePackedUInt(0); |
107 } | 113 } |
108 } | 114 } |
OLD | NEW |