Chromium Code Reviews| Index: ui/gfx/platform_font_win.cc |
| diff --git a/ui/gfx/platform_font_win.cc b/ui/gfx/platform_font_win.cc |
| index df2b874b64b6fbf2b2062142d9ccaa6cac299092..93f95a72bbb624dff6fab1e6919fdcebe496880f 100644 |
| --- a/ui/gfx/platform_font_win.cc |
| +++ b/ui/gfx/platform_font_win.cc |
| @@ -9,6 +9,7 @@ |
| #include <math.h> |
| #include <windows.h> |
| +#include "base/debug/alias.h" |
| #include "base/logging.h" |
| #include "base/macros.h" |
| #include "base/strings/string_util.h" |
| @@ -125,8 +126,40 @@ HRESULT GetMatchingDirectWriteFontForTypeface(const wchar_t* face_name, |
| DWRITE_FONT_STYLE italic = (font_style & SkTypeface::kItalic) |
| ? DWRITE_FONT_STYLE_ITALIC |
| : DWRITE_FONT_STYLE_NORMAL; |
| + |
| + // The IDWriteFontFamily::GetFirstMatchingFont call fails on certain machines |
| + // for fonts like MS UI Gothic, Segoe UI, etc. It is not clear why these |
| + // fonts could be accessible to GDI and not to DirectWrite. |
| + // The code below adds some debug fields to help track down these failures. |
| + // 1. We get the matching font list for the font attributes passed in. |
| + // 2. We get the font count in the family with a debug alias variable. |
| + // 3. If we fail to get the font via the GetFirstMatchingFont call then we |
| + // try to get the first matching font in the IDWriteFontList. |
| + // 4. If GetFirstMatchingFont and IDWriteFontList both fail then we CHECK as |
| + // before. |
| + // Next step would be to remove the CHECKs in this function and fallback to |
| + // GDI. |
|
scottmg
2014/11/19 22:15:36
add crbug link
ananta
2014/11/19 22:21:30
Done.
|
| + uint32 matching_font_count = 0; |
| + base::debug::Alias(&matching_font_count); |
| + |
| + base::win::ScopedComPtr<IDWriteFontList> matching_font_list; |
| + hr = font_family->GetMatchingFonts(weight, stretch, italic, |
| + matching_font_list.Receive()); |
| + if (SUCCEEDED(hr)) |
| + matching_font_count = matching_font_list->GetFontCount(); |
|
scottmg
2014/11/19 22:15:36
is it necessary to debug::Alias again after the as
ananta
2014/11/19 22:21:30
Done.
|
| + |
| + bool fallback_to_matching_font = false; |
| + base::debug::Alias(&fallback_to_matching_font); |
| + |
| hr = font_family->GetFirstMatchingFont(weight, stretch, italic, |
| dwrite_font); |
| + if (FAILED(hr)) { |
| + if (matching_font_list) { |
| + hr = matching_font_list->GetFont(0, dwrite_font); |
| + if (SUCCEEDED(hr)) |
| + fallback_to_matching_font = true; |
|
scottmg
2014/11/19 22:15:36
same
ananta
2014/11/19 22:21:30
Done.
|
| + } |
| + } |
| if (FAILED(hr)) |
| CHECK(false); |
| return hr; |
| @@ -447,7 +480,7 @@ PlatformFontWin::HFontRef* PlatformFontWin::CreateHFontRefFromSkia( |
| // GetAverageCharWidthInDialogUnits for details. |
| const int ave_char_width = |
| skia_metrics.fAvgCharWidth == 0 ? |
| - HFontRef::GetAverageCharWidthInDialogUnits(gdi_font) |
| + HFontRef::GetAverageCharWidthInDialogUnits(gdi_font) - 1 |
| : skia_metrics.fAvgCharWidth; |
| // tmAscent - tmInternalLeading in gdi font land gives us the cap height. |