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_linux.h" | 5 #include "ui/gfx/platform_font_linux.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/gfx/font.h" | 13 #include "ui/gfx/font.h" |
14 #include "ui/gfx/font_render_params.h" | 14 #include "ui/gfx/font_render_params.h" |
15 #include "ui/gfx/linux_font_delegate.h" | 15 #include "ui/gfx/linux_font_delegate.h" |
16 #include "ui/gfx/test/fontconfig_util_linux.h" | 16 #include "ui/gfx/test/fontconfig_util_linux.h" |
17 | 17 |
18 namespace gfx { | 18 namespace gfx { |
19 | 19 |
20 // Implementation of LinuxFontDelegate used to control the default font | 20 // Implementation of LinuxFontDelegate used to control the default font |
21 // description on Linux. | 21 // description on Linux. |
22 class TestFontDelegate : public LinuxFontDelegate { | 22 class TestFontDelegate : public LinuxFontDelegate { |
23 public: | 23 public: |
24 TestFontDelegate() | 24 TestFontDelegate() |
25 : size_pixels_(0), italic_(false), weight_(Font::Weight::NORMAL) {} | 25 : size_pixels_(0), style_(Font::NORMAL), weight_(Font::Weight::NORMAL) {} |
26 ~TestFontDelegate() override {} | 26 ~TestFontDelegate() override {} |
27 | 27 |
28 void set_family(const std::string& family) { family_ = family; } | 28 void set_family(const std::string& family) { family_ = family; } |
29 void set_size_pixels(int size_pixels) { size_pixels_ = size_pixels; } | 29 void set_size_pixels(int size_pixels) { size_pixels_ = size_pixels; } |
30 void set_italic(int italic) { italic_ = italic; } | 30 void set_style(int style) { style_ = style; } |
31 void set_weight(gfx::Font::Weight weight) { weight_ = weight; } | 31 void set_weight(gfx::Font::Weight weight) { weight_ = weight; } |
32 void set_params(const FontRenderParams& params) { params_ = params; } | 32 void set_params(const FontRenderParams& params) { params_ = params; } |
33 | 33 |
34 FontRenderParams GetDefaultFontRenderParams() const override { | 34 FontRenderParams GetDefaultFontRenderParams() const override { |
35 NOTIMPLEMENTED(); | 35 NOTIMPLEMENTED(); |
36 return FontRenderParams(); | 36 return FontRenderParams(); |
37 } | 37 } |
38 | 38 |
39 void GetDefaultFontDescription(std::string* family_out, | 39 void GetDefaultFontDescription(std::string* family_out, |
40 int* size_pixels_out, | 40 int* size_pixels_out, |
41 bool* italic_out, | 41 int* style_out, |
42 Font::Weight* weight_out, | 42 Font::Weight* weight_out, |
43 FontRenderParams* params_out) const override { | 43 FontRenderParams* params_out) const override { |
44 *family_out = family_; | 44 *family_out = family_; |
45 *size_pixels_out = size_pixels_; | 45 *size_pixels_out = size_pixels_; |
46 *italic_out = italic_; | 46 *style_out = style_; |
47 *weight_out = weight_; | 47 *weight_out = weight_; |
48 *params_out = params_; | 48 *params_out = params_; |
49 } | 49 } |
50 | 50 |
51 private: | 51 private: |
52 // Default values to be returned. | 52 // Default values to be returned. |
53 std::string family_; | 53 std::string family_; |
54 int size_pixels_; | 54 int size_pixels_; |
55 bool italic_; | 55 int style_; |
56 gfx::Font::Weight weight_; | 56 gfx::Font::Weight weight_; |
57 FontRenderParams params_; | 57 FontRenderParams params_; |
58 | 58 |
59 DISALLOW_COPY_AND_ASSIGN(TestFontDelegate); | 59 DISALLOW_COPY_AND_ASSIGN(TestFontDelegate); |
60 }; | 60 }; |
61 | 61 |
62 class PlatformFontLinuxTest : public testing::Test { | 62 class PlatformFontLinuxTest : public testing::Test { |
63 public: | 63 public: |
64 PlatformFontLinuxTest() { | 64 PlatformFontLinuxTest() { |
65 SetUpFontconfig(); | 65 SetUpFontconfig(); |
(...skipping 21 matching lines...) Expand all Loading... |
87 // with the correct parameters. | 87 // with the correct parameters. |
88 TEST_F(PlatformFontLinuxTest, DefaultFont) { | 88 TEST_F(PlatformFontLinuxTest, DefaultFont) { |
89 ASSERT_TRUE(LoadSystemFontIntoFontconfig("arial.ttf")); | 89 ASSERT_TRUE(LoadSystemFontIntoFontconfig("arial.ttf")); |
90 ASSERT_TRUE(LoadSystemFontIntoFontconfig("times_new_roman.ttf")); | 90 ASSERT_TRUE(LoadSystemFontIntoFontconfig("times_new_roman.ttf")); |
91 | 91 |
92 #if defined(OS_CHROMEOS) | 92 #if defined(OS_CHROMEOS) |
93 PlatformFontLinux::SetDefaultFontDescription("Arial,Times New Roman,13px"); | 93 PlatformFontLinux::SetDefaultFontDescription("Arial,Times New Roman,13px"); |
94 #else | 94 #else |
95 test_font_delegate_.set_family("Arial"); | 95 test_font_delegate_.set_family("Arial"); |
96 test_font_delegate_.set_size_pixels(13); | 96 test_font_delegate_.set_size_pixels(13); |
97 test_font_delegate_.set_italic(false); | 97 test_font_delegate_.set_style(Font::NORMAL); |
98 FontRenderParams params; | 98 FontRenderParams params; |
99 params.antialiasing = false; | 99 params.antialiasing = false; |
100 params.hinting = FontRenderParams::HINTING_FULL; | 100 params.hinting = FontRenderParams::HINTING_FULL; |
101 test_font_delegate_.set_params(params); | 101 test_font_delegate_.set_params(params); |
102 #endif | 102 #endif |
103 scoped_refptr<gfx::PlatformFontLinux> font(new gfx::PlatformFontLinux()); | 103 scoped_refptr<gfx::PlatformFontLinux> font(new gfx::PlatformFontLinux()); |
104 EXPECT_EQ("Arial", font->GetFontName()); | 104 EXPECT_EQ("Arial", font->GetFontName()); |
105 EXPECT_EQ(13, font->GetFontSize()); | 105 EXPECT_EQ(13, font->GetFontSize()); |
106 EXPECT_EQ(gfx::Font::NORMAL, font->GetStyle()); | 106 EXPECT_EQ(gfx::Font::NORMAL, font->GetStyle()); |
107 #if !defined(OS_CHROMEOS) | 107 #if !defined(OS_CHROMEOS) |
108 // On Linux, the FontRenderParams returned by the the delegate should be used. | 108 // On Linux, the FontRenderParams returned by the the delegate should be used. |
109 EXPECT_EQ(params.antialiasing, font->GetFontRenderParams().antialiasing); | 109 EXPECT_EQ(params.antialiasing, font->GetFontRenderParams().antialiasing); |
110 EXPECT_EQ(params.hinting, font->GetFontRenderParams().hinting); | 110 EXPECT_EQ(params.hinting, font->GetFontRenderParams().hinting); |
111 #endif | 111 #endif |
112 | 112 |
113 // Drop the old default font and check that new settings are loaded. | 113 // Drop the old default font and check that new settings are loaded. |
114 #if defined(OS_CHROMEOS) | 114 #if defined(OS_CHROMEOS) |
115 PlatformFontLinux::SetDefaultFontDescription( | 115 PlatformFontLinux::SetDefaultFontDescription( |
116 "Times New Roman,Arial,Bold Italic 15px"); | 116 "Times New Roman,Arial,Bold Italic 15px"); |
117 #else | 117 #else |
118 test_font_delegate_.set_family("Times New Roman"); | 118 test_font_delegate_.set_family("Times New Roman"); |
119 test_font_delegate_.set_size_pixels(15); | 119 test_font_delegate_.set_size_pixels(15); |
120 test_font_delegate_.set_italic(true); | 120 test_font_delegate_.set_style(gfx::Font::ITALIC); |
121 test_font_delegate_.set_weight(gfx::Font::Weight::BOLD); | 121 test_font_delegate_.set_weight(gfx::Font::Weight::BOLD); |
122 #endif | 122 #endif |
123 PlatformFontLinux::ReloadDefaultFont(); | 123 PlatformFontLinux::ReloadDefaultFont(); |
124 scoped_refptr<gfx::PlatformFontLinux> font2(new gfx::PlatformFontLinux()); | 124 scoped_refptr<gfx::PlatformFontLinux> font2(new gfx::PlatformFontLinux()); |
125 EXPECT_EQ("Times New Roman", font2->GetFontName()); | 125 EXPECT_EQ("Times New Roman", font2->GetFontName()); |
126 EXPECT_EQ(15, font2->GetFontSize()); | 126 EXPECT_EQ(15, font2->GetFontSize()); |
127 EXPECT_NE(font2->GetStyle() & Font::ITALIC, 0); | 127 EXPECT_NE(font2->GetStyle() & Font::ITALIC, 0); |
128 EXPECT_EQ(gfx::Font::Weight::BOLD, font2->GetWeight()); | 128 EXPECT_EQ(gfx::Font::Weight::BOLD, font2->GetWeight()); |
129 } | 129 } |
130 | 130 |
131 } // namespace gfx | 131 } // namespace gfx |
OLD | NEW |