• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Calculating the size of NSFont...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re:Calculating the size of NSFont... (From: Dale Miller <email@hidden>)

  • Prev by Date: Re:Calculating the size of NSFont...
  • Next by Date: Re: Bindings/NSUserDefaultsController issue
  • Previous by thread: Re:Calculating the size of NSFont...
  • Next by thread: NSUserDefaults dictionary raises exception instead of returning nil
  • Index(es):
    • Date
    • Thread