OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/gfx/platform_font_win.h" | 5 #include "ui/gfx/platform_font_win.h" |
6 | 6 |
| 7 #include <windows.h> |
7 #include <dwrite.h> | 8 #include <dwrite.h> |
8 #include <math.h> | 9 #include <math.h> |
| 10 #include <stdint.h> |
9 #include <wchar.h> | 11 #include <wchar.h> |
10 #include <windows.h> | |
11 | 12 |
12 #include <algorithm> | 13 #include <algorithm> |
13 | 14 |
14 #include "base/debug/alias.h" | 15 #include "base/debug/alias.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/sys_string_conversions.h" | 20 #include "base/strings/sys_string_conversions.h" |
20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // GDI has its own font system where in it creates a font matching the | 183 // GDI has its own font system where in it creates a font matching the |
183 // characteristics in the LOGFONT structure passed into | 184 // characteristics in the LOGFONT structure passed into |
184 // CreateFontIndirect. DirectWrite does not do that. If this succeeds then | 185 // CreateFontIndirect. DirectWrite does not do that. If this succeeds then |
185 // return the matching IDWriteFont from the family. | 186 // return the matching IDWriteFont from the family. |
186 // 2. If step 1 fails then repeat with the default system font. This has the | 187 // 2. If step 1 fails then repeat with the default system font. This has the |
187 // same limitations with the face name as mentioned above. | 188 // same limitations with the face name as mentioned above. |
188 // 3. If step 2 fails then return the first family from the collection and | 189 // 3. If step 2 fails then return the first family from the collection and |
189 // use that. | 190 // use that. |
190 base::win::ScopedComPtr<IDWriteFontFamily> font_family; | 191 base::win::ScopedComPtr<IDWriteFontFamily> font_family; |
191 BOOL exists = FALSE; | 192 BOOL exists = FALSE; |
192 uint32 index = 0; | 193 uint32_t index = 0; |
193 hr = font_collection->FindFamilyName(font_info->lfFaceName, &index, &exists); | 194 hr = font_collection->FindFamilyName(font_info->lfFaceName, &index, &exists); |
194 // If we fail to find a match then try fallback to the default font on the | 195 // If we fail to find a match then try fallback to the default font on the |
195 // system. This is what skia does as well. | 196 // system. This is what skia does as well. |
196 if (FAILED(hr) || (index == UINT_MAX) || !exists) { | 197 if (FAILED(hr) || (index == UINT_MAX) || !exists) { |
197 NONCLIENTMETRICS metrics = {0}; | 198 NONCLIENTMETRICS metrics = {0}; |
198 metrics.cbSize = sizeof(metrics); | 199 metrics.cbSize = sizeof(metrics); |
199 if (!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, | 200 if (!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, |
200 sizeof(metrics), | 201 sizeof(metrics), |
201 &metrics, | 202 &metrics, |
202 0)) { | 203 0)) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 // 3. If GetFirstMatchingFont fails then we CHECK as before. | 253 // 3. If GetFirstMatchingFont fails then we CHECK as before. |
253 // Next step would be to remove the CHECKs in this function and fallback to | 254 // Next step would be to remove the CHECKs in this function and fallback to |
254 // GDI. | 255 // GDI. |
255 // http://crbug.com/434425 | 256 // http://crbug.com/434425 |
256 // TODO(ananta) | 257 // TODO(ananta) |
257 // Remove the GetMatchingFonts and related code here once we get to a stable | 258 // Remove the GetMatchingFonts and related code here once we get to a stable |
258 // state in canary. | 259 // state in canary. |
259 base::win::ScopedComPtr<IDWriteFontList> matching_font_list; | 260 base::win::ScopedComPtr<IDWriteFontList> matching_font_list; |
260 hr = font_family->GetMatchingFonts(weight, stretch, italic, | 261 hr = font_family->GetMatchingFonts(weight, stretch, italic, |
261 matching_font_list.Receive()); | 262 matching_font_list.Receive()); |
262 uint32 matching_font_count = 0; | 263 uint32_t matching_font_count = 0; |
263 if (SUCCEEDED(hr)) | 264 if (SUCCEEDED(hr)) |
264 matching_font_count = matching_font_list->GetFontCount(); | 265 matching_font_count = matching_font_list->GetFontCount(); |
265 | 266 |
266 hr = font_family->GetFirstMatchingFont(weight, stretch, italic, | 267 hr = font_family->GetFirstMatchingFont(weight, stretch, italic, |
267 dwrite_font); | 268 dwrite_font); |
268 if (FAILED(hr)) { | 269 if (FAILED(hr)) { |
269 base::debug::Alias(&matching_font_count); | 270 base::debug::Alias(&matching_font_count); |
270 CHECK(false); | 271 CHECK(false); |
271 } | 272 } |
272 | 273 |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 return new PlatformFontWin(native_font); | 723 return new PlatformFontWin(native_font); |
723 } | 724 } |
724 | 725 |
725 // static | 726 // static |
726 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 727 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
727 int font_size) { | 728 int font_size) { |
728 return new PlatformFontWin(font_name, font_size); | 729 return new PlatformFontWin(font_name, font_size); |
729 } | 730 } |
730 | 731 |
731 } // namespace gfx | 732 } // namespace gfx |
OLD | NEW |