• 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: Best way to obtain the width of a piece of text?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best way to obtain the width of a piece of text?


  • Subject: Re: Best way to obtain the width of a piece of text?
  • From: Douglas Davidson <email@hidden>
  • Date: Thu, 8 Apr 2004 17:46:13 -0700

On Apr 8, 2004, at 5:16 PM, Steve Sims wrote:

The implication of the results I am seeing is that after a certain point a tab character will be interpreted as a new line, rather than as a tab. This is not exactly what I would expect.

The problem here is that you have tabs in text beyond the location of the last tab stop in your paragraph style. The text system responds to this by moving to the next line--try it in TextEdit. You need to modify your paragraph style to either add extra tab stops, or else set a default tab interval.

The other thing I believe you were missing before is that a default NSTextContainer has a non-zero line fragment padding, which is appropriate for ordinary text view uses but not usually for string drawing or sizing. The string drawing/sizing methods use a text container with the line fragment padding set to 0.

Note that if you already have a layout manager with the text you are interested in laid out, or if you wish to use the layout information for the same text more than once, then getting the used rect from the layout manager will generally be more efficient than using string drawing/sizing methods. The string drawing/sizing methods, however, are much easier to use, and will generally be more efficient if you have to deal with the same text only once.

Douglas Davidson
_______________________________________________
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.


References: 
 >Best way to obtain the width of a piece of text? (From: Steve Sims <email@hidden>)
 >Re: Best way to obtain the width of a piece of text? (From: Douglas Davidson <email@hidden>)
 >Re: Best way to obtain the width of a piece of text? (From: Steve Sims <email@hidden>)

  • Prev by Date: I need more mouseDragged events
  • Next by Date: Setting env vars from Cocoa with /bin/sh?
  • Previous by thread: Re: Best way to obtain the width of a piece of text?
  • Next by thread: Re: Objective-C++
  • Index(es):
    • Date
    • Thread