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(_WIN32) | 5 #if !defined(_WIN32) |
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 if (error) { | 103 if (error) { |
104 return false; | 104 return false; |
105 } | 105 } |
106 ::FT_Done_Face(dummy); | 106 ::FT_Done_Face(dummy); |
107 return true; | 107 return true; |
108 } | 108 } |
109 | 109 |
110 #elif defined(__APPLE_CC__) | 110 #elif defined(__APPLE_CC__) |
111 // Mac | 111 // Mac |
112 bool VerifyTranscodedFont(uint8_t *result, const size_t len) { | 112 bool VerifyTranscodedFont(uint8_t *result, const size_t len) { |
113 ATSFontContainerRef container_ref = 0; | 113 CFDataRef data = CFDataCreate(0, result, len); |
114 ATSFontActivateFromMemory(result, len, 3, kATSFontFormatUnspecified, | 114 if (!data) { |
115 NULL, kATSOptionFlagsDefault, &container_ref); | |
116 if (!container_ref) { | |
117 return false; | 115 return false; |
118 } | 116 } |
119 | 117 |
120 ItemCount count; | 118 CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(data); |
121 ATSFontFindFromContainer( | 119 CGFontRef cgFontRef = CGFontCreateWithDataProvider(dataProvider); |
122 container_ref, kATSOptionFlagsDefault, 0, NULL, &count); | 120 CGDataProviderRelease(dataProvider); |
123 if (!count) { | 121 CFRelease(data); |
| 122 if (!cgFontRef) { |
124 return false; | 123 return false; |
125 } | 124 } |
126 | 125 |
127 ATSFontRef ats_font_ref = 0; | 126 size_t numGlyphs = CGFontGetNumberOfGlyphs(cgFontRef); |
128 ATSFontFindFromContainer( | 127 CGFontRelease(cgFontRef); |
129 container_ref, kATSOptionFlagsDefault, 1, &ats_font_ref, NULL); | 128 if (!numGlyphs) { |
130 if (!ats_font_ref) { | |
131 return false; | |
132 } | |
133 | |
134 CTFontRef ct_font_ref = CTFontCreateWithPlatformFont(ats_font_ref, 12, | |
135 NULL, NULL); | |
136 if (!CTFontGetGlyphCount(ct_font_ref)) { | |
137 return false; | 129 return false; |
138 } | 130 } |
139 return true; | 131 return true; |
140 } | 132 } |
141 | 133 |
142 #elif defined(_WIN32) | 134 #elif defined(_WIN32) |
143 // Windows | 135 // Windows |
144 bool VerifyTranscodedFont(uint8_t *result, const size_t len) { | 136 bool VerifyTranscodedFont(uint8_t *result, const size_t len) { |
145 DWORD num_fonts = 0; | 137 DWORD num_fonts = 0; |
146 HANDLE handle = AddFontMemResourceEx(result, len, 0, &num_fonts); | 138 HANDLE handle = AddFontMemResourceEx(result, len, 0, &num_fonts); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 208 |
217 // Verify that the transcoded font can be opened by the font renderer for | 209 // Verify that the transcoded font can be opened by the font renderer for |
218 // Linux (FreeType2), Mac OS X, or Windows. | 210 // Linux (FreeType2), Mac OS X, or Windows. |
219 if (!VerifyTranscodedFont(result, result_len)) { | 211 if (!VerifyTranscodedFont(result, result_len)) { |
220 std::fprintf(stderr, "Failed to verify the transcoded font\n"); | 212 std::fprintf(stderr, "Failed to verify the transcoded font\n"); |
221 return 1; | 213 return 1; |
222 } | 214 } |
223 | 215 |
224 return 0; | 216 return 0; |
225 } | 217 } |
OLD | NEW |