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 "SkMakeUnique.h" | |
10 #include "SkStream.h" | 9 #include "SkStream.h" |
11 #include "SkData.h" | 10 #include "SkData.h" |
12 | 11 |
13 enum { | 12 enum { |
14 // these must match the sfnt 'name' enums | 13 // these must match the sfnt 'name' enums |
15 kFontFamilyName = 0x01, | 14 kFontFamilyName = 0x01, |
16 kFullName = 0x04, | 15 kFullName = 0x04, |
17 kPostscriptName = 0x06, | 16 kPostscriptName = 0x06, |
18 | 17 |
19 // These count backwards from 0xFF, so as not to collide with the SFNT | 18 // These count backwards from 0xFF, so as not to collide with the SFNT |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 default: | 99 default: |
101 SkDEBUGFAIL("Unknown id used by a font descriptor"); | 100 SkDEBUGFAIL("Unknown id used by a font descriptor"); |
102 return false; | 101 return false; |
103 } | 102 } |
104 } | 103 } |
105 | 104 |
106 size_t length = stream->readPackedUInt(); | 105 size_t length = stream->readPackedUInt(); |
107 if (length > 0) { | 106 if (length > 0) { |
108 sk_sp<SkData> data(SkData::MakeUninitialized(length)); | 107 sk_sp<SkData> data(SkData::MakeUninitialized(length)); |
109 if (stream->read(data->writable_data(), length) == length) { | 108 if (stream->read(data->writable_data(), length) == length) { |
110 result->fFontData = skstd::make_unique<SkFontData>( | 109 result->fFontData.reset(new SkFontData(new SkMemoryStream(data), |
111 skstd::make_unique<SkMemoryStream>(data), index, axis, axisCount
); | 110 index, axis, axisCount)); |
112 } else { | 111 } else { |
113 SkDEBUGFAIL("Could not read font data"); | 112 SkDEBUGFAIL("Could not read font data"); |
114 return false; | 113 return false; |
115 } | 114 } |
116 } | 115 } |
117 return true; | 116 return true; |
118 } | 117 } |
119 | 118 |
120 void SkFontDescriptor::serialize(SkWStream* stream) { | 119 void SkFontDescriptor::serialize(SkWStream* stream) { |
121 uint32_t styleBits = (fStyle.weight() << 16) | (fStyle.width() << 8) | (fSty
le.slant()); | 120 uint32_t styleBits = (fStyle.weight() << 16) | (fStyle.width() << 8) | (fSty
le.slant()); |
(...skipping 10 matching lines...) Expand all Loading... |
132 write_uint(stream, fFontData->getAxisCount(), kFontAxes); | 131 write_uint(stream, fFontData->getAxisCount(), kFontAxes); |
133 for (int i = 0; i < fFontData->getAxisCount(); ++i) { | 132 for (int i = 0; i < fFontData->getAxisCount(); ++i) { |
134 stream->writePackedUInt(fFontData->getAxis()[i]); | 133 stream->writePackedUInt(fFontData->getAxis()[i]); |
135 } | 134 } |
136 } | 135 } |
137 } | 136 } |
138 | 137 |
139 stream->writePackedUInt(kSentinel); | 138 stream->writePackedUInt(kSentinel); |
140 | 139 |
141 if (fFontData.get() && fFontData->hasStream()) { | 140 if (fFontData.get() && fFontData->hasStream()) { |
142 std::unique_ptr<SkStreamAsset> fontStream = fFontData->detachStream(); | 141 SkAutoTDelete<SkStreamAsset> fontData(fFontData->detachStream()); |
143 size_t length = fontStream->getLength(); | 142 size_t length = fontData->getLength(); |
144 stream->writePackedUInt(length); | 143 stream->writePackedUInt(length); |
145 stream->writeStream(fontStream.get(), length); | 144 stream->writeStream(fontData, length); |
146 } else { | 145 } else { |
147 stream->writePackedUInt(0); | 146 stream->writePackedUInt(0); |
148 } | 147 } |
149 } | 148 } |
OLD | NEW |