• 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: Buddy Kurz <email@hidden>
  • Date: Sun, 4 Mar 2007 08:03:28 -0800

Are you keeping everything in floats?

I use the following code snippet in a terminal emulator to get a font size that matches an integral 'box' size

float trialSize;
int deltaX;  //width of cell

trialSize=72;
trialFont = [manager fontWithFamily:fontFamily traits:NSFixedPitchFontMask weight:7 size:trialSize];
trialSize = ((trialSize * deltaX) / ([trialFont widthOfString:@"W1234"]/5));
trialFont = [manager fontWithFamily:fontFamily traits:NSFixedPitchFontMask weight:7 size:trialSize];


like your signature...

buddy kurz


On Mar 3, 2007, at 10:52 PM, Rachel Blackman wrote:

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

_______________________________________________

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: 
 >Calculating the size of NSFont... (From: Rachel Blackman <email@hidden>)

  • Prev by Date: i-bar not blinking
  • Next by Date: Re: rotating an object around the center of a view
  • Previous by thread: Calculating the size of NSFont...
  • Next by thread: Re: Calculating the size of NSFont...
  • Index(es):
    • Date
    • Thread