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..e120ab820ff7b9ae41e5552be7dbc980cb41d458 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,42 @@ 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. |
+ // http://crbug.com/434425 |
+ |
+ base::win::ScopedComPtr<IDWriteFontList> matching_font_list; |
+ hr = font_family->GetMatchingFonts(weight, stretch, italic, |
+ matching_font_list.Receive()); |
+ uint32 matching_font_count = 0; |
+ if (SUCCEEDED(hr)) |
+ matching_font_count = matching_font_list->GetFontCount(); |
+ base::debug::Alias(&matching_font_count); |
+ |
+ bool fallback_to_matching_font = false; |
+ |
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; |
+ } |
+ } |
+ base::debug::Alias(&fallback_to_matching_font); |
sky
2014/11/19 22:33:01
Can you move the Alias calls to where you need it?
ananta
2014/11/19 22:35:02
Done.
|
+ |
if (FAILED(hr)) |
CHECK(false); |
return hr; |
@@ -447,7 +482,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. |