Simple -[NSFont defaultLineHeightForFont] replacement

Adam R. Maxwell amaxwell at mac.com
Sun Nov 4 21:56:26 PST 2007


On Nov 4, 2007, at 9:16 PM, David Dunham wrote:

> So defaultLineHeightForFont is deprecated, and I guess I sorta see  
> why. You're supposed to use -[NSLayoutManager  
> defaultLineHeightForFont:] instead.
>
> But I'm trying to measure before using -[NSString  
> drawAtPoint:withAttributes:]. So I don't have an NSLayoutManager to  
> talk to. Do I really need to make a NSLayoutManager (and  
> NSTextContainer) each time I want to figure out a font's height?

I generally cache an NSLayoutManager for this purpose, and you don't  
need a text container; just create it with alloc/init.  You may also  
need to call setTypesetterBehavior: with the appropriate constant, as  
well.

-- 
adam


More information about the MacOSX-dev mailing list