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

Side by Side Diff: src/utils/SkWhitelistTypefaces.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/SkFontMgr_win_dw.cpp ('k') | src/utils/mac/SkCreateCGImageRef.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 2015 Google Inc. 2 * Copyright 2015 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 "SkOpts.h" 9 #include "SkOpts.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 SkAutoTUnref<SkTypeface::LocalizedStrings> debugIter( 56 SkAutoTUnref<SkTypeface::LocalizedStrings> debugIter(
57 SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(*tf)); 57 SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(*tf));
58 while (debugIter->next(&familyNameLocalized)) { 58 while (debugIter->next(&familyNameLocalized)) {
59 SkDebugf("no match fontName=\"%s\"\n", familyNameLocalized.fString.c_str ()); 59 SkDebugf("no match fontName=\"%s\"\n", familyNameLocalized.fString.c_str ());
60 } 60 }
61 #endif 61 #endif
62 return -1; 62 return -1;
63 } 63 }
64 64
65 static uint32_t compute_checksum(const SkTypeface* tf) { 65 static uint32_t compute_checksum(const SkTypeface* tf) {
66 std::unique_ptr<SkFontData> fontData = tf->makeFontData(); 66 SkFontData* fontData = tf->createFontData();
67 if (!fontData) { 67 if (!fontData) {
68 return 0; 68 return 0;
69 } 69 }
70 SkStreamAsset* fontStream = fontData->getStream(); 70 SkStreamAsset* fontStream = fontData->getStream();
71 if (!fontStream) { 71 if (!fontStream) {
72 return 0; 72 return 0;
73 } 73 }
74 SkTDArray<char> data; 74 SkTDArray<char> data;
75 size_t length = fontStream->getLength(); 75 size_t length = fontStream->getLength();
76 if (!length) { 76 if (!length) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 return isLocal; 111 return isLocal;
112 } 112 }
113 113
114 static void serialize_full(const SkTypeface* tf, SkWStream* wstream) { 114 static void serialize_full(const SkTypeface* tf, SkWStream* wstream) {
115 bool isLocal = false; 115 bool isLocal = false;
116 SkFontDescriptor desc; 116 SkFontDescriptor desc;
117 tf->getFontDescriptor(&desc, &isLocal); 117 tf->getFontDescriptor(&desc, &isLocal);
118 118
119 // Embed font data if it's a local font. 119 // Embed font data if it's a local font.
120 if (isLocal && !desc.hasFontData()) { 120 if (isLocal && !desc.hasFontData()) {
121 desc.setFontData(tf->makeFontData()); 121 desc.setFontData(tf->createFontData());
122 } 122 }
123 desc.serialize(wstream); 123 desc.serialize(wstream);
124 } 124 }
125 125
126 static void serialize_name_only(const SkTypeface* tf, SkWStream* wstream) { 126 static void serialize_name_only(const SkTypeface* tf, SkWStream* wstream) {
127 bool isLocal = false; 127 bool isLocal = false;
128 SkFontDescriptor desc; 128 SkFontDescriptor desc;
129 tf->getFontDescriptor(&desc, &isLocal); 129 tf->getFontDescriptor(&desc, &isLocal);
130 SkASSERT(!isLocal); 130 SkASSERT(!isLocal);
131 #if WHITELIST_DEBUG 131 #if WHITELIST_DEBUG
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 183 }
184 serialize_sub(fontName, tf->fontStyle(), wstream); 184 serialize_sub(fontName, tf->fontStyle(), wstream);
185 } 185 }
186 186
187 sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) { 187 sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) {
188 SkFontDescriptor desc; 188 SkFontDescriptor desc;
189 if (!SkFontDescriptor::Deserialize(stream, &desc)) { 189 if (!SkFontDescriptor::Deserialize(stream, &desc)) {
190 return nullptr; 190 return nullptr;
191 } 191 }
192 192
193 std::unique_ptr<SkFontData> data = desc.detachFontData(); 193 SkFontData* data = desc.detachFontData();
194 if (data) { 194 if (data) {
195 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(std::move(data)) ); 195 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data));
196 if (typeface) { 196 if (typeface) {
197 return typeface; 197 return typeface;
198 } 198 }
199 } 199 }
200 const char* familyName = desc.getFamilyName(); 200 const char* familyName = desc.getFamilyName();
201 if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) { 201 if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) {
202 familyName += sizeof(SUBNAME_PREFIX) - 1; 202 familyName += sizeof(SUBNAME_PREFIX) - 1;
203 } 203 }
204 return SkTypeface::MakeFromName(familyName, desc.getStyle()); 204 return SkTypeface::MakeFromName(familyName, desc.getStyle());
205 } 205 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 const char* fontName = whitelist[i].fFontName; 264 const char* fontName = whitelist[i].fFontName;
265 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkFontStyle())); 265 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkFontStyle()));
266 uint32_t checksum = compute_checksum(tf.get()); 266 uint32_t checksum = compute_checksum(tf.get());
267 line.printf(checksumEntry, fontName, checksum); 267 line.printf(checksumEntry, fontName, checksum);
268 sk_fwrite(line.c_str(), line.size(), file); 268 sk_fwrite(line.c_str(), line.size(), file);
269 } 269 }
270 sk_fwrite(checksumTrailer, sizeof(checksumTrailer) - 1, file); 270 sk_fwrite(checksumTrailer, sizeof(checksumTrailer) - 1, file);
271 sk_fclose(file); 271 sk_fclose(file);
272 return true; 272 return true;
273 } 273 }
OLDNEW
« no previous file with comments | « src/ports/SkFontMgr_win_dw.cpp ('k') | src/utils/mac/SkCreateCGImageRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698