Chromium Code Reviews| Index: ui/gfx/platform_font_win_unittest.cc |
| diff --git a/ui/gfx/platform_font_win_unittest.cc b/ui/gfx/platform_font_win_unittest.cc |
| index dc4ac5eb54bf92896c92c339f6f22da41b265202..bfefdf436d7b09381f5441007c3fa277bce6693b 100644 |
| --- a/ui/gfx/platform_font_win_unittest.cc |
| +++ b/ui/gfx/platform_font_win_unittest.cc |
| @@ -43,10 +43,6 @@ gfx::Font AdjustFontSizeForHeight(const gfx::Font& base_font, |
| } // namespace |
| TEST(PlatformFontWinTest, DeriveFontWithHeight) { |
| - // TODO(ananta): Fix this test for DirectWrite. http://crbug.com/442010 |
| - if (gfx::win::IsDirectWriteEnabled()) |
| - return; |
| - |
| const Font base_font; |
| PlatformFontWin* platform_font = |
| static_cast<PlatformFontWin*>(base_font.platform_font()); |
| @@ -55,17 +51,33 @@ TEST(PlatformFontWinTest, DeriveFontWithHeight) { |
| const int target_height = base_font.GetHeight() + i; |
| Font expected_font = AdjustFontSizeForHeight(base_font, target_height); |
| ASSERT_LE(expected_font.GetHeight(), target_height); |
| - |
| - Font derived_font = platform_font->DeriveFontWithHeight(target_height, 0); |
| + // With DirectWrite the height of the expected font calculated above may be |
|
msw
2015/01/09 23:40:22
I might just nuke AdjustFontSizeForHeight and expe
ananta
2015/01/10 00:43:15
DeriveFontWithHeight is windows specific at the mo
|
| + // lesser or greater by 1 px from the desired height due to vagaries in the |
| + // metrics calculation. |
| + // The AdjustFontSizeForHeight function and the DeriveFontWithHeight |
| + // function don't work the same way and thus we end up with mismatched |
| + // fonts with DirectWrite. To workaround this we use the expected fonts |
| + // height for the tests below. |
| + Font derived_font = platform_font->DeriveFontWithHeight( |
| + expected_font.GetHeight(), 0); |
| EXPECT_EQ(expected_font.GetFontName(), derived_font.GetFontName()); |
| - EXPECT_EQ(expected_font.GetFontSize(), derived_font.GetFontSize()); |
| + // Wierdly enough for some font heights like 24 and above when the font is |
| + // created via CreateFontIndirect and we get the metrics for the same, the |
| + // height returned by the GetTextMetric API is 23. This causes the derived |
| + // fonts size to be off by 1 px from the expected font size. We only see |
| + // this with DirectWrite because with GDI the AdjustFontSizeForHeight |
| + // function returns a font with height 23 and everything works well. |
| + EXPECT_LE(abs(expected_font.GetFontSize() - derived_font.GetFontSize()), |
| + 1); |
| EXPECT_LE(expected_font.GetHeight(), target_height); |
| EXPECT_EQ(0, derived_font.GetStyle()); |
| - derived_font = platform_font->DeriveFontWithHeight(target_height, |
| - Font::BOLD); |
| + derived_font = platform_font->DeriveFontWithHeight( |
| + expected_font.GetHeight(), Font::BOLD); |
| EXPECT_EQ(expected_font.GetFontName(), derived_font.GetFontName()); |
| - EXPECT_EQ(expected_font.GetFontSize(), derived_font.GetFontSize()); |
| + // Please refer to the comment above as to why this check is needed. |
| + EXPECT_LE(abs(expected_font.GetFontSize() - derived_font.GetFontSize()), |
| + 1); |
| EXPECT_LE(expected_font.GetHeight(), target_height); |
| EXPECT_EQ(Font::BOLD, derived_font.GetStyle()); |
| @@ -80,9 +92,6 @@ TEST(PlatformFontWinTest, DeriveFontWithHeight) { |
| } |
| TEST(PlatformFontWinTest, DeriveFontWithHeight_Consistency) { |
| - // TODO(ananta): Fix this test for DirectWrite. http://crbug.com/442010 |
| - if (gfx::win::IsDirectWriteEnabled()) |
| - return; |
| gfx::Font arial_12("Arial", 12); |
| ASSERT_GT(16, arial_12.GetHeight()); |
| gfx::Font derived_1 = static_cast<PlatformFontWin*>( |