• 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: Simple way to find out baseline for NSAttributedString?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple way to find out baseline for NSAttributedString?


  • Subject: Re: Simple way to find out baseline for NSAttributedString?
  • From: "Alastair J.Houghton" <email@hidden>
  • Date: Thu, 4 Sep 2003 20:32:53 +0100

On Thursday, September 4, 2003, at 07:15 pm, email@hidden wrote:

Have you looked at NSFont's ascender, descender, and
defaultLineHeightForFont methods?

Yes -- but what I want is not the descender for a single font, but for an attributed string which might consist of several fonts in a row. Imagine a 72-point Helvetica "A" followed by 60-point Palatino "pple" followed by a 7-point "(R)". So I need the descender that was calculated for the entire attributed string.

It's a bit awkward if you have super/subscript involved, but if you just had plain text, the baselines will line-up, so you need to maximum of the -descender values from all of the fonts in your line of text. If you wanted to make it work for superscript and subscript, you'll have to figure-out where the baseline of the super/subscript characters is in relation to the baseline of the text. Since this is graphics-related, I'll draw some ASCII-art to illustrate what I'm talking about:


ascent - - . - - - - - - - - - - - - - -,-,- - - -
ascent(2) - / \ - - - - - - - -|- - - - -( R )- - -
/___\ ___ ___ | ___ __`-'_______ baseline(3)
/ \ | \ | \ | |___|
baseline /-------\-|___/-|___/-|-|____--------------
| |
descent(2) - - - - | - - | - - - - - - - - - - - - -
descent - - - - - - - - - - - - - - - - - - - - -

ascent and descent are the ascender and descender for 72-point Helvetica, ascent(2) and descent(2) are the ascender and descender for 60-point Palatino, and baseline(3) shows the problem with superscript or subscript characters. Notice that all the ordinary characters are aligned on their baselines, despite being different sizes and different fonts.

The other question you have to answer is whether you want to know the values for the particular string you are looking at, or whether you want the maximum possible values for any string with those attributes; if you use NSFont's -ascender and -descender methods, you'll find the maximum bounds... for example, the -descender method will still tell you that the descent line is where it is shown on my diagram above, even though an upper-case 'A' doesn't descend below the baseline in Helvetica. If you want metrics that reflect the actual string, you'll have to use the more sophisticated methods on NSLayoutManager.

Kind regards,

Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Simple way to find out baseline for NSAttributedString?
      • From: email@hidden
References: 
 >Re: Simple way to find out baseline for NSAttributedString? (From: email@hidden)

  • Prev by Date: Re: Split Buttons: How do I make em?
  • Next by Date: Re: Simple way to find out baseline for NSAttributedString?
  • Previous by thread: Re: Simple way to find out baseline for NSAttributedString?
  • Next by thread: Re: Simple way to find out baseline for NSAttributedString?
  • Index(es):
    • Date
    • Thread