Re: Flipping Text
Re: Flipping Text
- Subject: Re: Flipping Text
- From: Dave Fernandes <email@hidden>
- Date: Tue, 30 Jan 2007 14:30:02 -0500
Yes, using an NSAffineTransform correctly flips any graphics you
draw. However, text rendering ignores this transform. It renders (in
my app) upside down whether or not I use the transform.
Here is a simplification of my code (without the transform) for my
custom NSView. The drawOffscreen method is called from within
drawRect, occasionally, when some parameter has changed and valid == NO.
- (BOOL)isFlipped
{
return YES;
}
- (void)drawRect:(NSRect)rect
{
[self lockFocus];
// Erase the background.
[[NSColor whiteColor] set];
[NSBezierPath fillRect:rect];
[tile drawRect:rect];
[self unlockFocus];
}
- (void)drawRect:(NSRect)rect
{
if (! valid) [self drawOffscreen];
valid = YES;
[image drawAtPoint:frame.origin fromRect:bounds
operation: NSCompositeSourceOver fraction: 1.];
}
- (void)drawOffscreen
{
[NSGraphicsContext saveGraphicsState];
[image lockFocus];
// Render title.
[titleString drawWithRect:titleRect
options:NSStringDrawingUsesLineFragmentOrigin
attributes:labelAttributes];
[image unlockFocus];
[NSGraphicsContext restoreGraphicsState];
}
On Jan 30, 2007, at 12:28 PM, Matt Neuburg wrote:
On Sun, 28 Jan 2007 22:38:51 -0500, Dave Fernandes
<email@hidden> said:
I have
an NSView with a flipped coordinate system. I draw text and bezier
paths into an NSImage with a flipped coordinate system. And then I
composite the image into the view.
Problem: the graphics look fine, but the text is upside-down.
I understand the poster's workaround to the problem, but I am hoping
someone has a more elegant solution. Is there anyway to get a non-
flipped graphics context when I draw my image?
Straight from the docs:
NSAffineTransform* t = [NSAffineTransform transform];
[t translateXBy: 0.0 yBy: [im size].height];
[t scaleXBy: 1.0 yBy: -1.0];
[NSGraphicsContext saveGraphicsState];
[t concat];
// draw here
[NSGraphicsContext restoreGraphicsState];
More that, without seeing your code, is hard to say. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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