Re: Choose an NSFont with specific line height?
Re: Choose an NSFont with specific line height?
- Subject: Re: Choose an NSFont with specific line height?
- From: Dustin Voss <email@hidden>
- Date: Mon, 17 Apr 2006 19:51:54 -0700
On 17 Apr 2006, at 11:49 AM, Douglas Davidson wrote:
On Apr 17, 2006, at 11:33 AM, Mike Blaguszewski wrote:
I'm trying to draw a few lines of text into a custom NSCell of
arbitrary height. So I know what height I need each line of text
to be, and I'd like to get an instance of NSFont with that line
height. (Line wrapping isn't an issue here.) I know how to
calculate line height given a font of a certain point size, but
short of doing a brute force search, I don't know how to go the
other way. Any ideas?
The question that usually gets asked here is something like, "I
have some text that I want to draw in a particular rect, and I want
to make the font size just large enough so that it will fit". We
have a known function that we want to invert. Fortunately, the
function is very nearly linear, so a root-finding algorithm with
linear extrapolation should do just fine.
So, if I understand the both of you correctly, the solution is take
the font at 72 point, see how off the size is, then reduce the font
size proportionately. So, for example, the cell's line height is 10
pixels, the 72-point line height is 82 pixels, therefore the pixels-
per-point is 82/72, and the point size that results in a 10-pixels
line height is 10*72/82. Right?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden