• 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: Choose an NSFont with specific line height?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Choose an NSFont with specific line height?


  • Subject: Re: Choose an NSFont with specific line height?
  • From: Douglas Davidson <email@hidden>
  • Date: Mon, 17 Apr 2006 11:49:22 -0700


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.


Actually, it's probably better to do this with a known piece of text rather than just a font, because in general font substitution might mean that a different font is used for portions of the text that can't be rendered with the supplied font. Also, it's best on principle to do the measurement with the same mechanism that will be doing the actual layout; for example, leading may depend on the typesetter behavior, which is one reason why defaultLineHeightForFont: is a method on NSLayoutManager.

Douglas Davidson

_______________________________________________
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


  • Follow-Ups:
    • Re: Choose an NSFont with specific line height?
      • From: Dustin Voss <email@hidden>
References: 
 >Choose an NSFont with specific line height? (From: Mike Blaguszewski <email@hidden>)

  • Prev by Date: Re: Different context in Core Data
  • Next by Date: Re: Adding bindings to a custom view - "simple" implementation
  • Previous by thread: Choose an NSFont with specific line height?
  • Next by thread: Re: Choose an NSFont with specific line height?
  • Index(es):
    • Date
    • Thread