Getting font info
Getting font info
- Subject: Getting font info
- From: Peter Schols <email@hidden>
- Date: Fri, 31 May 2002 21:43:55 +0200
Hi,
I'm looking for the easiest way to know whether a selected piece of text
in an NSTextView is bold or not.
I have tried the following:
Putting the selected text from the textfield in an NSAttributedString:
[as initWithRTF: [textView RTFFromRange:[textView selectedRange]]
documentAttributes:NULL];
Getting an NSDictionary from the FontAttributes of the attributed string
dict = [as fontAttributesInRange:NSMakeRange(0,1)];
And finally, reading the font attribute and checking it for the "Bold"
string.
This works fine, but there must be an easier way. The only thing I need
is a button that toggles the selected text Bold / Regular. Making the
selection bold is no problem (using the [fontManager
addFontTrait:sender]; method) but in order to be able to get the toggle
behaviour, I need to know whether the selection is bold or not.
Help, tips or sample code are very appreciated!
Thanks in advance!
peter
_______________________________________________
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.