What's wrong with this temporary attribute code?
What's wrong with this temporary attribute code?
- Subject: What's wrong with this temporary attribute code?
- From: Roberto <email@hidden>
- Date: Mon, 21 Oct 2002 01:14:41 -0600
I'm trying to use NSLayoutManager's temporary attribute calls just as
they are intended (to temporarily display some text in a different
color). The following code works great with 12 pt Helvetica text, but
at any other size, the position of the characters is messed up (some of
the characters are overwritten by other characters). It almost seems
like the layout manager thinks the text is still 12 pt. If I remove the
addTemporaryAttributes call, the text displays correctly.
Here's the code (somewhat simplified for easier reading):
NSTextStorage *contents = [self contents];
NSLayoutManager *lm = sharedDrawingLayoutManager();
NSTextContainer *tc = [[lm textContainers] objectAtIndex:0];
[tc setContainerSize:bounds.size];
[contents addLayoutManager:lm];
NSRange glyphRange = [lm glyphRangeForTextContainer:tc];
// This is the code that's causing the problem
NSDictionary *tempAttributes = [NSDictionary
dictionaryWithObject:[NSColor grayColor]
forKey:NSForegroundColorAttributeName];
[lm addTemporaryAttributes:tempAttributes
forCharacterRange:NSMakeRange( 5, 8)];
[lm drawBackgroundForGlyphRange:glyphRange atPoint:bounds.origin];
[lm drawGlyphsForGlyphRange:glyphRange atPoint:bounds.origin];
[lm removeTemporaryAttribute:NSForegroundColorAttributeName
forCharacterRange:NSMakeRange( 5, 8)];
Any ideas what I'm doing wrong?
_______________________________________________
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.