FROM : Douglas Davidson
DATE : Mon Apr 04 17:40:56 2005
On Apr 3, 2005, at 12:27 PM, Roland Silver wrote:
> In my program, the cursor is positioned between two characters in a
> text view. How can I determine the current font?
>
You need to figure out what it is that you mean by the "current
font". NSTextView uses what are called typing attributes to
determine the font and other attributes for the next character typed;
you can call -typingAttributes to examine these, or -
setTypingAttributes: to change them, or you can listen for
NSTextViewDidChangeTypingAttributesNotification to be informed when
they change. Ordinarily the text view will set the typing attributes
as appropriate when the selection changes, but there is no necessary
connection between the attributes of the text and the typing
attributes--for example, if you have a zero-length selection and pick
a font from the font panel, or hit cmd-B for bold, then the typing
attributes will change although nothing in the text changes. If you
want to determine the attributes of a character in the text, just
examine the attributes of the NSTextStorage--remember that
NSTextStorage is a direct subclass of NSMutableAttributedString.
Douglas Davidson
DATE : Mon Apr 04 17:40:56 2005
On Apr 3, 2005, at 12:27 PM, Roland Silver wrote:
> In my program, the cursor is positioned between two characters in a
> text view. How can I determine the current font?
>
You need to figure out what it is that you mean by the "current
font". NSTextView uses what are called typing attributes to
determine the font and other attributes for the next character typed;
you can call -typingAttributes to examine these, or -
setTypingAttributes: to change them, or you can listen for
NSTextViewDidChangeTypingAttributesNotification to be informed when
they change. Ordinarily the text view will set the typing attributes
as appropriate when the selection changes, but there is no necessary
connection between the attributes of the text and the typing
attributes--for example, if you have a zero-length selection and pick
a font from the font panel, or hit cmd-B for bold, then the typing
attributes will change although nothing in the text changes. If you
want to determine the attributes of a character in the text, just
examine the attributes of the NSTextStorage--remember that
NSTextStorage is a direct subclass of NSMutableAttributedString.
Douglas Davidson
| Related mails | Author | Date |
|---|---|---|
| Roland Silver | Apr 3, 21:27 | |
| Satoshi Matsumoto | Apr 4, 00:43 | |
| Douglas Davidson | Apr 4, 17:40 |






Cocoa mail archive

