OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "gfx/font.h" | 5 #include "gfx/font.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
9 #include "gfx/platform_font_win.h" | 9 #include "gfx/platform_font_win.h" |
10 #endif // defined(OS_WIN) | 10 #endif // defined(OS_WIN) |
(...skipping 28 matching lines...) Expand all Loading... |
39 static int minimum_size_; | 39 static int minimum_size_; |
40 | 40 |
41 DISALLOW_COPY_AND_ASSIGN(ScopedMinimumFontSizeCallback); | 41 DISALLOW_COPY_AND_ASSIGN(ScopedMinimumFontSizeCallback); |
42 }; | 42 }; |
43 | 43 |
44 int ScopedMinimumFontSizeCallback::minimum_size_ = 0; | 44 int ScopedMinimumFontSizeCallback::minimum_size_ = 0; |
45 #endif // defined(OS_WIN) | 45 #endif // defined(OS_WIN) |
46 | 46 |
47 | 47 |
48 TEST_F(FontTest, LoadArial) { | 48 TEST_F(FontTest, LoadArial) { |
49 Font cf(L"Arial", 16); | 49 Font cf(ASCIIToUTF16("Arial"), 16); |
50 ASSERT_TRUE(cf.GetNativeFont()); | 50 ASSERT_TRUE(cf.GetNativeFont()); |
51 ASSERT_EQ(cf.GetStyle(), Font::NORMAL); | 51 ASSERT_EQ(cf.GetStyle(), Font::NORMAL); |
52 ASSERT_EQ(cf.GetFontSize(), 16); | 52 ASSERT_EQ(cf.GetFontSize(), 16); |
53 ASSERT_EQ(cf.GetFontName(), L"Arial"); | 53 ASSERT_EQ(cf.GetFontName(), ASCIIToUTF16("Arial")); |
54 } | 54 } |
55 | 55 |
56 TEST_F(FontTest, LoadArialBold) { | 56 TEST_F(FontTest, LoadArialBold) { |
57 Font cf(L"Arial", 16); | 57 Font cf(ASCIIToUTF16("Arial"), 16); |
58 Font bold(cf.DeriveFont(0, Font::BOLD)); | 58 Font bold(cf.DeriveFont(0, Font::BOLD)); |
59 ASSERT_TRUE(bold.GetNativeFont()); | 59 ASSERT_TRUE(bold.GetNativeFont()); |
60 ASSERT_EQ(bold.GetStyle(), Font::BOLD); | 60 ASSERT_EQ(bold.GetStyle(), Font::BOLD); |
61 } | 61 } |
62 | 62 |
63 TEST_F(FontTest, Ascent) { | 63 TEST_F(FontTest, Ascent) { |
64 Font cf(L"Arial", 16); | 64 Font cf(ASCIIToUTF16("Arial"), 16); |
65 ASSERT_GT(cf.GetBaseline(), 2); | 65 ASSERT_GT(cf.GetBaseline(), 2); |
66 ASSERT_LE(cf.GetBaseline(), 22); | 66 ASSERT_LE(cf.GetBaseline(), 22); |
67 } | 67 } |
68 | 68 |
69 TEST_F(FontTest, Height) { | 69 TEST_F(FontTest, Height) { |
70 Font cf(L"Arial", 16); | 70 Font cf(ASCIIToUTF16("Arial"), 16); |
71 ASSERT_GE(cf.GetHeight(), 16); | 71 ASSERT_GE(cf.GetHeight(), 16); |
72 // TODO(akalin): Figure out why height is so large on Linux. | 72 // TODO(akalin): Figure out why height is so large on Linux. |
73 ASSERT_LE(cf.GetHeight(), 26); | 73 ASSERT_LE(cf.GetHeight(), 26); |
74 } | 74 } |
75 | 75 |
76 TEST_F(FontTest, AvgWidths) { | 76 TEST_F(FontTest, AvgWidths) { |
77 Font cf(L"Arial", 16); | 77 Font cf(ASCIIToUTF16("Arial"), 16); |
78 ASSERT_EQ(cf.GetExpectedTextWidth(0), 0); | 78 ASSERT_EQ(cf.GetExpectedTextWidth(0), 0); |
79 ASSERT_GT(cf.GetExpectedTextWidth(1), cf.GetExpectedTextWidth(0)); | 79 ASSERT_GT(cf.GetExpectedTextWidth(1), cf.GetExpectedTextWidth(0)); |
80 ASSERT_GT(cf.GetExpectedTextWidth(2), cf.GetExpectedTextWidth(1)); | 80 ASSERT_GT(cf.GetExpectedTextWidth(2), cf.GetExpectedTextWidth(1)); |
81 ASSERT_GT(cf.GetExpectedTextWidth(3), cf.GetExpectedTextWidth(2)); | 81 ASSERT_GT(cf.GetExpectedTextWidth(3), cf.GetExpectedTextWidth(2)); |
82 } | 82 } |
83 | 83 |
84 TEST_F(FontTest, Widths) { | 84 TEST_F(FontTest, Widths) { |
85 Font cf(L"Arial", 16); | 85 Font cf(ASCIIToUTF16("Arial"), 16); |
86 ASSERT_EQ(cf.GetStringWidth(ASCIIToUTF16("")), 0); | 86 ASSERT_EQ(cf.GetStringWidth(ASCIIToUTF16("")), 0); |
87 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("a")), | 87 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("a")), |
88 cf.GetStringWidth(ASCIIToUTF16(""))); | 88 cf.GetStringWidth(ASCIIToUTF16(""))); |
89 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("ab")), | 89 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("ab")), |
90 cf.GetStringWidth(ASCIIToUTF16("a"))); | 90 cf.GetStringWidth(ASCIIToUTF16("a"))); |
91 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("abc")), | 91 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("abc")), |
92 cf.GetStringWidth(ASCIIToUTF16("ab"))); | 92 cf.GetStringWidth(ASCIIToUTF16("ab"))); |
93 } | 93 } |
94 | 94 |
95 #if defined(OS_WIN) | 95 #if defined(OS_WIN) |
(...skipping 15 matching lines...) Expand all Loading... |
111 // The minimum font size is set to 5 in browser_main.cc. | 111 // The minimum font size is set to 5 in browser_main.cc. |
112 ScopedMinimumFontSizeCallback minimum_size(5); | 112 ScopedMinimumFontSizeCallback minimum_size(5); |
113 | 113 |
114 Font derived_font = cf.DeriveFont(-2); | 114 Font derived_font = cf.DeriveFont(-2); |
115 LOGFONT font_info; | 115 LOGFONT font_info; |
116 GetObject(derived_font.GetNativeFont(), sizeof(LOGFONT), &font_info); | 116 GetObject(derived_font.GetNativeFont(), sizeof(LOGFONT), &font_info); |
117 EXPECT_EQ(-6, font_info.lfHeight); | 117 EXPECT_EQ(-6, font_info.lfHeight); |
118 } | 118 } |
119 #endif | 119 #endif |
120 } // namespace | 120 } // namespace |
OLD | NEW |