Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Side by Side Diff: ui/gfx/platform_font_win_unittest.cc

Issue 844083002: Get all font unittests running with DirectWrite on Windows 7+ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« ui/gfx/font_list_unittest.cc ('K') | « ui/gfx/platform_font_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 25 matching lines...) Expand all
36 do { 36 do {
37 expected_font = expected_font.Derive(-1, 0); 37 expected_font = expected_font.Derive(-1, 0);
38 } while (expected_font.GetHeight() > target_height); 38 } while (expected_font.GetHeight() > target_height);
39 } 39 }
40 return expected_font; 40 return expected_font;
41 } 41 }
42 42
43 } // namespace 43 } // namespace
44 44
45 TEST(PlatformFontWinTest, DeriveFontWithHeight) { 45 TEST(PlatformFontWinTest, DeriveFontWithHeight) {
46 // TODO(ananta): Fix this test for DirectWrite. http://crbug.com/442010
47 if (gfx::win::IsDirectWriteEnabled())
48 return;
49
50 const Font base_font; 46 const Font base_font;
51 PlatformFontWin* platform_font = 47 PlatformFontWin* platform_font =
52 static_cast<PlatformFontWin*>(base_font.platform_font()); 48 static_cast<PlatformFontWin*>(base_font.platform_font());
53 49
54 for (int i = -10; i < 10; i++) { 50 for (int i = -10; i < 10; i++) {
55 const int target_height = base_font.GetHeight() + i; 51 const int target_height = base_font.GetHeight() + i;
56 Font expected_font = AdjustFontSizeForHeight(base_font, target_height); 52 Font expected_font = AdjustFontSizeForHeight(base_font, target_height);
57 ASSERT_LE(expected_font.GetHeight(), target_height); 53 ASSERT_LE(expected_font.GetHeight(), target_height);
58 54 // 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
59 Font derived_font = platform_font->DeriveFontWithHeight(target_height, 0); 55 // lesser or greater by 1 px from the desired height due to vagaries in the
56 // metrics calculation.
57 // The AdjustFontSizeForHeight function and the DeriveFontWithHeight
58 // function don't work the same way and thus we end up with mismatched
59 // fonts with DirectWrite. To workaround this we use the expected fonts
60 // height for the tests below.
61 Font derived_font = platform_font->DeriveFontWithHeight(
62 expected_font.GetHeight(), 0);
60 EXPECT_EQ(expected_font.GetFontName(), derived_font.GetFontName()); 63 EXPECT_EQ(expected_font.GetFontName(), derived_font.GetFontName());
61 EXPECT_EQ(expected_font.GetFontSize(), derived_font.GetFontSize()); 64 // Wierdly enough for some font heights like 24 and above when the font is
65 // created via CreateFontIndirect and we get the metrics for the same, the
66 // height returned by the GetTextMetric API is 23. This causes the derived
67 // fonts size to be off by 1 px from the expected font size. We only see
68 // this with DirectWrite because with GDI the AdjustFontSizeForHeight
69 // function returns a font with height 23 and everything works well.
70 EXPECT_LE(abs(expected_font.GetFontSize() - derived_font.GetFontSize()),
71 1);
62 EXPECT_LE(expected_font.GetHeight(), target_height); 72 EXPECT_LE(expected_font.GetHeight(), target_height);
63 EXPECT_EQ(0, derived_font.GetStyle()); 73 EXPECT_EQ(0, derived_font.GetStyle());
64 74
65 derived_font = platform_font->DeriveFontWithHeight(target_height, 75 derived_font = platform_font->DeriveFontWithHeight(
66 Font::BOLD); 76 expected_font.GetHeight(), Font::BOLD);
67 EXPECT_EQ(expected_font.GetFontName(), derived_font.GetFontName()); 77 EXPECT_EQ(expected_font.GetFontName(), derived_font.GetFontName());
68 EXPECT_EQ(expected_font.GetFontSize(), derived_font.GetFontSize()); 78 // Please refer to the comment above as to why this check is needed.
79 EXPECT_LE(abs(expected_font.GetFontSize() - derived_font.GetFontSize()),
80 1);
69 EXPECT_LE(expected_font.GetHeight(), target_height); 81 EXPECT_LE(expected_font.GetHeight(), target_height);
70 EXPECT_EQ(Font::BOLD, derived_font.GetStyle()); 82 EXPECT_EQ(Font::BOLD, derived_font.GetStyle());
71 83
72 // Test that deriving from the new font has the expected result. 84 // Test that deriving from the new font has the expected result.
73 Font rederived_font = derived_font.Derive(1, 0); 85 Font rederived_font = derived_font.Derive(1, 0);
74 expected_font = Font(derived_font.GetFontName(), 86 expected_font = Font(derived_font.GetFontName(),
75 derived_font.GetFontSize() + 1); 87 derived_font.GetFontSize() + 1);
76 EXPECT_EQ(expected_font.GetFontName(), rederived_font.GetFontName()); 88 EXPECT_EQ(expected_font.GetFontName(), rederived_font.GetFontName());
77 EXPECT_EQ(expected_font.GetFontSize(), rederived_font.GetFontSize()); 89 EXPECT_EQ(expected_font.GetFontSize(), rederived_font.GetFontSize());
78 EXPECT_EQ(expected_font.GetHeight(), rederived_font.GetHeight()); 90 EXPECT_EQ(expected_font.GetHeight(), rederived_font.GetHeight());
79 } 91 }
80 } 92 }
81 93
82 TEST(PlatformFontWinTest, DeriveFontWithHeight_Consistency) { 94 TEST(PlatformFontWinTest, DeriveFontWithHeight_Consistency) {
83 // TODO(ananta): Fix this test for DirectWrite. http://crbug.com/442010
84 if (gfx::win::IsDirectWriteEnabled())
85 return;
86 gfx::Font arial_12("Arial", 12); 95 gfx::Font arial_12("Arial", 12);
87 ASSERT_GT(16, arial_12.GetHeight()); 96 ASSERT_GT(16, arial_12.GetHeight());
88 gfx::Font derived_1 = static_cast<PlatformFontWin*>( 97 gfx::Font derived_1 = static_cast<PlatformFontWin*>(
89 arial_12.platform_font())->DeriveFontWithHeight(16, 0); 98 arial_12.platform_font())->DeriveFontWithHeight(16, 0);
90 99
91 gfx::Font arial_15("Arial", 15); 100 gfx::Font arial_15("Arial", 15);
92 ASSERT_LT(16, arial_15.GetHeight()); 101 ASSERT_LT(16, arial_15.GetHeight());
93 gfx::Font derived_2 = static_cast<PlatformFontWin*>( 102 gfx::Font derived_2 = static_cast<PlatformFontWin*>(
94 arial_15.platform_font())->DeriveFontWithHeight(16, 0); 103 arial_15.platform_font())->DeriveFontWithHeight(16, 0);
95 104
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 EXPECT_EQ(h_font_gdi->font_name(), h_font_skia->font_name()); 201 EXPECT_EQ(h_font_gdi->font_name(), h_font_skia->font_name());
193 202
194 EXPECT_LE(abs(h_font_gdi->cap_height() - h_font_skia->cap_height()), 1); 203 EXPECT_LE(abs(h_font_gdi->cap_height() - h_font_skia->cap_height()), 1);
195 EXPECT_LE(abs(h_font_gdi->baseline() - h_font_skia->baseline()), 1); 204 EXPECT_LE(abs(h_font_gdi->baseline() - h_font_skia->baseline()), 1);
196 EXPECT_LE(abs(h_font_gdi->height() - h_font_skia->height()), 1); 205 EXPECT_LE(abs(h_font_gdi->height() - h_font_skia->height()), 1);
197 } 206 }
198 } 207 }
199 208
200 209
201 } // namespace gfx 210 } // namespace gfx
OLDNEW
« ui/gfx/font_list_unittest.cc ('K') | « ui/gfx/platform_font_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698