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

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

Issue 19352002: Fixes vertical alignment of RenderText. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 (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/font_list.h" 5 #include "ui/gfx/font_list.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/platform_font_fake.h"
12 13
13 namespace { 14 namespace {
14 15
15 // Helper function for comparing fonts for equality. 16 // Helper function for comparing fonts for equality.
16 std::string FontToString(const gfx::Font& font) { 17 std::string FontToString(const gfx::Font& font) {
17 std::string font_string = font.GetFontName(); 18 std::string font_string = font.GetFontName();
18 font_string += "|"; 19 font_string += "|";
19 font_string += base::IntToString(font.GetFontSize()); 20 font_string += base::IntToString(font.GetFontSize());
20 int style = font.GetStyle(); 21 int style = font.GetStyle();
21 if (style & gfx::Font::BOLD) 22 if (style & gfx::Font::BOLD)
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 FontList font_list = FontList(fonts); 226 FontList font_list = FontList(fonts);
226 227
227 FontList derived = font_list.DeriveFontListWithSize(5); 228 FontList derived = font_list.DeriveFontListWithSize(5);
228 const std::vector<Font>& derived_fonts = derived.GetFonts(); 229 const std::vector<Font>& derived_fonts = derived.GetFonts();
229 230
230 EXPECT_EQ(2U, derived_fonts.size()); 231 EXPECT_EQ(2U, derived_fonts.size());
231 EXPECT_EQ("Arial|5", FontToString(derived_fonts[0])); 232 EXPECT_EQ("Arial|5", FontToString(derived_fonts[0]));
232 EXPECT_EQ("Sans serif|5", FontToString(derived_fonts[1])); 233 EXPECT_EQ("Sans serif|5", FontToString(derived_fonts[1]));
233 } 234 }
234 235
236 TEST(FontListTest, Fonts_GetHeight_GetBaseline) {
237 // Arial: ascent = 8, descent = 2
238 PlatformFontFake* pf_arial = new PlatformFontFake("Arial", 10);
msw 2013/07/16 09:32:36 Rather than creating a fake font class, why not ju
Yuki 2013/07/17 07:16:04 Done.
239 pf_arial->SetHeight(10);
240 pf_arial->SetBaseline(8);
241 Font font_arial(pf_arial);
242
243 // Helvetica: ascent = 6, descent = 4
244 PlatformFontFake* pf_helvetica = new PlatformFontFake("Helvetica", 10);
245 pf_helvetica->SetHeight(10);
246 pf_helvetica->SetBaseline(6);
247 Font font_helvetica(pf_helvetica);
248
249 // If the font list has only one font, the height and baseline must be
250 // the same.
251 FontList font_list_arial(font_arial);
252 EXPECT_EQ(font_arial.GetHeight(), font_list_arial.GetHeight());
253 EXPECT_EQ(font_arial.GetBaseline(), font_list_arial.GetBaseline());
254
255 // If there are two different fonts, the font list returns the max value
256 // for ascent and descent.
257 std::vector<Font> fonts;
258 fonts.push_back(font_arial);
259 fonts.push_back(font_helvetica);
260 FontList font_list_mix(fonts);
261 // font_list_mix: ascent = max(8, 6) = 8, descent = max(2, 4) = 4
262 // height = 8 + 4 = 12, baseline = 8
263 EXPECT_EQ(12, font_list_mix.GetHeight());
264 EXPECT_EQ(8, font_list_mix.GetBaseline());
265 }
266
235 } // namespace gfx 267 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698