Mac / views_examples -> Text Styles. Selecting "Underline" makes the font bold also |
|||
Issue descriptionChrome Version : 52.0.2713.0 OS Version: OS X 10.11.4 What steps will reproduce the problem? 1. On Mac, build and run views_examples_with_content_exe 2. Select the "Text Styles" example 3. Check "Underline" What is the expected result? Font goes underline only. What happens instead of that? Font also goes bold. - Checking/Unchecking "Bold" has no effect. But! - Checking/Unchecking "Halo" makes the other styles work "normally" - But! the sequence: Underline, Halo removes Underline. But then toggling Underline works as expected. - --enable-harfbuzz-rendertext didn't fix the problem - Didn't repro on Windows at r375745
,
Aug 1 2016
Investigated this. Seems to be caused by 2 bugs- 1) The text does not get underlined because PlatformFontMac::DeriveFont "loses" underline font style in the derived font at https://cs.chromium.org/chromium/src/ui/gfx/platform_font_mac.mm?q=platform_font_mac&sq=package:chromium&l=102. 2) Why does the text become bold? The Cocoa API's seem to be acting a bit weirdly. The font returned by NSFontWithSpec at https://cs.chromium.org/chromium/src/ui/gfx/platform_font_mac.mm?q=platform_font_mac&sq=package:chromium&l=23 is bold, even when we don't ask for a bold font. Example consider - NSFontDescriptor* descriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{NSFontFamilyAttribute: @".AppleSystemUIFont", NSFontTraitsAttribute: @{ NSFontSymbolicTrait : @(0)}}]; bool is_bold = [descriptor symbolicTraits] & NSFontBoldTrait; NSLog(@"---IsBold-%d %@\n", is_bold, [descriptor description]); NSFont* font = [NSFont fontWithDescriptor:descriptor size:13]; NSFontTraitMask traits = [[NSFontManager sharedFontManager] traitsOfFont:font]; is_bold = traits & NSFontBoldTrait; NSLog(@"---IsBold-%d %@\n", is_bold, [[font fontDescriptor] description]); This prints ---IsBold-0 NSCTFontDescriptor <0x600000080550> = { NSCTFontTraitsAttribute = { NSCTFontSymbolicTrait = 0; }; NSFontFamilyAttribute = ".AppleSystemUIFont"; } 2016-08-01 11:41:49.661 TestFullScreen[54215:21278314] ---IsBold-1 NSCTFontDescriptor <0x600000086540> = { NSCTFontUIUsageAttribute = CTFontEmphasizedUsage; NSFontSizeAttribute = 13; } Hence we are getting a bold font, even when we did not ask one. The cause seems to caused due to the CTFontEmphasizedUsage attribute which is added by default and makes the font bold. This attribute seems to be related to the font weight. Not sure what the right fix for this is, but creating a font descriptor with an NSFontWeightTrait of 0 (regular or medium font weight) seems to resolve the issue. Example NSFontDescriptor* descriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{NSFontFamilyAttribute: @".AppleSystemUIFont", NSFontTraitsAttribute: @{ NSFontSymbolicTrait : @(0), NSFontWeightTrait:@(0)}}]; bool is_bold = [descriptor symbolicTraits] & NSFontBoldTrait; NSLog(@"---IsBold-%d %@\n", is_bold, [descriptor description]); NSFont* font = [NSFont fontWithDescriptor:descriptor size:13]; NSFontTraitMask traits = [[NSFontManager sharedFontManager] traitsOfFont:font]; is_bold = traits & NSFontBoldTrait; NSLog(@"---IsBold-%d %@\n", is_bold, [[font fontDescriptor] description]); prints ---IsBold-0 NSCTFontDescriptor <0x630000081310> = { NSCTFontTraitsAttribute = { NSCTFontSymbolicTrait = 0; NSCTFontWeightTrait = 0; }; NSFontFamilyAttribute = ".AppleSystemUIFont"; } 2016-08-01 11:46:55.904 TestFullScreen[54289:21280526] ---IsBold-0 NSCTFontDescriptor <0x6300000863b0> = { NSCTFontUIUsageAttribute = CTFontRegularUsage; NSFontSizeAttribute = 13; }
,
Aug 9 2016
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/f7e5e8283b6a43f3371381fedd81beea941cef48 commit f7e5e8283b6a43f3371381fedd81beea941cef48 Author: karandeepb <karandeepb@chromium.org> Date: Tue Aug 09 02:18:11 2016 Mac: Fix PlatformFontMac::DeriveFont. 1. Currently, when we derive a font from an existing PlatformFontMac instance with only the size changed, we fail to persist the Font::UNDERLINE style in the derived font. 2. Also in all the other cases, instead of using the native_font_ instance to derive the font, we create a new PlatformFontMac instance from the font_name and other parameters. This can lead to unexpected results when the font from which we are deriving is a system font, since Apple explicitly forbids using a system font name to create a new font (See Potential API Pitfalls section in the WWDC talk Introducing the New System Fonts. Link - https://developer.apple.com/videos/play/wwdc2015/804/). For example, in the Text Styles example of views_examples_with_content_exe, on clicking underline, the derived font does not have underline due to 1 and is bold because of 2, even though we didn't specify the bold font trait. This CL modifies PlatformFontMac::DeriveFont to use the NSFontManager to create a new derived NSfont. Since the new PlatformFontMac instance created has the passed font style, 1 is solved. Also, since we no longer use the font name to create the derived font, 2 is also solved. Also, added two tests which fail on the current master and demonstrate the problem. BUG= 605404 TEST=Build and run views_examples_with_content_exe. Select the "Text Styles" example. Check "Underline". Verify the text gets underlined. Verify the font is not bold. Play around with different combinations and verify that they work as expected. Review-Url: https://codereview.chromium.org/2222483002 Cr-Commit-Position: refs/heads/master@{#410525} [modify] https://crrev.com/f7e5e8283b6a43f3371381fedd81beea941cef48/ui/gfx/font_unittest.cc [modify] https://crrev.com/f7e5e8283b6a43f3371381fedd81beea941cef48/ui/gfx/platform_font_mac.h [modify] https://crrev.com/f7e5e8283b6a43f3371381fedd81beea941cef48/ui/gfx/platform_font_mac.mm [modify] https://crrev.com/f7e5e8283b6a43f3371381fedd81beea941cef48/ui/gfx/platform_font_mac_unittest.mm
,
Aug 9 2016
|
|||
►
Sign in to add a comment |
|||
Comment 1 by tapted@chromium.org
, May 31 2016