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 "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" |
11 #include "base/win/scoped_hdc.h" | 11 #include "base/win/scoped_hdc.h" |
12 #include "base/win/scoped_select_object.h" | 12 #include "base/win/scoped_select_object.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "ui/gfx/font.h" | 14 #include "ui/gfx/font.h" |
15 #include "ui/gfx/win/direct_write.h" | 15 #include "ui/gfx/win/direct_write.h" |
16 #include "ui/gfx/win/scoped_set_map_mode.h" | 16 #include "ui/gfx/win/scoped_set_map_mode.h" |
17 | 17 |
18 namespace gfx { | 18 namespace gfx { |
19 | 19 |
20 TEST(PlatformFontWinTest, DeriveFontWithHeight) { | 20 TEST(PlatformFontWinTest, DeriveFontWithHeight) { |
21 const Font base_font; | 21 const Font base_font; |
22 PlatformFontWin* platform_font = | 22 PlatformFontWin* platform_font = |
23 static_cast<PlatformFontWin*>(base_font.platform_font()); | 23 static_cast<PlatformFontWin*>(base_font.platform_font()); |
24 | 24 |
25 for (int i = -10; i < 10; i++) { | 25 for (int i = -10; i < 10; i++) { |
26 const int target_height = base_font.GetHeight() + i; | 26 const int target_height = base_font.GetHeight() + i; |
27 | 27 |
28 Font derived_font = platform_font->DeriveFontWithHeight(target_height, 0); | 28 Font derived_font = platform_font->DeriveFontWithHeight( |
msw
2016/03/22 18:24:11
Remove tests of (or references to) the deleted Der
| |
29 target_height, 0, gfx::Font::WEIGHT_NORMAL); | |
29 EXPECT_LE(derived_font.GetHeight(), target_height); | 30 EXPECT_LE(derived_font.GetHeight(), target_height); |
30 EXPECT_GT(derived_font.Derive(1, 0).GetHeight(), target_height); | 31 EXPECT_GT(derived_font.Derive(1, 0, gfx::Font::WEIGHT_NORMAL).GetHeight(), |
32 target_height); | |
31 EXPECT_EQ(platform_font->GetActualFontNameForTesting(), | 33 EXPECT_EQ(platform_font->GetActualFontNameForTesting(), |
32 derived_font.GetActualFontNameForTesting()); | 34 derived_font.GetActualFontNameForTesting()); |
33 EXPECT_EQ(0, derived_font.GetStyle()); | 35 EXPECT_EQ(0, derived_font.GetStyle()); |
34 | 36 |
35 derived_font = platform_font->DeriveFontWithHeight(target_height, | 37 derived_font = platform_font->DeriveFontWithHeight(target_height, 0, |
36 Font::BOLD); | 38 gfx::Font::WEIGHT_BOLD); |
37 EXPECT_LE(derived_font.GetHeight(), target_height); | 39 EXPECT_LE(derived_font.GetHeight(), target_height); |
38 EXPECT_GT(derived_font.Derive(1, 0).GetHeight(), target_height); | 40 EXPECT_GT(derived_font.Derive(1, 0, gfx::Font::WEIGHT_NORMAL).GetHeight(), |
41 target_height); | |
39 EXPECT_EQ(platform_font->GetActualFontNameForTesting(), | 42 EXPECT_EQ(platform_font->GetActualFontNameForTesting(), |
40 derived_font.GetActualFontNameForTesting()); | 43 derived_font.GetActualFontNameForTesting()); |
41 EXPECT_EQ(Font::BOLD, derived_font.GetStyle()); | 44 EXPECT_EQ(Font::WEIGHT_BOLD, derived_font.GetWeight()); |
42 } | 45 } |
43 } | 46 } |
44 | 47 |
45 TEST(PlatformFontWinTest, DeriveFontWithHeight_Consistency) { | 48 TEST(PlatformFontWinTest, DeriveFontWithHeight_Consistency) { |
46 gfx::Font arial_12("Arial", 12); | 49 gfx::Font arial_12("Arial", 12); |
47 ASSERT_GT(16, arial_12.GetHeight()); | 50 ASSERT_GT(16, arial_12.GetHeight()); |
48 gfx::Font derived_1 = static_cast<PlatformFontWin*>( | 51 gfx::Font derived_1 = |
49 arial_12.platform_font())->DeriveFontWithHeight(16, 0); | 52 static_cast<PlatformFontWin*>(arial_12.platform_font()) |
53 ->DeriveFontWithHeight(16, 0, gfx::Font::WEIGHT_NORMAL); | |
50 | 54 |
51 gfx::Font arial_15("Arial", 15); | 55 gfx::Font arial_15("Arial", 15); |
52 ASSERT_LT(16, arial_15.GetHeight()); | 56 ASSERT_LT(16, arial_15.GetHeight()); |
53 gfx::Font derived_2 = static_cast<PlatformFontWin*>( | 57 gfx::Font derived_2 = |
54 arial_15.platform_font())->DeriveFontWithHeight(16, 0); | 58 static_cast<PlatformFontWin*>(arial_15.platform_font()) |
59 ->DeriveFontWithHeight(16, 0, gfx::Font::WEIGHT_NORMAL); | |
55 | 60 |
56 EXPECT_EQ(derived_1.GetFontSize(), derived_2.GetFontSize()); | 61 EXPECT_EQ(derived_1.GetFontSize(), derived_2.GetFontSize()); |
57 EXPECT_EQ(16, derived_1.GetHeight()); | 62 EXPECT_EQ(16, derived_1.GetHeight()); |
58 EXPECT_EQ(16, derived_2.GetHeight()); | 63 EXPECT_EQ(16, derived_2.GetHeight()); |
59 } | 64 } |
60 | 65 |
61 // Callback function used by DeriveFontWithHeight_MinSize() below. | 66 // Callback function used by DeriveFontWithHeight_MinSize() below. |
62 static int GetMinFontSize() { | 67 static int GetMinFontSize() { |
63 return 10; | 68 return 10; |
64 } | 69 } |
65 | 70 |
66 TEST(PlatformFontWinTest, DeriveFontWithHeight_MinSize) { | 71 TEST(PlatformFontWinTest, DeriveFontWithHeight_MinSize) { |
67 PlatformFontWin::GetMinimumFontSizeCallback old_callback = | 72 PlatformFontWin::GetMinimumFontSizeCallback old_callback = |
68 PlatformFontWin::get_minimum_font_size_callback; | 73 PlatformFontWin::get_minimum_font_size_callback; |
69 PlatformFontWin::get_minimum_font_size_callback = &GetMinFontSize; | 74 PlatformFontWin::get_minimum_font_size_callback = &GetMinFontSize; |
70 | 75 |
71 const Font base_font; | 76 const Font base_font; |
72 const Font min_font(base_font.GetFontName(), GetMinFontSize()); | 77 const Font min_font(base_font.GetFontName(), GetMinFontSize()); |
73 PlatformFontWin* platform_font = | 78 PlatformFontWin* platform_font = |
74 static_cast<PlatformFontWin*>(base_font.platform_font()); | 79 static_cast<PlatformFontWin*>(base_font.platform_font()); |
75 | 80 |
76 const Font derived_font = | 81 const Font derived_font = platform_font->DeriveFontWithHeight( |
77 platform_font->DeriveFontWithHeight(min_font.GetHeight() - 1, 0); | 82 min_font.GetHeight() - 1, 0, gfx::Font::WEIGHT_NORMAL); |
78 EXPECT_EQ(min_font.GetFontSize(), derived_font.GetFontSize()); | 83 EXPECT_EQ(min_font.GetFontSize(), derived_font.GetFontSize()); |
79 EXPECT_EQ(min_font.GetHeight(), derived_font.GetHeight()); | 84 EXPECT_EQ(min_font.GetHeight(), derived_font.GetHeight()); |
80 | 85 |
81 PlatformFontWin::get_minimum_font_size_callback = old_callback; | 86 PlatformFontWin::get_minimum_font_size_callback = old_callback; |
82 } | 87 } |
83 | 88 |
84 TEST(PlatformFontWinTest, DeriveFontWithHeight_TooSmall) { | 89 TEST(PlatformFontWinTest, DeriveFontWithHeight_TooSmall) { |
85 const Font base_font; | 90 const Font base_font; |
86 PlatformFontWin* platform_font = | 91 PlatformFontWin* platform_font = |
87 static_cast<PlatformFontWin*>(base_font.platform_font()); | 92 static_cast<PlatformFontWin*>(base_font.platform_font()); |
88 | 93 |
89 const Font derived_font = platform_font->DeriveFontWithHeight(1, 0); | 94 const Font derived_font = |
95 platform_font->DeriveFontWithHeight(1, 0, gfx::Font::WEIGHT_NORMAL); | |
90 EXPECT_GT(derived_font.GetHeight(), 1); | 96 EXPECT_GT(derived_font.GetHeight(), 1); |
91 } | 97 } |
92 | 98 |
93 // Test whether font metrics retrieved by DirectWrite (skia) and GDI match as | 99 // Test whether font metrics retrieved by DirectWrite (skia) and GDI match as |
94 // per assumptions mentioned below:- | 100 // per assumptions mentioned below:- |
95 // 1. Font size is the same | 101 // 1. Font size is the same |
96 // 2. The difference between GDI and DirectWrite for font height, baseline, | 102 // 2. The difference between GDI and DirectWrite for font height, baseline, |
97 // and cap height is at most 1. For smaller font sizes under 12, GDI | 103 // and cap height is at most 1. For smaller font sizes under 12, GDI |
98 // font heights/baselines/cap height are equal/larger by 1 point. For larger | 104 // font heights/baselines/cap height are equal/larger by 1 point. For larger |
99 // font sizes DirectWrite font heights/baselines/cap height are equal/larger | 105 // font sizes DirectWrite font heights/baselines/cap height are equal/larger |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 PlatformFontWin::GetTextMetricsForFont(screen_dc, hFont, &font_metrics); | 204 PlatformFontWin::GetTextMetricsForFont(screen_dc, hFont, &font_metrics); |
199 | 205 |
200 scoped_refptr<PlatformFontWin::HFontRef> h_font_skia( | 206 scoped_refptr<PlatformFontWin::HFontRef> h_font_skia( |
201 PlatformFontWin::CreateHFontRefFromSkia(hFont, font_metrics)); | 207 PlatformFontWin::CreateHFontRefFromSkia(hFont, font_metrics)); |
202 | 208 |
203 EXPECT_EQ(font.expected_font_name, h_font_skia->font_name()); | 209 EXPECT_EQ(font.expected_font_name, h_font_skia->font_name()); |
204 } | 210 } |
205 } | 211 } |
206 | 212 |
207 } // namespace gfx | 213 } // namespace gfx |
OLD | NEW |