Simple -[NSFont defaultLineHeightForFont] replacement

  • 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?

    David Dunham    A Sharp, LLC
    Voice/Fax: 206 783 7404    http://a-sharp.com
    Efficiency is intelligent laziness.
  • 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
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today