Drawing strings and line heights off (NSTextView)
Drawing strings and line heights off (NSTextView)
- Subject: Drawing strings and line heights off (NSTextView)
- From: Francisco Tolmasky <email@hidden>
- Date: Sat, 24 Jan 2004 02:57:58 -0800
I have an NSTextView subclass, and at one point I need to draw a shape
around some text. What I do is make a buffer image with the shape and
text and then draw it on top of the NSTextview, something like this:
- (void)drawRect:(NSRect)someCrazyRect
{
[super drawRect: someCrazyRect];
[image compositeToPoint: thePointThatWasSavedEarlier operation:
NSCompositeSourceOver];
}
The only problem is, the text in the image has a larger line height for
some reason. I'm really confused why. This is the code to draw the
given text:
- (void)prepareImageForTextRange:(NSRange)aRange
{
// ... Calculate the glyph rect etc.
[image lockFocus]
// .. draw surrounding shape
NSMutableAttributedString *theString= [[[self textStorage]
attributedSubstringFromRange: aRange] mutableCopy];
[rhsString addAttribute: NSForegroundColorAttributeName value:
[NSColor blueColor] range: NSMakeRange(0,[theString length])];
[rhsString drawInRect: theGlyphRect];
[image unlockFocus];
}
The result is *almost* perfect. If it's one line you can't tell, even
two. But by the third line the difference is noticeable by one pixel,
then two, etc. Does drawInRect: do something differently? Does anyone
know what's going on?
Thanks in advance
Francisco Tolmasky
email@hidden
http://users.adelphia.net/~ftolmasky
_______________________________________________
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.