Chromium Code Reviews| Index: ui/gfx/platform_font_mac.mm |
| diff --git a/ui/gfx/platform_font_mac.mm b/ui/gfx/platform_font_mac.mm |
| index 53781f8e2309e74b7c72fb319b85c430132c83aa..e7d2e90e4a41a6af9acca7073d1bb0fa7155e4d8 100644 |
| --- a/ui/gfx/platform_font_mac.mm |
| +++ b/ui/gfx/platform_font_mac.mm |
| @@ -218,8 +218,14 @@ int GetFontStyleFromNSFont(NSFont* font) { |
| // 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"]]); |
| + // -[NSFont boundingRectForGlyph:] seems to always return the largest bounding |
| + // rect that could be needed, which produces very wide expected widths for |
| + // strings. Instead, compute the actual width of a string containing all the |
| + // lowercase characters to find a reasonable guess at the average. |
| + NSAttributedString* as = [[[NSAttributedString alloc] |
|
tapted
2017/05/01 06:48:05
since this is a bit heavyweight, and barely anythi
Elly Fong-Jones
2017/05/02 14:41:23
Done.
|
| + initWithString:@"abcdefghijklmnopqrstuvwxyz" |
| + attributes:@{NSFontAttributeName : font}] autorelease]; |
| + average_width_ = [as size].width / [as length]; |
|
tapted
2017/05/01 06:48:05
rounding is occurring here, and GetExpectedTextWid
Elly Fong-Jones
2017/05/02 14:41:23
Done.
|
| FontRenderParamsQuery query; |
| query.families.push_back(font_name_); |