Re: Calculating the size of NSFont...
Re: Calculating the size of NSFont...
- Subject: Re: Calculating the size of NSFont...
- From: Aki Inoue <email@hidden>
- Date: Sun, 4 Mar 2007 12:39:35 -0800
Probably, in both cases, you're calculating width using the printer
font instead of screen font.
NSLayoutManager substitutes your printer fonts with screen fonts via -
substituteFontForFont: method.
Usually screen fonts have rounded advancements. So, if you calculate
width using printer fonts that have ideal metrics and NSLayoutManager
rendering with screen fonts, it could result in metrics mismatch.
Aki
I asked the same question a couple of months ago and got zero
response. However, i was able to find, by experiment, an answer
which seems to work. Caveat: no documentation exists to verify this.
In fact all the documentation contradicts it. However the actual
behavior of the Apple typesetter contradicts the documentation, and
agrees with my experiments, at least for the sizes and fonts I have
tried. The following code works for me:
float adv = [termFont advancementForGlyph:
[termFont glyphWithName:@"space"]].width;
charSize.width = (int)(adv+0.5); /* font size must
be < 17. */
charSize.height = [layoutMgr defaultLineHeightForFont:termFont];
Note that if the Font Size is 17 or greater, the fractional floating
advance seems to be used. Go Figure!
Dale Miller
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden