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

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

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Alexei's issues Created 4 years, 8 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
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_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
37 std::string* family_out, 39 void GetDefaultFontDescription(std::string* family_out,
38 int* size_pixels_out, 40 int* size_pixels_out,
39 int* style_out, 41 bool* italic_out,
40 FontRenderParams* params_out) const override { 42 Font::Weight* weight_out,
43 FontRenderParams* params_out) const override {
41 *family_out = family_; 44 *family_out = family_;
42 *size_pixels_out = size_pixels_; 45 *size_pixels_out = size_pixels_;
43 *style_out = style_; 46 *italic_out = italic_;
47 *weight_out = weight_;
44 *params_out = params_; 48 *params_out = params_;
45 } 49 }
46 50
47 private: 51 private:
48 // Default values to be returned. 52 // Default values to be returned.
49 std::string family_; 53 std::string family_;
50 int size_pixels_; 54 int size_pixels_;
51 int style_; 55 bool italic_;
56 gfx::Font::Weight weight_;
Alexei Svitkine (slow) 2016/04/05 16:38:52 Remove gfx::
52 FontRenderParams params_; 57 FontRenderParams params_;
53 58
54 DISALLOW_COPY_AND_ASSIGN(TestFontDelegate); 59 DISALLOW_COPY_AND_ASSIGN(TestFontDelegate);
55 }; 60 };
56 61
57 class PlatformFontLinuxTest : public testing::Test { 62 class PlatformFontLinuxTest : public testing::Test {
58 public: 63 public:
59 PlatformFontLinuxTest() { 64 PlatformFontLinuxTest() {
60 SetUpFontconfig(); 65 SetUpFontconfig();
61 original_font_delegate_ = LinuxFontDelegate::instance(); 66 original_font_delegate_ = LinuxFontDelegate::instance();
(...skipping 20 matching lines...) Expand all
82 // with the correct parameters. 87 // with the correct parameters.
83 TEST_F(PlatformFontLinuxTest, DefaultFont) { 88 TEST_F(PlatformFontLinuxTest, DefaultFont) {
84 ASSERT_TRUE(LoadSystemFontIntoFontconfig("arial.ttf")); 89 ASSERT_TRUE(LoadSystemFontIntoFontconfig("arial.ttf"));
85 ASSERT_TRUE(LoadSystemFontIntoFontconfig("times_new_roman.ttf")); 90 ASSERT_TRUE(LoadSystemFontIntoFontconfig("times_new_roman.ttf"));
86 91
87 #if defined(OS_CHROMEOS) 92 #if defined(OS_CHROMEOS)
88 PlatformFontLinux::SetDefaultFontDescription("Arial,Times New Roman,13px"); 93 PlatformFontLinux::SetDefaultFontDescription("Arial,Times New Roman,13px");
89 #else 94 #else
90 test_font_delegate_.set_family("Arial"); 95 test_font_delegate_.set_family("Arial");
91 test_font_delegate_.set_size_pixels(13); 96 test_font_delegate_.set_size_pixels(13);
92 test_font_delegate_.set_style(gfx::Font::NORMAL); 97 test_font_delegate_.set_italic(false);
93 FontRenderParams params; 98 FontRenderParams params;
94 params.antialiasing = false; 99 params.antialiasing = false;
95 params.hinting = FontRenderParams::HINTING_FULL; 100 params.hinting = FontRenderParams::HINTING_FULL;
96 test_font_delegate_.set_params(params); 101 test_font_delegate_.set_params(params);
97 #endif 102 #endif
98 scoped_refptr<gfx::PlatformFontLinux> font(new gfx::PlatformFontLinux()); 103 scoped_refptr<gfx::PlatformFontLinux> font(new gfx::PlatformFontLinux());
99 EXPECT_EQ("Arial", font->GetFontName()); 104 EXPECT_EQ("Arial", font->GetFontName());
100 EXPECT_EQ(13, font->GetFontSize()); 105 EXPECT_EQ(13, font->GetFontSize());
101 EXPECT_EQ(gfx::Font::NORMAL, font->GetStyle()); 106 EXPECT_EQ(gfx::Font::NORMAL, font->GetStyle());
102 #if !defined(OS_CHROMEOS) 107 #if !defined(OS_CHROMEOS)
103 // 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.
104 EXPECT_EQ(params.antialiasing, font->GetFontRenderParams().antialiasing); 109 EXPECT_EQ(params.antialiasing, font->GetFontRenderParams().antialiasing);
105 EXPECT_EQ(params.hinting, font->GetFontRenderParams().hinting); 110 EXPECT_EQ(params.hinting, font->GetFontRenderParams().hinting);
106 #endif 111 #endif
107 112
108 // 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.
109 #if defined(OS_CHROMEOS) 114 #if defined(OS_CHROMEOS)
110 PlatformFontLinux::SetDefaultFontDescription( 115 PlatformFontLinux::SetDefaultFontDescription(
111 "Times New Roman,Arial,Bold 15px"); 116 "Times New Roman,Arial,Bold 15px");
112 #else 117 #else
113 test_font_delegate_.set_family("Times New Roman"); 118 test_font_delegate_.set_family("Times New Roman");
114 test_font_delegate_.set_size_pixels(15); 119 test_font_delegate_.set_size_pixels(15);
115 test_font_delegate_.set_style(gfx::Font::BOLD); 120 test_font_delegate_.set_italic(true);
121 test_font_delegate_.set_weight(gfx::Font::Weight::BOLD);
116 #endif 122 #endif
117 PlatformFontLinux::ReloadDefaultFont(); 123 PlatformFontLinux::ReloadDefaultFont();
118 scoped_refptr<gfx::PlatformFontLinux> font2(new gfx::PlatformFontLinux()); 124 scoped_refptr<gfx::PlatformFontLinux> font2(new gfx::PlatformFontLinux());
119 EXPECT_EQ("Times New Roman", font2->GetFontName()); 125 EXPECT_EQ("Times New Roman", font2->GetFontName());
120 EXPECT_EQ(15, font2->GetFontSize()); 126 EXPECT_EQ(15, font2->GetFontSize());
121 EXPECT_EQ(gfx::Font::BOLD, font2->GetStyle()); 127 EXPECT_NE(font2->GetStyle() & Font::ITALIC, 0);
128 EXPECT_EQ(gfx::Font::Weight::BOLD, font2->GetWeight());
122 } 129 }
123 130
124 } // namespace gfx 131 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698