SOLVED Re: NSAttributedString rendering bugs when rendered with Cocoa Text (rdar://6379047)
SOLVED Re: NSAttributedString rendering bugs when rendered with Cocoa Text (rdar://6379047)
- Subject: SOLVED Re: NSAttributedString rendering bugs when rendered with Cocoa Text (rdar://6379047)
- From: Rua Haszard Morris <email@hidden>
- Date: Wed, 19 Nov 2008 09:18:30 +1300
To follow up.. below I have pasted the code that draws the text (for
my test app, as opposed to the more complex ways of reproducing the
bug elsewhere in my code). (the full test app is attached to the radar
bug)
I have been consulting the Text System Overview documentation, which I
don't believe mentions this fact.
http://developer.apple.com/documentation/Cocoa/Conceptual/TextArchitecture/TextArchitecture.html
I can understand that drawing text top to bottom makes sense, but I am
surprised that the coordinate system of the destination context has
such far-reaching side effects.
Thanks for all the info,
Rua HM.
- (void)drawRect:(NSRect)rect {
CGContextRef context = (CGContextRef)[[NSGraphicsContext
currentContext]graphicsPort];
CGContextSaveGState(context);
NSTextStorage* textStorage = [[NSTextStorage alloc]
initWithAttributedString:attribString];
NSLayoutManager *layoutManager;
layoutManager = [[NSLayoutManager alloc] init];
[textStorage addLayoutManager:layoutManager];
NSTextContainer *container = [[NSTextContainer alloc]
initWithContainerSize:NSMakeSize(9999, 9999)];
[layoutManager addTextContainer:container];
NSRange glyphRange = [layoutManager
glyphRangeForTextContainer:container];
[layoutManager drawGlyphsForGlyphRange:glyphRange
atPoint:NSMakePoint(10, 10)];
[container release];
[layoutManager release];
[textStorage release];
CGContextRestoreGState(context);
}
On Nov 19, 2008, at 9:09 am, 11(November)/19/08, Douglas Davidson wrote:
On Nov 18, 2008, at 11:53 AM, Rua Haszard Morris wrote:
I was ensuring that I am _not_ drawing in a flipped context... (!)
now, as you suggest I tried flipping the custom view (override
isFlipped) that the attributed string is drawn in, and note that it
works correctly!
So an improved workaround is to tweak the positioning logic (to
account for the flipped context) instead of tweaking (hacking) the
actual attributes.
I'm still not clear on why this should be the case. Thanks for the
vastly better workaround though..
The text system generally prefers a flipped context, because text
generally runs from top to bottom rather than the reverse. You
didn't post code, so I'm not sure exactly what you're doing, but
this is a good general rule.
Douglas Davidson
_______________________________________________
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