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