1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/font_list.h"
#include <string>
#include <vector>
#include "testing/gtest/include/gtest/gtest.h"
namespace gfx {
typedef testing::Test FontListTest;
TEST_F(FontListTest, FontDescString_FromDescString) {
// Test init from font name style size string.
FontList font_list = FontList("Droid Sans serif, Sans serif, 10");
const std::string& font_str = font_list.GetFontDescriptionString();
EXPECT_EQ("Droid Sans serif, Sans serif, 10", font_str);
}
TEST_F(FontListTest, FontDescString_FromFont) {
// Test init from Font.
Font font("Arial", 8);
FontList font_list = FontList(font);
const std::string& font_str = font_list.GetFontDescriptionString();
EXPECT_EQ("Arial,8", font_str);
}
TEST_F(FontListTest, FontDescString_FromFontWithNonNormalStyle) {
// Test init from Font with non-normal style.
Font font("Arial", 8);
FontList font_list = FontList(font.DeriveFont(2, Font::BOLD));
const std::string& font_str = font_list.GetFontDescriptionString();
#if defined(OS_LINUX)
EXPECT_EQ("Arial,PANGO_WEIGHT_BOLD 10", font_str);
#else
EXPECT_EQ("Arial,10", font_str);
#endif
font_list = FontList(font.DeriveFont(-2, Font::ITALIC));
const std::string& font_str_1 = font_list.GetFontDescriptionString();
#if defined(OS_LINUX)
EXPECT_EQ("Arial,PANGO_STYLE_ITALIC 6", font_str_1);
#else
EXPECT_EQ("Arial,6", font_str_1);
#endif
}
TEST_F(FontListTest, FontDescString_FromFontVector) {
// Test init from Font vector.
Font font("Arial", 8);
Font font_1("Sans serif", 10);
std::vector<Font> fonts;
fonts.push_back(font.DeriveFont(0, Font::BOLD));
fonts.push_back(font_1.DeriveFont(-2, Font::BOLD));
FontList font_list = FontList(fonts);
const std::string& font_str = font_list.GetFontDescriptionString();
#if defined(OS_LINUX)
EXPECT_EQ("Arial,Sans serif,PANGO_WEIGHT_BOLD 8", font_str);
#else
EXPECT_EQ("Arial,Sans serif,8", font_str);
#endif
}
TEST_F(FontListTest, Fonts_FromDescString) {
// Test init from font name size string.
FontList font_list = FontList("serif,Sans serif, 10");
const std::vector<Font>& fonts = font_list.GetFonts();
EXPECT_EQ(2U, fonts.size());
EXPECT_EQ("serif", fonts[0].GetFontName());
EXPECT_EQ(10, fonts[0].GetFontSize());
EXPECT_EQ(Font::NORMAL, fonts[0].GetStyle());
EXPECT_EQ("Sans serif", fonts[1].GetFontName());
EXPECT_EQ(10, fonts[1].GetFontSize());
EXPECT_EQ(Font::NORMAL, fonts[1].GetStyle());
}
TEST_F(FontListTest, Fonts_FromDescStringInFlexibleFormat) {
// Test init from font name size string with flexible format.
FontList font_list = FontList(" serif , Sans serif , 10 ");
const std::vector<Font>& fonts = font_list.GetFonts();
EXPECT_EQ(2U, fonts.size());
EXPECT_EQ("serif", fonts[0].GetFontName());
EXPECT_EQ(10, fonts[0].GetFontSize());
EXPECT_EQ(Font::NORMAL, fonts[0].GetStyle());
EXPECT_EQ("Sans serif", fonts[1].GetFontName());
EXPECT_EQ(10, fonts[1].GetFontSize());
EXPECT_EQ(Font::NORMAL, fonts[1].GetStyle());
}
TEST_F(FontListTest, Fonts_FromDescStringWithStyleInFlexibleFormat) {
// Test init from font name style size string with flexible format.
FontList font_list = FontList(" serif , Sans serif , PANGO_WEIGHT_BOLD "
" PANGO_STYLE_ITALIC 10 ");
const std::vector<Font>& fonts = font_list.GetFonts();
EXPECT_EQ(2U, fonts.size());
EXPECT_EQ("serif", fonts[0].GetFontName());
EXPECT_EQ(10, fonts[0].GetFontSize());
#if defined(OS_LINUX)
EXPECT_EQ(Font::BOLD | Font::ITALIC, fonts[0].GetStyle());
#else
EXPECT_EQ(Font::NORMAL, fonts[0].GetStyle());
#endif
EXPECT_EQ("Sans serif", fonts[1].GetFontName());
EXPECT_EQ(10, fonts[1].GetFontSize());
#if defined(OS_LINUX)
EXPECT_EQ(Font::BOLD | Font::ITALIC, fonts[1].GetStyle());
#else
EXPECT_EQ(Font::NORMAL, fonts[1].GetStyle());
#endif
}
TEST_F(FontListTest, Fonts_FromFont) {
// Test init from Font.
Font font("Arial", 8);
FontList font_list = FontList(font);
const std::vector<Font>& fonts = font_list.GetFonts();
EXPECT_EQ(1U, fonts.size());
EXPECT_EQ("Arial", fonts[0].GetFontName());
EXPECT_EQ(8, fonts[0].GetFontSize());
EXPECT_EQ(Font::NORMAL, fonts[0].GetStyle());
}
TEST_F(FontListTest, Fonts_FromFontWithNonNormalStyle) {
// Test init from Font with non-normal style.
Font font("Arial", 8);
FontList font_list = FontList(font.DeriveFont(2, Font::BOLD));
const std::vector<Font>& fonts = font_list.GetFonts();
EXPECT_EQ(1U, fonts.size());
EXPECT_EQ("Arial", fonts[0].GetFontName());
EXPECT_EQ(10, fonts[0].GetFontSize());
EXPECT_EQ(Font::BOLD, fonts[0].GetStyle());
font_list = FontList(font.DeriveFont(-2, Font::ITALIC));
const std::vector<Font>& fonts_1 = font_list.GetFonts();
EXPECT_EQ(1U, fonts_1.size());
EXPECT_EQ("Arial", fonts_1[0].GetFontName());
EXPECT_EQ(6, fonts_1[0].GetFontSize());
EXPECT_EQ(Font::ITALIC, fonts_1[0].GetStyle());
}
TEST_F(FontListTest, Fonts_FromFontVector) {
// Test init from Font vector.
Font font("Arial", 8);
Font font_1("Sans serif", 10);
std::vector<Font> input_fonts;
input_fonts.push_back(font.DeriveFont(0, Font::BOLD));
input_fonts.push_back(font_1.DeriveFont(-2, Font::BOLD));
FontList font_list = FontList(input_fonts);
const std::vector<Font>& fonts = font_list.GetFonts();
EXPECT_EQ(2U, fonts.size());
EXPECT_EQ("Arial", fonts[0].GetFontName());
EXPECT_EQ(8, fonts[0].GetFontSize());
EXPECT_EQ(Font::BOLD, fonts[0].GetStyle());
EXPECT_EQ("Sans serif", fonts[1].GetFontName());
EXPECT_EQ(8, fonts[1].GetFontSize());
EXPECT_EQ(Font::BOLD, fonts[1].GetStyle());
}
TEST_F(FontListTest, Fonts_DescStringWithStyleInFlexibleFormat_RoundTrip) {
// Test round trip from font description string to font vector to
// font description string.
FontList font_list = FontList(" serif , Sans serif , PANGO_WEIGHT_BOLD "
" PANGO_STYLE_ITALIC 10 ");
const std::vector<Font>& fonts = font_list.GetFonts();
FontList font_list_1 = FontList(fonts);
const std::string& desc_str = font_list_1.GetFontDescriptionString();
#if defined(OS_LINUX)
EXPECT_EQ("serif,Sans serif,PANGO_WEIGHT_BOLD PANGO_STYLE_ITALIC 10",
desc_str);
#else
EXPECT_EQ("serif,Sans serif,10", desc_str);
#endif
}
TEST_F(FontListTest, Fonts_FontVector_RoundTrip) {
// Test round trip from font vector to font description string to font vector.
Font font("Arial", 8);
Font font_1("Sans serif", 10);
std::vector<Font> input_fonts;
input_fonts.push_back(font.DeriveFont(0, Font::BOLD));
input_fonts.push_back(font_1.DeriveFont(-2, Font::BOLD));
FontList font_list = FontList(input_fonts);
const std::string& desc_string = font_list.GetFontDescriptionString();
FontList font_list_1 = FontList(desc_string);
const std::vector<Font>& round_trip_fonts = font_list_1.GetFonts();
EXPECT_EQ(2U, round_trip_fonts.size());
EXPECT_EQ("Arial", round_trip_fonts[0].GetFontName());
EXPECT_EQ(8, round_trip_fonts[0].GetFontSize());
EXPECT_EQ("Sans serif", round_trip_fonts[1].GetFontName());
EXPECT_EQ(8, round_trip_fonts[1].GetFontSize());
#if defined(OS_LINUX)
EXPECT_EQ(Font::BOLD, round_trip_fonts[0].GetStyle());
EXPECT_EQ(Font::BOLD, round_trip_fonts[1].GetStyle());
#else
// Style is ignored.
EXPECT_EQ(Font::NORMAL, round_trip_fonts[0].GetStyle());
EXPECT_EQ(Font::NORMAL, round_trip_fonts[1].GetStyle());
#endif
}
} // namespace gfx
|