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

Unified Diff: ui/gfx/platform_font_mac.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 | « no previous file | ui/gfx/platform_font_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/platform_font_mac.mm
diff --git a/ui/gfx/platform_font_mac.mm b/ui/gfx/platform_font_mac.mm
index 892d2ea66d8a0be0b501b838a07516bfd5e5c0d7..008c4d049f11d8c58695a5d2a517f1ac59948263 100644
--- a/ui/gfx/platform_font_mac.mm
+++ b/ui/gfx/platform_font_mac.mm
@@ -166,11 +166,18 @@ void PlatformFontMac::CalculateMetricsAndInitRenderParams() {
return;
}
- base::scoped_nsobject<NSLayoutManager> layout_manager(
- [[NSLayoutManager alloc] init]);
- height_ = SkScalarCeilToInt([layout_manager defaultLineHeightForFont:font]);
- ascent_ = SkScalarCeilToInt([font ascender]);
- cap_height_ = SkScalarCeilToInt([font capHeight]);
+ ascent_ = ceil([font ascender]);
+ cap_height_ = ceil([font capHeight]);
+
+ // PlatformFontMac once used -[NSLayoutManager defaultLineHeightForFont:] to
+ // initialize |height_|. However, it has a silly rounding bug. Essentially, it
+ // gives round(ascent) + round(descent). E.g. Helvetica Neue at size 16 gives
+ // ascent=15.4634, descent=3.38208 -> 15 + 3 = 18. When the height should be
+ // at least 19. According to the OpenType specification, these values should
+ // simply be added, so do that. Note this uses the already-rounded |ascent_|
+ // to ensure GetBaseline() + descender fits within GetHeight() during layout.
+ height_ = ceil(ascent_ + std::abs([font descender]) + [font leading]);
+
average_width_ =
NSWidth([font boundingRectForGlyph:[font glyphWithName:@"x"]]);
« no previous file with comments | « no previous file | ui/gfx/platform_font_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698