OLD | NEW |
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 Loading... |
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, SkTypeface::Style style, SkWStre
am* wstream) { | 86 static void serialize_sub(const char* fontName, SkFontStyle style, SkWStream* ws
tream) { |
87 SkFontDescriptor desc(style); | 87 SkFontDescriptor desc; |
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); |
92 desc.serialize(wstream); | 93 desc.serialize(wstream); |
93 #if WHITELIST_DEBUG | 94 #if WHITELIST_DEBUG |
94 for (int i = 0; i < whitelistCount; ++i) { | 95 for (int i = 0; i < whitelistCount; ++i) { |
95 if (!strcmp(fontName, whitelist[i].fFontName)) { | 96 if (!strcmp(fontName, whitelist[i].fFontName)) { |
96 if (!whitelist[i].fSerializedSub) { | 97 if (!whitelist[i].fSerializedSub) { |
97 whitelist[i].fSerializedSub = true; | 98 whitelist[i].fSerializedSub = true; |
98 SkDebugf("%s %s\n", __FUNCTION__, familyName); | 99 SkDebugf("%s %s\n", __FUNCTION__, familyName); |
99 } | 100 } |
100 break; | 101 break; |
101 } | 102 } |
102 } | 103 } |
103 #endif | 104 #endif |
104 } | 105 } |
105 | 106 |
106 static bool is_local(const SkTypeface* tf) { | 107 static bool is_local(const SkTypeface* tf) { |
107 bool isLocal = false; | 108 bool isLocal = false; |
108 SkFontDescriptor desc(tf->style()); | 109 SkFontDescriptor desc; |
109 tf->getFontDescriptor(&desc, &isLocal); | 110 tf->getFontDescriptor(&desc, &isLocal); |
110 return isLocal; | 111 return isLocal; |
111 } | 112 } |
112 | 113 |
113 static void serialize_full(const SkTypeface* tf, SkWStream* wstream) { | 114 static void serialize_full(const SkTypeface* tf, SkWStream* wstream) { |
114 bool isLocal = false; | 115 bool isLocal = false; |
115 SkFontDescriptor desc(tf->style()); | 116 SkFontDescriptor desc; |
116 tf->getFontDescriptor(&desc, &isLocal); | 117 tf->getFontDescriptor(&desc, &isLocal); |
117 | 118 |
118 // Embed font data if it's a local font. | 119 // Embed font data if it's a local font. |
119 if (isLocal && !desc.hasFontData()) { | 120 if (isLocal && !desc.hasFontData()) { |
120 desc.setFontData(tf->createFontData()); | 121 desc.setFontData(tf->createFontData()); |
121 } | 122 } |
122 desc.serialize(wstream); | 123 desc.serialize(wstream); |
123 } | 124 } |
124 | 125 |
125 static void serialize_name_only(const SkTypeface* tf, SkWStream* wstream) { | 126 static void serialize_name_only(const SkTypeface* tf, SkWStream* wstream) { |
126 bool isLocal = false; | 127 bool isLocal = false; |
127 SkFontDescriptor desc(tf->style()); | 128 SkFontDescriptor desc; |
128 tf->getFontDescriptor(&desc, &isLocal); | 129 tf->getFontDescriptor(&desc, &isLocal); |
129 SkASSERT(!isLocal); | 130 SkASSERT(!isLocal); |
130 #if WHITELIST_DEBUG | 131 #if WHITELIST_DEBUG |
131 const char* familyName = desc.getFamilyName(); | 132 const char* familyName = desc.getFamilyName(); |
132 if (familyName) { | 133 if (familyName) { |
133 if (!strcmp(familyName, "Times New Roman")) { | 134 if (!strcmp(familyName, "Times New Roman")) { |
134 if (!timesNewRomanSerializedNameOnly) { | 135 if (!timesNewRomanSerializedNameOnly) { |
135 timesNewRomanSerializedNameOnly = true; | 136 timesNewRomanSerializedNameOnly = true; |
136 SkDebugf("%s %s\n", __FUNCTION__, familyName); | 137 SkDebugf("%s %s\n", __FUNCTION__, familyName); |
137 } | 138 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 if (whitelist[whitelistIndex].fChecksum != checksum) { | 174 if (whitelist[whitelistIndex].fChecksum != checksum) { |
174 #if WHITELIST_DEBUG | 175 #if WHITELIST_DEBUG |
175 if (whitelist[whitelistIndex].fChecksum) { | 176 if (whitelist[whitelistIndex].fChecksum) { |
176 SkDebugf("!!! checksum changed !!!\n"); | 177 SkDebugf("!!! checksum changed !!!\n"); |
177 } | 178 } |
178 SkDebugf("checksum updated\n"); | 179 SkDebugf("checksum updated\n"); |
179 SkDebugf(" { \"%s\", 0x%08x },\n", fontName, checksum); | 180 SkDebugf(" { \"%s\", 0x%08x },\n", fontName, checksum); |
180 #endif | 181 #endif |
181 whitelist[whitelistIndex].fChecksum = checksum; | 182 whitelist[whitelistIndex].fChecksum = checksum; |
182 } | 183 } |
183 serialize_sub(fontName, tf->style(), wstream); | 184 serialize_sub(fontName, tf->fontStyle(), wstream); |
184 } | 185 } |
185 | 186 |
186 sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) { | 187 sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) { |
187 SkFontDescriptor desc; | 188 SkFontDescriptor desc; |
188 if (!SkFontDescriptor::Deserialize(stream, &desc)) { | 189 if (!SkFontDescriptor::Deserialize(stream, &desc)) { |
189 return nullptr; | 190 return nullptr; |
190 } | 191 } |
191 | 192 |
192 SkFontData* data = desc.detachFontData(); | 193 SkFontData* data = desc.detachFontData(); |
193 if (data) { | 194 if (data) { |
194 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data)); | 195 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data)); |
195 if (typeface) { | 196 if (typeface) { |
196 return typeface; | 197 return typeface; |
197 } | 198 } |
198 } | 199 } |
199 const char* familyName = desc.getFamilyName(); | 200 const char* familyName = desc.getFamilyName(); |
200 if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) { | 201 if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) { |
201 familyName += sizeof(SUBNAME_PREFIX) - 1; | 202 familyName += sizeof(SUBNAME_PREFIX) - 1; |
202 } | 203 } |
203 return SkTypeface::MakeFromName(familyName, SkFontStyle::FromOldStyle(desc.g
etStyle())); | 204 return SkTypeface::MakeFromName(familyName, desc.getStyle()); |
204 } | 205 } |
205 | 206 |
206 bool CheckChecksums() { | 207 bool CheckChecksums() { |
207 for (int i = 0; i < whitelistCount; ++i) { | 208 for (int i = 0; i < whitelistCount; ++i) { |
208 const char* fontName = whitelist[i].fFontName; | 209 const char* fontName = whitelist[i].fFontName; |
209 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkFontStyle())); | 210 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkFontStyle())); |
210 uint32_t checksum = compute_checksum(tf.get()); | 211 uint32_t checksum = compute_checksum(tf.get()); |
211 if (whitelist[i].fChecksum != checksum) { | 212 if (whitelist[i].fChecksum != checksum) { |
212 return false; | 213 return false; |
213 } | 214 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 const char* fontName = whitelist[i].fFontName; | 264 const char* fontName = whitelist[i].fFontName; |
264 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkFontStyle())); | 265 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkFontStyle())); |
265 uint32_t checksum = compute_checksum(tf.get()); | 266 uint32_t checksum = compute_checksum(tf.get()); |
266 line.printf(checksumEntry, fontName, checksum); | 267 line.printf(checksumEntry, fontName, checksum); |
267 sk_fwrite(line.c_str(), line.size(), file); | 268 sk_fwrite(line.c_str(), line.size(), file); |
268 } | 269 } |
269 sk_fwrite(checksumTrailer, sizeof(checksumTrailer) - 1, file); | 270 sk_fwrite(checksumTrailer, sizeof(checksumTrailer) - 1, file); |
270 sk_fclose(file); | 271 sk_fclose(file); |
271 return true; | 272 return true; |
272 } | 273 } |
OLD | NEW |