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

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

Issue 2067583002: Revert of Update typeface serialization style. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 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/SkTypeface_win_dw.cpp ('k') | no next file » | 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 "SkChecksum.h" 8 #include "SkChecksum.h"
9 #include "SkFontDescriptor.h" 9 #include "SkFontDescriptor.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 if (!length) { 76 if (!length) {
77 return 0; 77 return 0;
78 } 78 }
79 data.setCount((int) length); 79 data.setCount((int) length);
80 if (!fontStream->peek(data.begin(), length)) { 80 if (!fontStream->peek(data.begin(), length)) {
81 return 0; 81 return 0;
82 } 82 }
83 return SkChecksum::Murmur3(data.begin(), length); 83 return SkChecksum::Murmur3(data.begin(), length);
84 } 84 }
85 85
86 static void serialize_sub(const char* fontName, SkFontStyle style, SkWStream* ws tream) { 86 static void serialize_sub(const char* fontName, SkTypeface::Style style, SkWStre am* wstream) {
87 SkFontDescriptor desc; 87 SkFontDescriptor desc(style);
88 SkString subName(SUBNAME_PREFIX); 88 SkString subName(SUBNAME_PREFIX);
89 subName.append(fontName); 89 subName.append(fontName);
90 const char* familyName = subName.c_str(); 90 const char* familyName = subName.c_str();
91 desc.setFamilyName(familyName); 91 desc.setFamilyName(familyName);
92 desc.setStyle(style);
93 desc.serialize(wstream); 92 desc.serialize(wstream);
94 #if WHITELIST_DEBUG 93 #if WHITELIST_DEBUG
95 for (int i = 0; i < whitelistCount; ++i) { 94 for (int i = 0; i < whitelistCount; ++i) {
96 if (!strcmp(fontName, whitelist[i].fFontName)) { 95 if (!strcmp(fontName, whitelist[i].fFontName)) {
97 if (!whitelist[i].fSerializedSub) { 96 if (!whitelist[i].fSerializedSub) {
98 whitelist[i].fSerializedSub = true; 97 whitelist[i].fSerializedSub = true;
99 SkDebugf("%s %s\n", __FUNCTION__, familyName); 98 SkDebugf("%s %s\n", __FUNCTION__, familyName);
100 } 99 }
101 break; 100 break;
102 } 101 }
103 } 102 }
104 #endif 103 #endif
105 } 104 }
106 105
107 static bool is_local(const SkTypeface* tf) { 106 static bool is_local(const SkTypeface* tf) {
108 bool isLocal = false; 107 bool isLocal = false;
109 SkFontDescriptor desc; 108 SkFontDescriptor desc(tf->style());
110 tf->getFontDescriptor(&desc, &isLocal); 109 tf->getFontDescriptor(&desc, &isLocal);
111 return isLocal; 110 return isLocal;
112 } 111 }
113 112
114 static void serialize_full(const SkTypeface* tf, SkWStream* wstream) { 113 static void serialize_full(const SkTypeface* tf, SkWStream* wstream) {
115 bool isLocal = false; 114 bool isLocal = false;
116 SkFontDescriptor desc; 115 SkFontDescriptor desc(tf->style());
117 tf->getFontDescriptor(&desc, &isLocal); 116 tf->getFontDescriptor(&desc, &isLocal);
118 117
119 // Embed font data if it's a local font. 118 // Embed font data if it's a local font.
120 if (isLocal && !desc.hasFontData()) { 119 if (isLocal && !desc.hasFontData()) {
121 desc.setFontData(tf->createFontData()); 120 desc.setFontData(tf->createFontData());
122 } 121 }
123 desc.serialize(wstream); 122 desc.serialize(wstream);
124 } 123 }
125 124
126 static void serialize_name_only(const SkTypeface* tf, SkWStream* wstream) { 125 static void serialize_name_only(const SkTypeface* tf, SkWStream* wstream) {
127 bool isLocal = false; 126 bool isLocal = false;
128 SkFontDescriptor desc; 127 SkFontDescriptor desc(tf->style());
129 tf->getFontDescriptor(&desc, &isLocal); 128 tf->getFontDescriptor(&desc, &isLocal);
130 SkASSERT(!isLocal); 129 SkASSERT(!isLocal);
131 #if WHITELIST_DEBUG 130 #if WHITELIST_DEBUG
132 const char* familyName = desc.getFamilyName(); 131 const char* familyName = desc.getFamilyName();
133 if (familyName) { 132 if (familyName) {
134 if (!strcmp(familyName, "Times New Roman")) { 133 if (!strcmp(familyName, "Times New Roman")) {
135 if (!timesNewRomanSerializedNameOnly) { 134 if (!timesNewRomanSerializedNameOnly) {
136 timesNewRomanSerializedNameOnly = true; 135 timesNewRomanSerializedNameOnly = true;
137 SkDebugf("%s %s\n", __FUNCTION__, familyName); 136 SkDebugf("%s %s\n", __FUNCTION__, familyName);
138 } 137 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if (whitelist[whitelistIndex].fChecksum != checksum) { 173 if (whitelist[whitelistIndex].fChecksum != checksum) {
175 #if WHITELIST_DEBUG 174 #if WHITELIST_DEBUG
176 if (whitelist[whitelistIndex].fChecksum) { 175 if (whitelist[whitelistIndex].fChecksum) {
177 SkDebugf("!!! checksum changed !!!\n"); 176 SkDebugf("!!! checksum changed !!!\n");
178 } 177 }
179 SkDebugf("checksum updated\n"); 178 SkDebugf("checksum updated\n");
180 SkDebugf(" { \"%s\", 0x%08x },\n", fontName, checksum); 179 SkDebugf(" { \"%s\", 0x%08x },\n", fontName, checksum);
181 #endif 180 #endif
182 whitelist[whitelistIndex].fChecksum = checksum; 181 whitelist[whitelistIndex].fChecksum = checksum;
183 } 182 }
184 serialize_sub(fontName, tf->fontStyle(), wstream); 183 serialize_sub(fontName, tf->style(), wstream);
185 } 184 }
186 185
187 sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) { 186 sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) {
188 SkFontDescriptor desc; 187 SkFontDescriptor desc;
189 if (!SkFontDescriptor::Deserialize(stream, &desc)) { 188 if (!SkFontDescriptor::Deserialize(stream, &desc)) {
190 return nullptr; 189 return nullptr;
191 } 190 }
192 191
193 SkFontData* data = desc.detachFontData(); 192 SkFontData* data = desc.detachFontData();
194 if (data) { 193 if (data) {
195 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data)); 194 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data));
196 if (typeface) { 195 if (typeface) {
197 return typeface; 196 return typeface;
198 } 197 }
199 } 198 }
200 const char* familyName = desc.getFamilyName(); 199 const char* familyName = desc.getFamilyName();
201 if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) { 200 if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) {
202 familyName += sizeof(SUBNAME_PREFIX) - 1; 201 familyName += sizeof(SUBNAME_PREFIX) - 1;
203 } 202 }
204 return SkTypeface::MakeFromName(familyName, desc.getStyle()); 203 return SkTypeface::MakeFromName(familyName, SkFontStyle::FromOldStyle(desc.g etStyle()));
205 } 204 }
206 205
207 bool CheckChecksums() { 206 bool CheckChecksums() {
208 for (int i = 0; i < whitelistCount; ++i) { 207 for (int i = 0; i < whitelistCount; ++i) {
209 const char* fontName = whitelist[i].fFontName; 208 const char* fontName = whitelist[i].fFontName;
210 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkFontStyle())); 209 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkFontStyle()));
211 uint32_t checksum = compute_checksum(tf.get()); 210 uint32_t checksum = compute_checksum(tf.get());
212 if (whitelist[i].fChecksum != checksum) { 211 if (whitelist[i].fChecksum != checksum) {
213 return false; 212 return false;
214 } 213 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 const char* fontName = whitelist[i].fFontName; 263 const char* fontName = whitelist[i].fFontName;
265 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkFontStyle())); 264 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkFontStyle()));
266 uint32_t checksum = compute_checksum(tf.get()); 265 uint32_t checksum = compute_checksum(tf.get());
267 line.printf(checksumEntry, fontName, checksum); 266 line.printf(checksumEntry, fontName, checksum);
268 sk_fwrite(line.c_str(), line.size(), file); 267 sk_fwrite(line.c_str(), line.size(), file);
269 } 268 }
270 sk_fwrite(checksumTrailer, sizeof(checksumTrailer) - 1, file); 269 sk_fwrite(checksumTrailer, sizeof(checksumTrailer) - 1, file);
271 sk_fclose(file); 270 sk_fclose(file);
272 return true; 271 return true;
273 } 272 }
OLDNEW
« no previous file with comments | « src/ports/SkTypeface_win_dw.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698