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

Side by Side Diff: src/ports/SkFontMgr_FontConfigInterface.cpp

Issue 2343933002: Revert of SkFontData to use smart pointers. (Closed)
Patch Set: 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/ports/SkFontHost_win.cpp ('k') | src/ports/SkFontMgr_android.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 2013 Google Inc. 2 * Copyright 2013 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 "SkFontConfigInterface.h" 8 #include "SkFontConfigInterface.h"
9 #include "SkFontConfigTypeface.h" 9 #include "SkFontConfigTypeface.h"
10 #include "SkFontDescriptor.h" 10 #include "SkFontDescriptor.h"
11 #include "SkFontMgr.h" 11 #include "SkFontMgr.h"
12 #include "SkFontStyle.h" 12 #include "SkFontStyle.h"
13 #include "SkMakeUnique.h"
14 #include "SkMutex.h" 13 #include "SkMutex.h"
15 #include "SkString.h" 14 #include "SkString.h"
16 #include "SkTypeface.h" 15 #include "SkTypeface.h"
17 #include "SkTypefaceCache.h" 16 #include "SkTypefaceCache.h"
18 #include "SkResourceCache.h" 17 #include "SkResourceCache.h"
19 18
20 SkStreamAsset* SkTypeface_FCI::onOpenStream(int* ttcIndex) const { 19 SkStreamAsset* SkTypeface_FCI::onOpenStream(int* ttcIndex) const {
21 *ttcIndex = this->getIdentity().fTTCIndex; 20 *ttcIndex = this->getIdentity().fTTCIndex;
22 21
23 if (fFontData) { 22 if (fFontData) {
24 SkStreamAsset* stream = fFontData->getStream(); 23 SkStreamAsset* stream = fFontData->getStream();
25 if (!stream) { 24 if (!stream) {
26 return nullptr; 25 return nullptr;
27 } 26 }
28 return stream->duplicate(); 27 return stream->duplicate();
29 } 28 }
30 29
31 return fFCI->openStream(this->getIdentity()); 30 return fFCI->openStream(this->getIdentity());
32 } 31 }
33 32
34 std::unique_ptr<SkFontData> SkTypeface_FCI::onMakeFontData() const { 33 SkFontData* SkTypeface_FCI::onCreateFontData() const {
35 if (fFontData) { 34 if (fFontData) {
36 return skstd::make_unique<SkFontData>(*fFontData); 35 return new SkFontData(*fFontData.get());
37 } 36 }
38 37
39 const SkFontConfigInterface::FontIdentity& id = this->getIdentity(); 38 const SkFontConfigInterface::FontIdentity& id = this->getIdentity();
40 return skstd::make_unique<SkFontData>(std::unique_ptr<SkStreamAsset>(fFCI->o penStream(id)), 39 return new SkFontData( fFCI->openStream(id), id.fTTCIndex, nullptr, 0);
41 id.fTTCIndex, nullptr, 0);
42 } 40 }
43 41
44 void SkTypeface_FCI::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocalSt ream) const { 42 void SkTypeface_FCI::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocalSt ream) const {
45 SkString name; 43 SkString name;
46 this->getFamilyName(&name); 44 this->getFamilyName(&name);
47 desc->setFamilyName(name.c_str()); 45 desc->setFamilyName(name.c_str());
48 desc->setStyle(this->fontStyle()); 46 desc->setStyle(this->fontStyle());
49 *isLocalStream = SkToBool(fFontData); 47 *isLocalStream = SkToBool(fFontData);
50 } 48 }
51 49
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 const char* bcp47[], int bcp47Count, 192 const char* bcp47[], int bcp47Count,
195 SkUnichar character) const override { 193 SkUnichar character) const override {
196 return nullptr; 194 return nullptr;
197 } 195 }
198 SkTypeface* onMatchFaceStyle(const SkTypeface*, 196 SkTypeface* onMatchFaceStyle(const SkTypeface*,
199 const SkFontStyle&) const override { return nul lptr; } 197 const SkFontStyle&) const override { return nul lptr; }
200 198
201 SkTypeface* onCreateFromData(SkData*, int ttcIndex) const override { return nullptr; } 199 SkTypeface* onCreateFromData(SkData*, int ttcIndex) const override { return nullptr; }
202 200
203 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override { 201 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override {
204 std::unique_ptr<SkStreamAsset> stream(bareStream); 202 SkAutoTDelete<SkStreamAsset> stream(bareStream);
205 const size_t length = stream->getLength(); 203 const size_t length = stream->getLength();
206 if (!length) { 204 if (!length) {
207 return nullptr; 205 return nullptr;
208 } 206 }
209 if (length >= 1024 * 1024 * 1024) { 207 if (length >= 1024 * 1024 * 1024) {
210 return nullptr; // don't accept too large fonts (>= 1GB) for safety . 208 return nullptr; // don't accept too large fonts (>= 1GB) for safety .
211 } 209 }
212 210
213 // TODO should the caller give us the style or should we get it from fre etype? 211 // TODO should the caller give us the style or should we get it from fre etype?
214 SkFontStyle style; 212 SkFontStyle style;
215 bool isFixedPitch = false; 213 bool isFixedPitch = false;
216 if (!fScanner.scanFont(stream.get(), 0, nullptr, &style, &isFixedPitch, nullptr)) { 214 if (!fScanner.scanFont(stream, 0, nullptr, &style, &isFixedPitch, nullpt r)) {
217 return nullptr; 215 return nullptr;
218 } 216 }
219 217
220 auto fontData = skstd::make_unique<SkFontData>(std::move(stream), ttcInd ex, nullptr, 0); 218 std::unique_ptr<SkFontData> fontData(new SkFontData(stream.release(), tt cIndex,
219 nullptr, 0));
221 return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch); 220 return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch);
222 } 221 }
223 222
224 SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& param s) const override { 223 SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& param s) const override {
225 using Scanner = SkTypeface_FreeType::Scanner; 224 using Scanner = SkTypeface_FreeType::Scanner;
226 std::unique_ptr<SkStreamAsset> stream(s); 225 SkAutoTDelete<SkStreamAsset> stream(s);
227 const size_t length = stream->getLength(); 226 const size_t length = stream->getLength();
228 if (!length) { 227 if (!length) {
229 return nullptr; 228 return nullptr;
230 } 229 }
231 if (length >= 1024 * 1024 * 1024) { 230 if (length >= 1024 * 1024 * 1024) {
232 return nullptr; // don't accept too large fonts (>= 1GB) for safety . 231 return nullptr; // don't accept too large fonts (>= 1GB) for safety .
233 } 232 }
234 233
235 bool isFixedPitch; 234 bool isFixedPitch;
236 SkFontStyle style; 235 SkFontStyle style;
237 SkString name; 236 SkString name;
238 Scanner::AxisDefinitions axisDefinitions; 237 Scanner::AxisDefinitions axisDefinitions;
239 if (!fScanner.scanFont(stream.get(), params.getCollectionIndex(), 238 if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &styl e, &isFixedPitch,
240 &name, &style, &isFixedPitch, &axisDefinitions)) 239 &axisDefinitions))
241 { 240 {
242 return nullptr; 241 return nullptr;
243 } 242 }
244 243
245 int paramAxisCount; 244 int paramAxisCount;
246 const FontParameters::Axis* paramAxes = params.getAxes(&paramAxisCount); 245 const FontParameters::Axis* paramAxes = params.getAxes(&paramAxisCount);
247 SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count()); 246 SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
248 Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, a xisValues, name); 247 Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, a xisValues, name);
249 248
250 auto fontData = skstd::make_unique<SkFontData>(std::move(stream), 249 std::unique_ptr<SkFontData> fontData(new SkFontData(stream.release(),
251 params.getCollectionIndex (), 250 params.getCollection Index(),
252 axisValues.get(), 251 axisValues.get(),
253 axisDefinitions.count()); 252 axisDefinitions.coun t()));
254 return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch); 253 return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch);
255 } 254 }
256 255
257 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override { 256 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
258 std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path); 257 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path));
259 return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr; 258 return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
260 } 259 }
261 260
262 SkTypeface* onLegacyCreateTypeface(const char requestedFamilyName[], 261 SkTypeface* onLegacyCreateTypeface(const char requestedFamilyName[],
263 SkFontStyle requestedStyle) const overrid e 262 SkFontStyle requestedStyle) const overrid e
264 { 263 {
265 SkAutoMutexAcquire ama(fMutex); 264 SkAutoMutexAcquire ama(fMutex);
266 265
267 // Check if this request is already in the request cache. 266 // Check if this request is already in the request cache.
268 using Request = SkFontRequestCache::Request; 267 using Request = SkFontRequestCache::Request;
(...skipping 23 matching lines...) Expand all
292 fCache.add(face, request.release()); 291 fCache.add(face, request.release());
293 292
294 return face; 293 return face;
295 } 294 }
296 }; 295 };
297 296
298 SK_API SkFontMgr* SkFontMgr_New_FCI(SkFontConfigInterface* fci) { 297 SK_API SkFontMgr* SkFontMgr_New_FCI(SkFontConfigInterface* fci) {
299 SkASSERT(fci); 298 SkASSERT(fci);
300 return new SkFontMgr_FCI(fci); 299 return new SkFontMgr_FCI(fci);
301 } 300 }
OLDNEW
« no previous file with comments | « src/ports/SkFontHost_win.cpp ('k') | src/ports/SkFontMgr_android.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698