• 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
Calculating the size of NSFont...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calculating the size of NSFont...


  • Subject: Calculating the size of NSFont...
  • From: Rachel Blackman <email@hidden>
  • Date: Sat, 3 Mar 2007 22:52:01 -0800

Alright, one more query, as long as I'm diving back into the cocoadev folder... :)

I've got a monospaced font. I need to calculate the 'width' of a given character, so that I can figure out certain things. However, I can't seem to quite get a 'right' value. If I draw a bunch of boxes and start typing, the characters and the boxes get out of alignment after a while.

NSFont -maximumAdvancement seems to have the boxes ever so slightly too small, which isn't surprising; I think -maximumAdvancement isn't actually accounting for space between the characters. Taking a string of characters, figuring out the size using NSFont - widthOfString: and then dividing by the string length gets me closer (and 'good enough' for some purposes) but still gets offset after about 20 characters. So, also no good for this particular case, where I need the alignment good for up to about 90 characters.

Given that I have turned off kerning on the textview where this would be displayed, Is there some relatively simple way I'm missing to get what the spacing is between the characters, some nice value to add to -maximumAdvancement?

--
Rachel 'Sparks' Blackman -- sysadmin, developer, mad scientist
"If it is not broken, give me five minutes to redesign it!"

_______________________________________________

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


  • Follow-Ups:
    • Re: Calculating the size of NSFont...
      • From: m <email@hidden>
    • Re: Calculating the size of NSFont...
      • From: Buddy Kurz <email@hidden>
  • Prev by Date: Re: Subclass of NSMutableDictionary hanging
  • Next by Date: Re: NSUserDefaults won't do as it's told
  • Previous by thread: Re: question about custom cursor
  • Next by thread: Re: Calculating the size of NSFont...
  • Index(es):
    • Date
    • Thread