Bug with NSAffineTransform and NSAttributedString?
Bug with NSAffineTransform and NSAttributedString?
- Subject: Bug with NSAffineTransform and NSAttributedString?
- From: Dix Lorenz <email@hidden>
- Date: Tue, 16 Sep 2003 16:05:06 +0200
Hi,
I am trying to draw a very simple tablike view, which can be either
horizontal or vertical. horizontal works fine, but vertical gives me
problems. I am pretty sure my transformations are correct, as the
drawing of the tab is correct. But the string is not quite correct.
When the View is a lot taller than wide, the string simply vanishes.
When it is a lot wider than tall, part of the string isn't being drawn,
it seems to be clipped. The wider I make the view, the more of the
string vanishes, sort of creeping in from the left.
Are there any known problems? I don't do any fancy clipping, and when I
draw the Rect where I think the string should be, it is exactly where I
want it to be. drawAtPoint or drawInRect doesn't make a difference. Or
is there a bug in my code? I've included the views "drawRect:", it is
self-contained (except for "vertical", which is a BOOL) if somebody
wants to try for him- or herself.
Thanks,
Dix
- (void)drawRect:(NSRect)aRect
{
NSRect frameRect = [self bounds];
frameRect.size.height -= 1.0;
frameRect.size.width -= 1.0;
float frameWidth = frameRect.size.width;
float frameHeight = frameRect.size.height;
NSAffineTransform *theTransform = [NSAffineTransform transform];
[NSGraphicsContext saveGraphicsState];
if (vertical) {
[theTransform rotateByDegrees:90.0];
[theTransform translateXBy:0.5 yBy:-0.5-frameRect.size.width];
frameWidth = frameRect.size.height;
frameHeight = frameRect.size.width;
frameRect.size.height = frameHeight;
frameRect.size.width = frameWidth;
} else {
[theTransform translateXBy:0.5 yBy:0.5];
}
[theTransform concat];
float capWidth = frameWidth * 0.1;
NSBezierPath *thePath = [NSBezierPath bezierPath];
[thePath moveToPoint:NSMakePoint(0.0, frameHeight)];
[thePath lineToPoint:NSMakePoint(capWidth, 0.0)];
[thePath lineToPoint:NSMakePoint(frameWidth - capWidth, 0.0)];
[thePath lineToPoint:NSMakePoint(frameWidth, frameHeight)];
[thePath lineToPoint:NSMakePoint(0.0, frameHeight)];
[[NSColor greenColor] set];
[thePath fill];
[[NSColor blackColor] set];
[thePath stroke];
[thePath addClip];
float textvOffset = frameHeight * 0.1;
float texthOffset = capWidth * 1.1;
NSRect stringFrame = NSMakeRect(
texthOffset, textvOffset,
frameWidth - 2 * texthOffset, frameHeight - 2 * textvOffset);
NSLog(@"stringFrame: %@", NSStringFromRect(stringFrame));
NSAttributedString *theLabel = [[[NSAttributedString alloc]
initWithString:@"Test"
attributes:[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont fontWithName:@"Helvetica" size:stringFrame.size.height*0.9],
NSFontAttributeName,
0]] autorelease];
NSSize theStringSize = [theLabel size];
NSRect theStringRect = NSMakeRect(0.0, 0.0, theStringSize.width,
theStringSize.height);
theStringRect.origin.x = stringFrame.origin.x +
(stringFrame.size.width - theStringSize.width) / 2;
theStringRect.origin.y = stringFrame.origin.y +
(stringFrame.size.height - theStringSize.height) / 2;
[theLabel drawAtPoint:theStringRect.origin];
NSFrameRect(theStringRect);
}
_______________________________________________
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.