Re: Drawing text "with NSText"
Re: Drawing text "with NSText"
- Subject: Re: Drawing text "with NSText"
- From: publiclook <email@hidden>
- Date: Sun, 31 Aug 2003 15:57:17 -0400
On Sunday, August 31, 2003, at 01:23 PM, Alastair J.Houghton wrote:
In a number of places, both in the documentation and in Cocoa
Programming, we are told to use NSText in preference to NSString and
NSAttributedString's drawInRect:[withAttributes:] methods. There is
also a claim somewhere that all of the Cocoa UI elements use a shared
instance of NSText (the field editor, I think) to render their labels
(even the window title bar, apparently). Having looked at the text
system, though, I can't see how they could use NSText to do what is
claimed.
NSText is perfectly capable of drawing text. In fact, NSTextView is a
subclass of NSText. NSTextView was added (I think) with Rhapsody. The
field editor concept has been around since NeXTstep 0.8 and certainly
pre-dates the existence of NSTextView.
From what I can see, it would make sense to use an NSTextStorage, an
NSTextLayoutManager and an NSTextContainer to render text... perhaps
this is what the documentation means?
There is nothing wrong with NSText's -setString and -dislay methods.
What makes you say that NSText isn't capable of drawing all of the
incidental text in a window such as labels ?
I suppose it could be that Cocoa uses the NSTextStorage and
NSTextContainer associated with the field editor, but that would mean
the field editor had to be an NSTextView (otherwise there doesn't
appear to be a way to get at the text storage and container objects).
Yet NSWindow's -fieldEditor:forObject: returns an NSText. (Yes, I know
that NSTextView is a subclass of NSText, but isn't it a bit
presumptuous to make the assumption that it will always be an
NSTextView?)
I suspect that the field editor in Cocoa is usually an instance of
NSTextView, and my suspicion can be easily verified if you want.
However, NSTextStorage and NSLayoutManager are certainly not required
to store, layout, and draw text. NSTextStorage and NSLayoutManager are
a relatively new refinement to the text system. They make the Model
View Controller partitioning more obvious and provide a degree of
flexibility and refinement missing from plain old NSText, but NSText is
more than capable of rendering arbitrary RTF and it is trivial to
renter window titles, labels, pop-up help, etc. with NSText.
So, how does Cocoa draw text using an NSText instance?
It uses -setString: and -display. It also uses -alignLeft: and friends
and -setTextColor: and -setFont: and many other features of NSText.
Because NSTextView is a subclass of NSText, it may be that the field
editor is actually an instance of NSTextView in some cases, and the
assertion that the field editor is an instance of NSText remains true
because all instances of NSTextView ARE instances of NSText via
inheritance.
_______________________________________________
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.