OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/mac/scoped_cftyperef.h" | 9 #include "base/mac/scoped_cftyperef.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 ATSFontContainerRef font_container; | 119 ATSFontContainerRef font_container; |
120 if (!FontLoader::ATSFontContainerFromBuffer(shmem_handle, font_data_length_, | 120 if (!FontLoader::ATSFontContainerFromBuffer(shmem_handle, font_data_length_, |
121 &font_container)) { | 121 &font_container)) { |
122 LOG(ERROR) << "Call to CreateCGFontFromBuffer() failed"; | 122 LOG(ERROR) << "Call to CreateCGFontFromBuffer() failed"; |
123 return false; | 123 return false; |
124 } | 124 } |
125 | 125 |
126 // Unload the font container when done. | 126 // Unload the font container when done. |
127 ScopedFontContainer scoped_unloader(font_container); | 127 ScopedFontContainer scoped_unloader(font_container); |
128 | 128 |
129 CGFontRef font_ref; | 129 CGFontRef cg_font_ref; |
130 if (!CGFontFromFontContainer(font_container, &font_ref)) { | 130 if (!CGFontFromFontContainer(font_container, &cg_font_ref)) { |
131 LOG(ERROR) << "CGFontFromFontContainer failed"; | 131 LOG(ERROR) << "CGFontFromFontContainer failed"; |
132 return false; | 132 return false; |
133 } | 133 } |
134 | 134 |
135 if (!font_ref) { | 135 if (!cg_font_ref) { |
136 LOG(ERROR) << "Got NULL CGFontRef"; | 136 LOG(ERROR) << "Got NULL CGFontRef"; |
137 return false; | 137 return false; |
138 } | 138 } |
139 base::mac::ScopedCFTypeRef<CGFontRef> cgfont; | 139 base::mac::ScopedCFTypeRef<CGFontRef> cgfont(cg_font_ref); |
140 cgfont.reset(font_ref); | |
141 | 140 |
142 const NSFont* nsfont = reinterpret_cast<const NSFont*>( | 141 CTFontRef ct_font_ref = |
143 CTFontCreateWithGraphicsFont(cgfont.get(), 16.0, | 142 CTFontCreateWithGraphicsFont(cgfont.get(), 16.0, NULL, NULL); |
144 NULL, NULL)); | 143 base::mac::ScopedCFTypeRef<CTFontRef> ctfont(ct_font_ref); |
145 if (!nsfont) { | 144 |
| 145 if (!ct_font_ref) { |
146 LOG(ERROR) << "CTFontCreateWithGraphicsFont() failed"; | 146 LOG(ERROR) << "CTFontCreateWithGraphicsFont() failed"; |
147 return false; | 147 return false; |
148 } | 148 } |
149 | 149 |
150 // Do something with the font to make sure it's loaded. | 150 // Do something with the font to make sure it's loaded. |
151 CGFloat cap_height = [nsfont capHeight]; | 151 CGFloat cap_height = CTFontGetCapHeight(ct_font_ref); |
152 | 152 |
153 if (cap_height <= 0.0) { | 153 if (cap_height <= 0.0) { |
154 LOG(ERROR) << "Got bad value for [NSFont capHeight] " << cap_height; | 154 LOG(ERROR) << "Got bad value for CTFontGetCapHeight " << cap_height; |
155 return false; | 155 return false; |
156 } | 156 } |
157 | 157 |
158 return true; | 158 return true; |
159 } | 159 } |
160 | 160 |
161 TEST_F(MacSandboxTest, FontLoadingTest) { | 161 TEST_F(MacSandboxTest, FontLoadingTest) { |
162 FilePath temp_file_path; | 162 FilePath temp_file_path; |
163 FILE* temp_file = file_util::CreateAndOpenTemporaryFile(&temp_file_path); | 163 FILE* temp_file = file_util::CreateAndOpenTemporaryFile(&temp_file_path); |
164 ASSERT_TRUE(temp_file); | 164 ASSERT_TRUE(temp_file); |
165 file_util::ScopedFILE temp_file_closer(temp_file); | 165 file_util::ScopedFILE temp_file_closer(temp_file); |
166 | 166 |
167 base::SharedMemory font_data; | 167 base::SharedMemory font_data; |
168 uint32 font_data_size; | 168 uint32 font_data_size; |
169 NSFont* srcFont = [NSFont fontWithName:@"Geeza Pro" size:16.0]; | 169 NSFont* srcFont = [NSFont fontWithName:@"Geeza Pro" size:16.0]; |
170 EXPECT_TRUE(FontLoader::LoadFontIntoBuffer(srcFont, | 170 EXPECT_TRUE(FontLoader::LoadFontIntoBuffer(srcFont, |
171 &font_data, &font_data_size)); | 171 &font_data, &font_data_size)); |
172 EXPECT_GT(font_data_size, 0U); | 172 EXPECT_GT(font_data_size, 0U); |
173 | 173 |
174 file_util::WriteFileDescriptor(fileno(temp_file), | 174 file_util::WriteFileDescriptor(fileno(temp_file), |
175 static_cast<const char *>(font_data.memory()), font_data_size); | 175 static_cast<const char *>(font_data.memory()), font_data_size); |
176 | 176 |
177 ASSERT_TRUE(RunTestInSandbox(sandbox::SANDBOX_TYPE_RENDERER, | 177 ASSERT_TRUE(RunTestInSandbox(sandbox::SANDBOX_TYPE_RENDERER, |
178 "FontLoadingTestCase", temp_file_path.value().c_str())); | 178 "FontLoadingTestCase", temp_file_path.value().c_str())); |
179 temp_file_closer.reset(); | 179 temp_file_closer.reset(); |
180 ASSERT_TRUE(file_util::Delete(temp_file_path, false)); | 180 ASSERT_TRUE(file_util::Delete(temp_file_path, false)); |
181 } | 181 } |
182 | 182 |
183 } // namespace | 183 } // namespace |
OLD | NEW |