| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #if !defined(_MSC_VER) | 5 #if !defined(_MSC_VER) |
| 6 #ifdef __linux__ | 6 #ifdef __linux__ |
| 7 // Linux | 7 // Linux |
| 8 #include <freetype/ftoutln.h> | 8 #include <freetype/ftoutln.h> |
| 9 #include <ft2build.h> | 9 #include <ft2build.h> |
| 10 #include FT_FREETYPE_H | 10 #include FT_FREETYPE_H |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 std::fprintf(stderr, "OK: FreeType2 didn't crash: %s\n", file_name); | 88 std::fprintf(stderr, "OK: FreeType2 didn't crash: %s\n", file_name); |
| 89 return 0; | 89 return 0; |
| 90 } | 90 } |
| 91 #else | 91 #else |
| 92 // Mac OS X | 92 // Mac OS X |
| 93 int OpenAndLoadChars( | 93 int OpenAndLoadChars( |
| 94 const char *file_name, uint8_t *trans_font, size_t trans_len) { | 94 const char *file_name, uint8_t *trans_font, size_t trans_len) { |
| 95 ATSFontContainerRef container_ref = 0; | 95 CFDataRef data = CFDataCreate(0, trans_font, trans_len); |
| 96 ATSFontActivateFromMemory(trans_font, trans_len, 3, kATSFontFormatUnspecified, | 96 if (!data) { |
| 97 NULL, kATSOptionFlagsDefault, &container_ref); | |
| 98 if (!container_ref) { | |
| 99 std::fprintf(stderr, | 97 std::fprintf(stderr, |
| 100 "OK: font renderer couldn't open the transcoded font: %s\n", | 98 "OK: font renderer couldn't open the transcoded font: %s\n", |
| 101 file_name); | 99 file_name); |
| 102 return 0; | 100 return 0; |
| 103 } | 101 } |
| 104 | 102 |
| 105 ItemCount count; | 103 CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(data); |
| 106 ATSFontFindFromContainer( | 104 CGFontRef cgFontRef = CGFontCreateWithDataProvider(dataProvider); |
| 107 container_ref, kATSOptionFlagsDefault, 0, NULL, &count); | 105 CGDataProviderRelease(dataProvider); |
| 108 if (!count) { | 106 CFRelease(data); |
| 107 if (!cgFontRef) { |
| 109 std::fprintf(stderr, | 108 std::fprintf(stderr, |
| 110 "OK: font renderer couldn't open the transcoded font: %s\n", | 109 "OK: font renderer couldn't open the transcoded font: %s\n", |
| 111 file_name); | 110 file_name); |
| 112 return 0; | 111 return 0; |
| 113 } | 112 } |
| 114 | 113 |
| 115 ATSFontRef ats_font_ref = 0; | 114 size_t numGlyphs = CGFontGetNumberOfGlyphs(cgFontRef); |
| 116 ATSFontFindFromContainer( | 115 CGFontRelease(cgFontRef); |
| 117 container_ref, kATSOptionFlagsDefault, 1, &ats_font_ref, NULL); | 116 if (!numGlyphs) { |
| 118 if (!ats_font_ref) { | |
| 119 std::fprintf(stderr, | 117 std::fprintf(stderr, |
| 120 "OK: font renderer couldn't open the transcoded font: %s\n", | 118 "OK: font renderer couldn't open the transcoded font: %s\n", |
| 121 file_name); | 119 file_name); |
| 122 return 0; | 120 return 0; |
| 123 } | 121 } |
| 124 | |
| 125 CTFontRef ct_font_ref = CTFontCreateWithPlatformFont(ats_font_ref, 12, | |
| 126 NULL, NULL); | |
| 127 if (!CTFontGetGlyphCount(ct_font_ref)) { | |
| 128 std::fprintf(stderr, | |
| 129 "OK: font renderer couldn't open the transcoded font: %s\n", | |
| 130 file_name); | |
| 131 return 0; | |
| 132 } | |
| 133 | |
| 134 std::fprintf(stderr, "OK: font renderer didn't crash: %s\n", file_name); | 122 std::fprintf(stderr, "OK: font renderer didn't crash: %s\n", file_name); |
| 135 // TODO(yusukes): would be better to perform LoadChar() like Linux. | 123 // TODO(yusukes): would be better to perform LoadChar() like Linux. |
| 136 return 0; | 124 return 0; |
| 137 } | 125 } |
| 138 #endif // __linux__ | 126 #endif // __linux__ |
| 139 #else | 127 #else |
| 140 // Windows | 128 // Windows |
| 141 // TODO(yusukes): Support Windows. | 129 // TODO(yusukes): Support Windows. |
| 142 #endif // _MSC_VER | 130 #endif // _MSC_VER |
| 143 | 131 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 164 |
| 177 bool result = ots::Process(&output, orig_font, orig_len); | 165 bool result = ots::Process(&output, orig_font, orig_len); |
| 178 if (!result) { | 166 if (!result) { |
| 179 std::fprintf(stderr, "OK: the malicious font was filtered: %s\n", argv[1]); | 167 std::fprintf(stderr, "OK: the malicious font was filtered: %s\n", argv[1]); |
| 180 return 0; | 168 return 0; |
| 181 } | 169 } |
| 182 const size_t trans_len = output.Tell(); | 170 const size_t trans_len = output.Tell(); |
| 183 | 171 |
| 184 return OpenAndLoadChars(argv[1], trans_font, trans_len); | 172 return OpenAndLoadChars(argv[1], trans_font, trans_len); |
| 185 } | 173 } |
| OLD | NEW |