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) |
| 6 #ifdef __linux__ |
| 7 // Linux |
| 8 #include <freetype/ftoutln.h> |
| 9 #include <ft2build.h> |
| 10 #include FT_FREETYPE_H |
| 11 #else |
| 12 // Mac OS X |
| 13 #include <ApplicationServices/ApplicationServices.h> // g++ -framework Cocoa |
| 14 #endif // __linux__ |
| 15 #else |
| 16 // Windows |
| 17 // TODO(yusukes): Support Windows. |
| 18 #endif // _MSC_VER |
| 19 |
5 #include <fcntl.h> | 20 #include <fcntl.h> |
6 #include <sys/stat.h> | 21 #include <sys/stat.h> |
7 #include <unistd.h> | 22 #include <unistd.h> |
8 | 23 |
9 #include <cstdio> | 24 #include <cstdio> |
10 #include <cstdlib> | 25 #include <cstdlib> |
11 #include <cstring> | 26 #include <cstring> |
12 | 27 |
13 #include "opentype-sanitiser.h" | 28 #include "opentype-sanitiser.h" |
14 #include "ots-memory-stream.h" | 29 #include "ots-memory-stream.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 ::perror("opening output file"); | 98 ::perror("opening output file"); |
84 return 1; | 99 return 1; |
85 } | 100 } |
86 if ((::write(fd1, result, result_len) < 0) || | 101 if ((::write(fd1, result, result_len) < 0) || |
87 (::write(fd2, result2, result2_len) < 0)) { | 102 (::write(fd2, result2, result2_len) < 0)) { |
88 ::perror("writing output file"); | 103 ::perror("writing output file"); |
89 return 1; | 104 return 1; |
90 } | 105 } |
91 } | 106 } |
92 | 107 |
| 108 // Verify that the transcoded font can be opened by the font renderer for |
| 109 // Linux (FreeType2), Mac OS X, or Windows. |
| 110 #if !defined(_MSC_VER) |
| 111 #ifdef __linux__ |
| 112 // Linux |
| 113 FT_Library library; |
| 114 FT_Error error = ::FT_Init_FreeType(&library); |
| 115 if (error) { |
| 116 std::fprintf(stderr, "Failed to initialize FreeType2!\n"); |
| 117 return 1; |
| 118 } |
| 119 FT_Face dummy; |
| 120 error = ::FT_New_Memory_Face(library, result, result_len, 0, &dummy); |
| 121 if (error) { |
| 122 std::fprintf(stderr, "Failed to open the transcoded font\n"); |
| 123 return 1; |
| 124 } |
| 125 #else |
| 126 // Mac OS X |
| 127 ATSFontContainerRef container_ref = 0; |
| 128 ATSFontActivateFromMemory(result, result_len, 3, kATSFontFormatUnspecified, |
| 129 NULL, kATSOptionFlagsDefault, &container_ref); |
| 130 if (!container_ref) { |
| 131 std::fprintf(stderr, "Failed to open the transcoded font\n"); |
| 132 return 1; |
| 133 } |
| 134 |
| 135 ItemCount count; |
| 136 ATSFontFindFromContainer( |
| 137 container_ref, kATSOptionFlagsDefault, 0, NULL, &count); |
| 138 if (!count) { |
| 139 std::fprintf(stderr, "Failed to open the transcoded font\n"); |
| 140 return 1; |
| 141 } |
| 142 |
| 143 ATSFontRef ats_font_ref = 0; |
| 144 ATSFontFindFromContainer( |
| 145 container_ref, kATSOptionFlagsDefault, 1, &ats_font_ref, NULL); |
| 146 if (!ats_font_ref) { |
| 147 std::fprintf(stderr, "Failed to open the transcoded font\n"); |
| 148 return 1; |
| 149 } |
| 150 |
| 151 CGFontRef cg_font_ref = CGFontCreateWithPlatformFont(&ats_font_ref); |
| 152 if (!CGFontGetNumberOfGlyphs(cg_font_ref)) { |
| 153 std::fprintf(stderr, "Failed to open the transcoded font\n"); |
| 154 return 1; |
| 155 } |
| 156 #endif // __linux__ |
| 157 #else |
| 158 // Windows |
| 159 // TODO(yusukes): Support Windows. |
| 160 #endif // _MSC_VER |
| 161 |
93 return 0; | 162 return 0; |
94 } | 163 } |
OLD | NEW |