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

Side by Side Diff: ui/gfx/platform_font_mac_unittest.mm

Issue 1252893002: Fix font height on Mac with Helvetica Neue at size 16 (ResourceBundle::MediumFont) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20150722-MacViews-AppInfoNit
Patch Set: nit test comment Created 5 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
« ui/gfx/platform_font_mac.mm ('K') | « ui/gfx/platform_font_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <Cocoa/Cocoa.h> 5 #include <Cocoa/Cocoa.h>
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gfx/font.h" 8 #include "ui/gfx/font.h"
9 9
10 TEST(PlatformFontMacTest, DeriveFont) { 10 TEST(PlatformFontMacTest, DeriveFont) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 EXPECT_EQ(14, italic_font.GetFontSize()); 47 EXPECT_EQ(14, italic_font.GetFontSize());
48 EXPECT_EQ("Helvetica", italic_font.GetFontName()); 48 EXPECT_EQ("Helvetica", italic_font.GetFontName());
49 EXPECT_EQ(gfx::Font::ITALIC, italic_font.GetStyle()); 49 EXPECT_EQ(gfx::Font::ITALIC, italic_font.GetStyle());
50 50
51 gfx::Font bold_italic_font( 51 gfx::Font bold_italic_font(
52 [NSFont fontWithName:@"Helvetica-BoldOblique" size:14]); 52 [NSFont fontWithName:@"Helvetica-BoldOblique" size:14]);
53 EXPECT_EQ(14, bold_italic_font.GetFontSize()); 53 EXPECT_EQ(14, bold_italic_font.GetFontSize());
54 EXPECT_EQ("Helvetica", bold_italic_font.GetFontName()); 54 EXPECT_EQ("Helvetica", bold_italic_font.GetFontName());
55 EXPECT_EQ(gfx::Font::BOLD | gfx::Font::ITALIC, bold_italic_font.GetStyle()); 55 EXPECT_EQ(gfx::Font::BOLD | gfx::Font::ITALIC, bold_italic_font.GetStyle());
56 } 56 }
57
58 // Ensures that the Font's reported height is consistent with the native font's
59 // ascender and descender metrics.
60 TEST(PlatformFontMacTest, ValidateFontHeight) {
61 // Use the default ResourceBundle system font. E.g. Helvetica Neue in 10.10,
62 // Lucida Grande before that, and San Francisco after.
63 gfx::Font default_font;
64 gfx::Font::FontStyle style[] = {
Alexei Svitkine (slow) 2015/07/27 14:48:04 Nit: styles
tapted 2015/07/28 00:38:49 Done.
65 gfx::Font::NORMAL, gfx::Font::BOLD, gfx::Font::ITALIC, gfx::Font::UNDERLINE
66 };
67
68 for (size_t i = 0; i < arraysize(style); ++i) {
69 SCOPED_TRACE(testing::Message() << "Font::FontStyle: " << style[i]);
70 // Include the range of sizes used by ResourceBundle::FontStyle (-1 to +8).
71 for (int delta = -1; delta <= 8; ++delta) {
72 gfx::Font font = default_font.Derive(delta, style[i]);
73 SCOPED_TRACE(testing::Message() << "FontSize(): " << font.GetFontSize());
74 NSFont* native_font = font.GetNativeFont();
75
76 // Font height (an integer) should be the sum of these.
77 CGFloat ascender = [native_font ascender];
78 CGFloat descender = [native_font descender];
79 CGFloat leading = [native_font leading];
80
81 // NSFont always gives a negative value for descender. Others positive.
82 EXPECT_GE(0, descender);
83 EXPECT_LE(0, ascender);
84 EXPECT_LE(0, leading);
85
86 int sum = ceil(ascender - descender + leading);
87
88 // Text layout is performed using an integral baseline offset derived from
89 // the ascender. The height needs to be enough to fit the full descender
90 // (plus baseline). So the height depends on the rounding of the ascender,
91 // and can be as much as 1 greater than the simple sum of floats.
92 EXPECT_LE(sum, font.GetHeight());
93 EXPECT_GE(sum + 1, font.GetHeight());
94
95 // Recreate the rounding performed for GetBaseLine().
96 EXPECT_EQ(ceil(ceil(ascender) - descender + leading), font.GetHeight());
97 }
98 }
99 }
OLDNEW
« ui/gfx/platform_font_mac.mm ('K') | « ui/gfx/platform_font_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698