Determine particular symbol width in TextField

Discussion in 'Mac Programming' started by i.yalovecky, Jun 1, 2010.

  1. i.yalovecky macrumors member

    Joined:
    Feb 24, 2010
    #1
    How i can do it? User can change Fontsize and font family in NSTextField, and i need to get width for specified symbol. Thanks.
     
  2. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #2
    Probably something like

    bool CGFontGetGlyphBBoxes (
    CGFontRef font,
    const CGGlyph glyphs[],
    size_t count,
    CGRect bboxes[]
    );

    Pass it your font, your symbol (glyph), 1, and a CGRect and if the function returns true then CGRect.width should contain the appropriate width you are looking for.
     
  3. i.yalovecky thread starter macrumors member

    Joined:
    Feb 24, 2010
    #3
    How i can convert unichar or NSString* to glyphs?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Have you considered putting the character into a NSString and using
    sizeWithAttributes: (passing an appropriate dictionary of attributes)?
     
  5. i.yalovecky thread starter macrumors member

    Joined:
    Feb 24, 2010
    #5
    Woow, its worked!
     

Share This Page