[NSString sizeWithAttributes:] does not respect a font's NSFontFixedAdvanceAttribute setting in 10.11
| Originator: | chinhster2 | ||
| Number: | rdar://21960743 | Date Originated: | 23-Jul-2015 08:52 AM |
| Status: | Closed | Resolved: | beta 7 |
| Product: | OS X | Product Version: | 10.11 |
| Classification: | Serious bug | Reproducible: | Always |
Summary:
Starting in El Capitan beta 2, [NSString sizeWithAttributes:] does not respect a font's fontDescriptor's NSFontFixedAdvanceAttribute setting in El Capitan. As of beta 4, the bug still exists.
Steps to Reproduce:
1. Install Xcode on 10.11.
2. Compile included program foo.m from terminal with "clang -fobjc-arc -framework Cocoa foo.m -o foo".
3. Execute foo executable.
Expected Results:
The output from the program "foo" should show:
1) maxAdvance=8.000000
2) charWidth=8.000000
which it does on any version of OS X prior to 10.11 beta 2.
Actual Results:
The output instead shows when run on 10.11:
1) maxAdvance=8.000000
2) charWidth=7.224609
Version:
OS X El Capitan/15A226f
Notes:
Although I can code around this problem in the current release of my application, I can't make changes to much earlier releases of my application that many users still use and would use in 10.11. This affects output in my application because I draw text with fixed width fonts using integer coordinates and integer advancement.
Configuration:
I get the correct output on any version of OS X prior to 10.11 beta 2. I get the incorrect result on 10.11 beta2 to beta 4.
foo.m:
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
NSString *system = [[NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"] objectForKey:@"ProductVersion"] ;
NSLog(@"ProductVersion=%@", system) ;
NSString *string = @"Wg" ;
NSFont *font = [NSFont userFixedPitchFontOfSize:12.] ;
CGFloat maxAdvance = ceilf(font.maximumAdvancement.width) ;
printf("1) maxAdvance=%f\n", maxAdvance) ;
NSFontDescriptor *descriptor = [font.fontDescriptor fontDescriptorByAddingAttributes:@{NSFontFixedAdvanceAttribute: [NSNumber numberWithDouble:maxAdvance]}] ;
font = [NSFont fontWithDescriptor:descriptor size:font.pointSize] ;
printf("2) charWidth=%f\n", [string sizeWithAttributes:@{NSFontAttributeName: font}].width/2.) ;
return(0) ;
}
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!