Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/core/SkFontDescriptor.cpp

Issue 2339273002: SkFontData to use smart pointers. (Closed)
Patch Set: Add trivial bodies to the trivial implementations. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkFontDescriptor.h ('k') | src/core/SkFontMgr.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
9 #include "SkStream.h" 10 #include "SkStream.h"
10 #include "SkData.h" 11 #include "SkData.h"
11 12
12 enum { 13 enum {
13 // these must match the sfnt 'name' enums 14 // these must match the sfnt 'name' enums
14 kFontFamilyName = 0x01, 15 kFontFamilyName = 0x01,
15 kFullName = 0x04, 16 kFullName = 0x04,
16 kPostscriptName = 0x06, 17 kPostscriptName = 0x06,
17 18
18 // These count backwards from 0xFF, so as not to collide with the SFNT 19 // 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
99 default: 100 default:
100 SkDEBUGFAIL("Unknown id used by a font descriptor"); 101 SkDEBUGFAIL("Unknown id used by a font descriptor");
101 return false; 102 return false;
102 } 103 }
103 } 104 }
104 105
105 size_t length = stream->readPackedUInt(); 106 size_t length = stream->readPackedUInt();
106 if (length > 0) { 107 if (length > 0) {
107 sk_sp<SkData> data(SkData::MakeUninitialized(length)); 108 sk_sp<SkData> data(SkData::MakeUninitialized(length));
108 if (stream->read(data->writable_data(), length) == length) { 109 if (stream->read(data->writable_data(), length) == length) {
109 result->fFontData.reset(new SkFontData(new SkMemoryStream(data), 110 result->fFontData = skstd::make_unique<SkFontData>(
110 index, axis, axisCount)); 111 skstd::make_unique<SkMemoryStream>(data), index, axis, axisCount );
111 } else { 112 } else {
112 SkDEBUGFAIL("Could not read font data"); 113 SkDEBUGFAIL("Could not read font data");
113 return false; 114 return false;
114 } 115 }
115 } 116 }
116 return true; 117 return true;
117 } 118 }
118 119
119 void SkFontDescriptor::serialize(SkWStream* stream) { 120 void SkFontDescriptor::serialize(SkWStream* stream) {
120 uint32_t styleBits = (fStyle.weight() << 16) | (fStyle.width() << 8) | (fSty le.slant()); 121 uint32_t styleBits = (fStyle.weight() << 16) | (fStyle.width() << 8) | (fSty le.slant());
(...skipping 10 matching lines...) Expand all
131 write_uint(stream, fFontData->getAxisCount(), kFontAxes); 132 write_uint(stream, fFontData->getAxisCount(), kFontAxes);
132 for (int i = 0; i < fFontData->getAxisCount(); ++i) { 133 for (int i = 0; i < fFontData->getAxisCount(); ++i) {
133 stream->writePackedUInt(fFontData->getAxis()[i]); 134 stream->writePackedUInt(fFontData->getAxis()[i]);
134 } 135 }
135 } 136 }
136 } 137 }
137 138
138 stream->writePackedUInt(kSentinel); 139 stream->writePackedUInt(kSentinel);
139 140
140 if (fFontData.get() && fFontData->hasStream()) { 141 if (fFontData.get() && fFontData->hasStream()) {
141 SkAutoTDelete<SkStreamAsset> fontData(fFontData->detachStream()); 142 std::unique_ptr<SkStreamAsset> fontStream = fFontData->detachStream();
142 size_t length = fontData->getLength(); 143 size_t length = fontStream->getLength();
143 stream->writePackedUInt(length); 144 stream->writePackedUInt(length);
144 stream->writeStream(fontData, length); 145 stream->writeStream(fontStream.get(), length);
145 } else { 146 } else {
146 stream->writePackedUInt(0); 147 stream->writePackedUInt(0);
147 } 148 }
148 } 149 }
OLDNEW
« no previous file with comments | « src/core/SkFontDescriptor.h ('k') | src/core/SkFontMgr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698