Calculate height of text in a text field
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