| 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 10 matching lines...) Expand all Loading... |
| 21 sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* ); | 21 sk_sp<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, SkFontStyle 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 sk_sp<SkTypeface> defaultFace(SkTypeface::MakeFromName(nullptr, style)); |
| 36 sk_sp<SkTypeface> foundFace(SkTypeface::MakeFromName(fontName, style)); | 36 sk_sp<SkTypeface> foundFace(SkTypeface::MakeFromName(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 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 if (!is_local(tf)) { | 155 if (!is_local(tf)) { |
| 156 serialize_name_only(tf, wstream); | 156 serialize_name_only(tf, wstream); |
| 157 return; | 157 return; |
| 158 } | 158 } |
| 159 int whitelistIndex = whitelist_name_index(tf); | 159 int whitelistIndex = whitelist_name_index(tf); |
| 160 if (whitelistIndex < 0) { | 160 if (whitelistIndex < 0) { |
| 161 serialize_full(tf, wstream); | 161 serialize_full(tf, wstream); |
| 162 return; | 162 return; |
| 163 } | 163 } |
| 164 const char* fontName = whitelist[whitelistIndex].fFontName; | 164 const char* fontName = whitelist[whitelistIndex].fFontName; |
| 165 if (!font_name_is_local(fontName, tf->style())) { | 165 if (!font_name_is_local(fontName, tf->fontStyle())) { |
| 166 #if WHITELIST_DEBUG | 166 #if WHITELIST_DEBUG |
| 167 SkDebugf("name not found locally \"%s\" style=%d\n", fontName, tf->style
()); | 167 SkDebugf("name not found locally \"%s\" style=%d\n", fontName, tf->style
()); |
| 168 #endif | 168 #endif |
| 169 serialize_full(tf, wstream); | 169 serialize_full(tf, wstream); |
| 170 return; | 170 return; |
| 171 } | 171 } |
| 172 uint32_t checksum = compute_checksum(tf); | 172 uint32_t checksum = compute_checksum(tf); |
| 173 if (whitelist[whitelistIndex].fChecksum != checksum) { | 173 if (whitelist[whitelistIndex].fChecksum != checksum) { |
| 174 #if WHITELIST_DEBUG | 174 #if WHITELIST_DEBUG |
| 175 if (whitelist[whitelistIndex].fChecksum) { | 175 if (whitelist[whitelistIndex].fChecksum) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 193 if (data) { | 193 if (data) { |
| 194 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data)); | 194 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(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::MakeFromName(familyName, SkFontStyle::FromOldStyle(desc.g
etStyle())); |
| 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 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkFontStyle())); |
| 210 uint32_t checksum = compute_checksum(tf.get()); | 210 uint32_t checksum = compute_checksum(tf.get()); |
| 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 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkFontStyle())); |
| 265 uint32_t checksum = compute_checksum(tf.get()); | 265 uint32_t checksum = compute_checksum(tf.get()); |
| 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 } |
| OLD | NEW |