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

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

Issue 403923002: Make GetCustomFontRenderParams() pass font style. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove an extra assignment Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/font_render_params.h" 5 #include "ui/gfx/font_render_params.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/font.h"
12 #include "ui/gfx/test/fontconfig_util_linux.h" 13 #include "ui/gfx/test/fontconfig_util_linux.h"
13 14
14 namespace gfx { 15 namespace gfx {
15 16
16 namespace { 17 namespace {
17 18
18 // Loads the first system font defined by fontconfig_util_linux.h with a base 19 // Loads the first system font defined by fontconfig_util_linux.h with a base
19 // filename of |basename|. Case is ignored. 20 // filename of |basename|. Case is ignored.
20 bool LoadSystemFont(const std::string& basename) { 21 bool LoadSystemFont(const std::string& basename) {
21 for (size_t i = 0; i < kNumSystemFontsForFontconfig; ++i) { 22 for (size_t i = 0; i < kNumSystemFontsForFontconfig; ++i) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 EXPECT_TRUE(params.antialiasing); 66 EXPECT_TRUE(params.antialiasing);
66 EXPECT_FALSE(params.autohinter); 67 EXPECT_FALSE(params.autohinter);
67 EXPECT_TRUE(params.use_bitmaps); 68 EXPECT_TRUE(params.use_bitmaps);
68 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); 69 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting);
69 EXPECT_FALSE(params.subpixel_positioning); 70 EXPECT_FALSE(params.subpixel_positioning);
70 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, 71 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB,
71 params.subpixel_rendering); 72 params.subpixel_rendering);
72 } 73 }
73 74
74 TEST_F(FontRenderParamsTest, Size) { 75 TEST_F(FontRenderParamsTest, Size) {
75 // Fontconfig needs to know about at least one font to return a match.
76 ASSERT_TRUE(LoadSystemFont("arial.ttf")); 76 ASSERT_TRUE(LoadSystemFont("arial.ttf"));
77 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), 77 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(),
78 std::string(kFontconfigFileHeader) + 78 std::string(kFontconfigFileHeader) +
79 kFontconfigMatchHeader + 79 kFontconfigMatchHeader +
80 CreateFontconfigEditStanza("antialias", "bool", "true") + 80 CreateFontconfigEditStanza("antialias", "bool", "true") +
81 CreateFontconfigEditStanza("hinting", "bool", "true") + 81 CreateFontconfigEditStanza("hinting", "bool", "true") +
82 CreateFontconfigEditStanza("hintstyle", "const", "hintfull") + 82 CreateFontconfigEditStanza("hintstyle", "const", "hintfull") +
83 CreateFontconfigEditStanza("rgba", "const", "none") + 83 CreateFontconfigEditStanza("rgba", "const", "none") +
84 kFontconfigMatchFooter + 84 kFontconfigMatchFooter +
85 kFontconfigMatchHeader + 85 kFontconfigMatchHeader +
86 CreateFontconfigTestStanza("pixelsize", "less_eq", "double", "10") + 86 CreateFontconfigTestStanza("pixelsize", "less_eq", "double", "10") +
87 CreateFontconfigEditStanza("antialias", "bool", "false") + 87 CreateFontconfigEditStanza("antialias", "bool", "false") +
88 kFontconfigMatchFooter + 88 kFontconfigMatchFooter +
89 kFontconfigMatchHeader + 89 kFontconfigMatchHeader +
90 CreateFontconfigTestStanza("size", "more_eq", "double", "20") + 90 CreateFontconfigTestStanza("size", "more_eq", "double", "20") +
91 CreateFontconfigEditStanza("hintstyle", "const", "hintslight") + 91 CreateFontconfigEditStanza("hintstyle", "const", "hintslight") +
92 CreateFontconfigEditStanza("rgba", "const", "rgb") + 92 CreateFontconfigEditStanza("rgba", "const", "rgb") +
93 kFontconfigMatchFooter + 93 kFontconfigMatchFooter +
94 kFontconfigFileFooter)); 94 kFontconfigFileFooter));
95 95
96 // The defaults should be used when the supplied size isn't matched by the 96 // The defaults should be used when the supplied size isn't matched by the
97 // second or third blocks. 97 // second or third blocks.
98 int pixel_size = 12; 98 int pixel_size = 12;
99 FontRenderParams params = GetCustomFontRenderParams( 99 FontRenderParams params = GetCustomFontRenderParams(
100 false, NULL, &pixel_size, NULL, NULL); 100 false, NULL, &pixel_size, NULL, NULL, NULL);
101 EXPECT_TRUE(params.antialiasing); 101 EXPECT_TRUE(params.antialiasing);
102 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); 102 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting);
103 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, 103 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE,
104 params.subpixel_rendering); 104 params.subpixel_rendering);
105 105
106 pixel_size = 10; 106 pixel_size = 10;
107 params = GetCustomFontRenderParams(false, NULL, &pixel_size, NULL, NULL); 107 params = GetCustomFontRenderParams(
108 false, NULL, &pixel_size, NULL, NULL, NULL);
108 EXPECT_FALSE(params.antialiasing); 109 EXPECT_FALSE(params.antialiasing);
109 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); 110 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting);
110 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, 111 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE,
111 params.subpixel_rendering); 112 params.subpixel_rendering);
112 113
113 int point_size = 20; 114 int point_size = 20;
114 params = GetCustomFontRenderParams(false, NULL, NULL, &point_size, NULL); 115 params = GetCustomFontRenderParams(
116 false, NULL, NULL, &point_size, NULL, NULL);
115 EXPECT_TRUE(params.antialiasing); 117 EXPECT_TRUE(params.antialiasing);
116 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting); 118 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting);
117 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, 119 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB,
118 params.subpixel_rendering); 120 params.subpixel_rendering);
119 } 121 }
120 122
123 TEST_F(FontRenderParamsTest, Style) {
124 ASSERT_TRUE(LoadSystemFont("arial.ttf"));
125 // Load a config that disables antialiasing for bold text and disables
126 // hinting for italic text.
127 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(),
128 std::string(kFontconfigFileHeader) +
129 kFontconfigMatchHeader +
130 CreateFontconfigEditStanza("antialias", "bool", "true") +
131 CreateFontconfigEditStanza("hinting", "bool", "true") +
132 CreateFontconfigEditStanza("hintstyle", "const", "hintfull") +
133 kFontconfigMatchFooter +
134 kFontconfigMatchHeader +
135 CreateFontconfigTestStanza("weight", "eq", "const", "bold") +
136 CreateFontconfigEditStanza("antialias", "bool", "false") +
137 kFontconfigMatchFooter +
138 kFontconfigMatchHeader +
139 CreateFontconfigTestStanza("slant", "eq", "const", "italic") +
140 CreateFontconfigEditStanza("hinting", "bool", "false") +
141 kFontconfigMatchFooter +
142 kFontconfigFileFooter));
143
144 int style = Font::NORMAL;
145 FontRenderParams params = GetCustomFontRenderParams(
146 false, NULL, NULL, NULL, &style, NULL);
147 EXPECT_TRUE(params.antialiasing);
148 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting);
149
150 style = Font::BOLD;
151 params = GetCustomFontRenderParams(
152 false, NULL, NULL, NULL, &style, NULL);
153 EXPECT_FALSE(params.antialiasing);
154 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting);
155
156 style = Font::ITALIC;
157 params = GetCustomFontRenderParams(
158 false, NULL, NULL, NULL, &style, NULL);
159 EXPECT_TRUE(params.antialiasing);
160 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting);
161
162 style = Font::BOLD | Font::ITALIC;
163 params = GetCustomFontRenderParams(
164 false, NULL, NULL, NULL, &style, NULL);
165 EXPECT_FALSE(params.antialiasing);
166 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting);
167 }
168
121 } // namespace gfx 169 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698