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

Unified 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: style -> styles 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/platform_font_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/platform_font_mac_unittest.mm
diff --git a/ui/gfx/platform_font_mac_unittest.mm b/ui/gfx/platform_font_mac_unittest.mm
index 17ab686ea423e295478d729fe87edfb5a44705b0..dd4ba43a1043b96432910f8a3817ad56ab1dd5fc 100644
--- a/ui/gfx/platform_font_mac_unittest.mm
+++ b/ui/gfx/platform_font_mac_unittest.mm
@@ -54,3 +54,46 @@ TEST(PlatformFontMacTest, ConstructFromNativeFont) {
EXPECT_EQ("Helvetica", bold_italic_font.GetFontName());
EXPECT_EQ(gfx::Font::BOLD | gfx::Font::ITALIC, bold_italic_font.GetStyle());
}
+
+// Ensures that the Font's reported height is consistent with the native font's
+// ascender and descender metrics.
+TEST(PlatformFontMacTest, ValidateFontHeight) {
+ // Use the default ResourceBundle system font. E.g. Helvetica Neue in 10.10,
+ // Lucida Grande before that, and San Francisco after.
+ gfx::Font default_font;
+ gfx::Font::FontStyle styles[] = {
+ gfx::Font::NORMAL, gfx::Font::BOLD, gfx::Font::ITALIC, gfx::Font::UNDERLINE
+ };
+
+ for (size_t i = 0; i < arraysize(styles); ++i) {
+ SCOPED_TRACE(testing::Message() << "Font::FontStyle: " << styles[i]);
+ // Include the range of sizes used by ResourceBundle::FontStyle (-1 to +8).
+ for (int delta = -1; delta <= 8; ++delta) {
+ gfx::Font font = default_font.Derive(delta, styles[i]);
+ SCOPED_TRACE(testing::Message() << "FontSize(): " << font.GetFontSize());
+ NSFont* native_font = font.GetNativeFont();
+
+ // Font height (an integer) should be the sum of these.
+ CGFloat ascender = [native_font ascender];
+ CGFloat descender = [native_font descender];
+ CGFloat leading = [native_font leading];
+
+ // NSFont always gives a negative value for descender. Others positive.
+ EXPECT_GE(0, descender);
+ EXPECT_LE(0, ascender);
+ EXPECT_LE(0, leading);
+
+ int sum = ceil(ascender - descender + leading);
+
+ // Text layout is performed using an integral baseline offset derived from
+ // the ascender. The height needs to be enough to fit the full descender
+ // (plus baseline). So the height depends on the rounding of the ascender,
+ // and can be as much as 1 greater than the simple sum of floats.
+ EXPECT_LE(sum, font.GetHeight());
+ EXPECT_GE(sum + 1, font.GetHeight());
+
+ // Recreate the rounding performed for GetBaseLine().
+ EXPECT_EQ(ceil(ceil(ascender) - descender + leading), font.GetHeight());
+ }
+ }
+}
« no previous file with comments | « ui/gfx/platform_font_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698