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

Side by Side Diff: src/utils/SkWhitelistTypefaces.cpp

Issue 1974783002: Revert of Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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
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 "SkChecksum.h" 8 #include "SkChecksum.h"
9 #include "SkFontDescriptor.h" 9 #include "SkFontDescriptor.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
11 #include "SkString.h" 11 #include "SkString.h"
12 #include "SkTypeface.h" 12 #include "SkTypeface.h"
13 #include "SkUtils.h" 13 #include "SkUtils.h"
14 #include "../sfnt/SkOTUtils.h" 14 #include "../sfnt/SkOTUtils.h"
15 15
16 #include "SkWhitelistChecksums.cpp" 16 #include "SkWhitelistChecksums.cpp"
17 17
18 #define WHITELIST_DEBUG 0 18 #define WHITELIST_DEBUG 0
19 19
20 extern void WhitelistSerializeTypeface(const SkTypeface*, SkWStream* ); 20 extern void WhitelistSerializeTypeface(const SkTypeface*, SkWStream* );
21 sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* ); 21 extern SkTypeface* WhitelistDeserializeTypeface(SkStream* );
22 extern bool CheckChecksums(); 22 extern bool CheckChecksums();
23 extern bool GenerateChecksums(); 23 extern bool GenerateChecksums();
24 24
25 #if WHITELIST_DEBUG 25 #if WHITELIST_DEBUG
26 static bool timesNewRomanSerializedNameOnly = false; 26 static bool timesNewRomanSerializedNameOnly = false;
27 #endif 27 #endif
28 28
29 #define SUBNAME_PREFIX "sk_" 29 #define SUBNAME_PREFIX "sk_"
30 30
31 static bool font_name_is_local(const char* fontName, SkTypeface::Style style) { 31 static bool font_name_is_local(const char* fontName, SkTypeface::Style style) {
32 if (!strcmp(fontName, "DejaVu Sans")) { 32 if (!strcmp(fontName, "DejaVu Sans")) {
33 return true; 33 return true;
34 } 34 }
35 sk_sp<SkTypeface> defaultFace(SkTypeface::MakeFromName(nullptr, style)); 35 SkTypeface* defaultFace = SkTypeface::CreateFromName(nullptr, style);
36 sk_sp<SkTypeface> foundFace(SkTypeface::MakeFromName(fontName, style)); 36 SkTypeface* foundFace = SkTypeface::CreateFromName(fontName, style);
37 return defaultFace != foundFace; 37 return defaultFace != foundFace;
38 } 38 }
39 39
40 static int whitelist_name_index(const SkTypeface* tf) { 40 static int whitelist_name_index(const SkTypeface* tf) {
41 41
42 SkString fontNameStr; 42 SkString fontNameStr;
43 SkAutoTUnref<SkTypeface::LocalizedStrings> nameIter( 43 SkAutoTUnref<SkTypeface::LocalizedStrings> nameIter(
44 SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(*tf)); 44 SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(*tf));
45 SkTypeface::LocalizedString familyNameLocalized; 45 SkTypeface::LocalizedString familyNameLocalized;
46 while (nameIter->next(&familyNameLocalized)) { 46 while (nameIter->next(&familyNameLocalized)) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 SkDebugf("!!! checksum changed !!!\n"); 176 SkDebugf("!!! checksum changed !!!\n");
177 } 177 }
178 SkDebugf("checksum updated\n"); 178 SkDebugf("checksum updated\n");
179 SkDebugf(" { \"%s\", 0x%08x },\n", fontName, checksum); 179 SkDebugf(" { \"%s\", 0x%08x },\n", fontName, checksum);
180 #endif 180 #endif
181 whitelist[whitelistIndex].fChecksum = checksum; 181 whitelist[whitelistIndex].fChecksum = checksum;
182 } 182 }
183 serialize_sub(fontName, tf->style(), wstream); 183 serialize_sub(fontName, tf->style(), wstream);
184 } 184 }
185 185
186 sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) { 186 SkTypeface* WhitelistDeserializeTypeface(SkStream* stream) {
187 SkFontDescriptor desc; 187 SkFontDescriptor desc;
188 if (!SkFontDescriptor::Deserialize(stream, &desc)) { 188 if (!SkFontDescriptor::Deserialize(stream, &desc)) {
189 return nullptr; 189 return nullptr;
190 } 190 }
191 191
192 SkFontData* data = desc.detachFontData(); 192 SkFontData* data = desc.detachFontData();
193 if (data) { 193 if (data) {
194 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data)); 194 SkTypeface* typeface = SkTypeface::CreateFromFontData(data);
195 if (typeface) { 195 if (typeface) {
196 return typeface; 196 return typeface;
197 } 197 }
198 } 198 }
199 const char* familyName = desc.getFamilyName(); 199 const char* familyName = desc.getFamilyName();
200 if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) { 200 if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) {
201 familyName += sizeof(SUBNAME_PREFIX) - 1; 201 familyName += sizeof(SUBNAME_PREFIX) - 1;
202 } 202 }
203 return SkTypeface::MakeFromName(familyName, desc.getStyle()); 203 return SkTypeface::CreateFromName(familyName, desc.getStyle());
204 } 204 }
205 205
206 bool CheckChecksums() { 206 bool CheckChecksums() {
207 for (int i = 0; i < whitelistCount; ++i) { 207 for (int i = 0; i < whitelistCount; ++i) {
208 const char* fontName = whitelist[i].fFontName; 208 const char* fontName = whitelist[i].fFontName;
209 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkTypeface::kNor mal)); 209 SkTypeface* tf = SkTypeface::CreateFromName(fontName, SkTypeface::kNorma l);
210 uint32_t checksum = compute_checksum(tf.get()); 210 uint32_t checksum = compute_checksum(tf);
211 if (whitelist[i].fChecksum != checksum) { 211 if (whitelist[i].fChecksum != checksum) {
212 return false; 212 return false;
213 } 213 }
214 } 214 }
215 return true; 215 return true;
216 } 216 }
217 217
218 const char checksumFileName[] = "SkWhitelistChecksums.cpp"; 218 const char checksumFileName[] = "SkWhitelistChecksums.cpp";
219 219
220 const char checksumHeader[] = 220 const char checksumHeader[] =
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 FILE* file = sk_fopen(checksumFileName, kWrite_SkFILE_Flag); 254 FILE* file = sk_fopen(checksumFileName, kWrite_SkFILE_Flag);
255 if (!file) { 255 if (!file) {
256 SkDebugf("Can't open %s for writing.\n", checksumFileName); 256 SkDebugf("Can't open %s for writing.\n", checksumFileName);
257 return false; 257 return false;
258 } 258 }
259 SkString line; 259 SkString line;
260 line.printf(checksumHeader, __FUNCTION__, __FILE__, checksumFileName); 260 line.printf(checksumHeader, __FUNCTION__, __FILE__, checksumFileName);
261 sk_fwrite(line.c_str(), line.size(), file); 261 sk_fwrite(line.c_str(), line.size(), file);
262 for (int i = 0; i < whitelistCount; ++i) { 262 for (int i = 0; i < whitelistCount; ++i) {
263 const char* fontName = whitelist[i].fFontName; 263 const char* fontName = whitelist[i].fFontName;
264 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkTypeface::kNor mal)); 264 SkTypeface* tf = SkTypeface::CreateFromName(fontName, SkTypeface::kNorma l);
265 uint32_t checksum = compute_checksum(tf.get()); 265 uint32_t checksum = compute_checksum(tf);
266 line.printf(checksumEntry, fontName, checksum); 266 line.printf(checksumEntry, fontName, checksum);
267 sk_fwrite(line.c_str(), line.size(), file); 267 sk_fwrite(line.c_str(), line.size(), file);
268 } 268 }
269 sk_fwrite(checksumTrailer, sizeof(checksumTrailer) - 1, file); 269 sk_fwrite(checksumTrailer, sizeof(checksumTrailer) - 1, file);
270 sk_fclose(file); 270 sk_fclose(file);
271 return true; 271 return true;
272 } 272 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698