• 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
Calculate height of text in a text field
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calculate height of text in a text field


  • Subject: Calculate height of text in a text field
  • From: "pavao" <email@hidden>
  • Date: Mon, 22 Nov 2004 22:12:27 -0000
  • Thread-topic: Calculate height of text in a text field

Hi,

I need to calculate the vertical space occupied by the text in a given NSTextField so that I can expand it vertically accordingly. To do that, I'm creating my own private instances of NSTextContainer, NSLayoutManager and NSTextStorage. I connect them to each other and then use -[NSLayoutManager usedRectForTextContainer:] to get the height of the text. The problem is that the calculated value is not always right and either I get one extra empty line or I end up with the last line of text not being visible because the TextField wasn't resized to a big enough value.

I've searched the net and the list archives and added the following lines of code prior to calling usedRectForTextContainer:

	[textContainer setLineFragmentPadding:2.0];
	[layoutManager setTypesetterBehavior:NSTypesetterBehavior_10_2_WithCompatibility];

This supposedly mimics the typesetting behavior used by the text fields. However, the calculated height value still isn't consistent with the layout done by the text field! After some testing, I came to the conclusion that using "NSTypesetterOriginalBehavior" instead of the suggested "NSTypesetterBehavior_10_2_WithCompatibility" gives me the desired behavior. Everything shows up fine! However, as was previously mentioned on this list (and also on the Apple docs, I guess) the correct value to use should be "NSTypesetterBehavior_10_2_WithCompatibility".

I'm building and testing under MacOS X 10.3.6.

Am I doing something wrong? Can I use "NSTypesetterOriginalBehavior" and get reliable behavior in every release of MacOS X?

Thanks,
--
Joao Pavao

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Calculate height of text in a text field
      • From: João Pavão <email@hidden>
  • Prev by Date: Re: Installing a font programmatically?
  • Next by Date: Re: Applescript
  • Previous by thread: Re: Cannot load Interface Builder file ...
  • Next by thread: Re: Calculate height of text in a text field
  • Index(es):
    • Date
    • Thread