Height of a string with fixed width and given font
Height of a string with fixed width and given font
- Subject: Height of a string with fixed width and given font
- From: Steve Bennett <email@hidden>
- Date: Mon, 18 Feb 2002 17:46:37 -0500
In the "It should be trivial but this blasted documentation doesn't show it"
department:
Simple Task -- I want to display a block of text (a single NSString) in an
area which has a fixed width. The text could easily wrap, or contain
newlines, etc, and I want to know what the resulting total height of the
text will be if drawn with a specific font.
I would think that the NSString method sizeWithAttributes would be able to
do this, but I've tried all kinds of attributes and can't find one which
will tell it to give me anything but the base font height.
I've read through the docs on just about every NSTextXxxx class,
NSLayoutManager, NSFont, NSAttributedString (and it's AppKit additions),
NSString (and it's Appkit additions), and NSTypesetter, and barring writing
some massive function to use a dozen classes to calculate the wrap points
and line endings and count the resulting lines and then use the font height
to calculate the actual text height, I'm stumped.
Please tell me I'm missing something obvious? It seems ridiculous that such
a trivial task could be so complex to do under cocoa...
-->Steve Bennett
_______________________________________________
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.