Problem with drawBackgroundForGlyphRange:atPoint:
Problem with drawBackgroundForGlyphRange:atPoint:
- Subject: Problem with drawBackgroundForGlyphRange:atPoint:
- From: "Jjgod Jiang" <email@hidden>
- Date: Mon, 13 Aug 2007 02:03:32 +0800
Hi,
When I was trying to do custom text drawing with NSLayoutManager,
I got the following problem:
- (void) drawRect:(NSRect)rect
{
NSTextStorage *textStorage = [[NSTextStorage alloc] initWithString: @""];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
NSTextContainer *textContainer = [[NSTextContainer alloc]
initWithContainerSize: NSMakeSize(1.0e7, 1.0e7)];
[layoutManager addTextContainer: textContainer];
[textContainer release];
[textStorage addLayoutManager: layoutManager];
[layoutManager release];
NSString *string = @"Hello World";
NSMutableDictionary *attributes = [NSMutableDictionary
dictionaryWithObjectsAndKeys:
[NSColor blueColor],
NSBackgroundColorAttributeName,
[NSColor whiteColor],
NSForegroundColorAttributeName,
nil];
NSRange charRange = NSMakeRange(0, [string length]);
[[textStorage mutableString] setString: string];
[textStorage setAttributes: attributes range: charRange];
NSRange glyphRange = [layoutManager glyphRangeForCharacterRange: charRange
actualCharacterRange: NULL];
[layoutManager drawBackgroundForGlyphRange: glyphRange atPoint:
NSMakePoint(0, 0)];
[layoutManager drawGlyphsForGlyphRange: glyphRange atPoint:
NSMakePoint(0, 0)];
[textStorage release];
}
Foreground text is drawn correctly, but background is never drawn
no matter which color I set for NSBackgroundColorAttributeName.
- Jiang
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden