NSString drawAtPoint under non-identity CTM doesn't draw anything
NSString drawAtPoint under non-identity CTM doesn't draw anything
- Subject: NSString drawAtPoint under non-identity CTM doesn't draw anything
- From: brianw <email@hidden>
- Date: Mon, 18 Mar 2002 10:25:06 -0800
I wonder if anyone else has run into this little problem:
I have my own coordinate system and use an NSAffineTransform to map my
coordinate system to the native one. This works just fine for graphical
objects, but I get no output from NSString drawAtPoint. Here is
example code snippet who started out life as the Simple Draw example in
Appendix A of O'Reilly's "Learning Cocoa":
#import "MyView.h"
#ifndef min
#define min(x,y) (((x) < (y)) ? (x) : (y))
#endif /* min */
@implementation MyView
-(BOOL)isFlipped
{
return YES;
}
-(id)initWithFrame:(NSRect)frame
{
[super initWithFrame:frame];
[self setString: @"Hello World"];
[self setFont: [NSFont systemFontOfSize: 36]];
return self;
}
-(void)setString:(NSString*) value
{
[string autorelease];
string = [value copy];
[self setNeedsDisplay: YES];
}
-(void)setFont:(NSFont*)value
{
[font autorelease];
font = [value retain];
[self setNeedsDisplay: YES];
}
-(void)drawRect:(NSRect)rect
{
NSRect myBounds = [self bounds];
NSRect viewBox = { {0, 0}, {myBounds.size.width*3.0,
myBounds.size.height*3.0}};
NSMutableDictionary* attrs = [NSMutableDictionary dictionary];
NSAffineTransform* viewBoxTransform = [NSAffineTransform transform];
float scale = min(myBounds.size.width/viewBox.size.width,
myBounds.size.height/viewBox.size.height);
NSAffineTransformStruct transformStruct =
{
scale, 0, 0, scale, 0, 0
};
[viewBoxTransform setTransformStruct:transformStruct];
[[NSColor colorWithDeviceRed:0 green:1.0 blue:0 alpha:0.5]set];
[attrs setObject:font forKey:NSFontAttributeName];
// uncomment-out these three lines to use my coordinates
[viewBoxTransform concat];
[NSBezierPath fillRect:NSMakeRect(viewBox.size.width/2.0, 5, 200,
200)];
[string drawAtPoint: NSMakePoint((viewBox.size.width/2.0), 5)
withAttributes:attrs];
// uncomment-out these two lines to use default coordinates
// [NSBezierPath fillRect:NSMakeRect(myBounds.size.width/2.0, 5, 200,
200)];
// [string drawAtPoint: NSMakePoint((myBounds.size.width/2.0), 5)
withAttributes:attrs];
}
@end
As shown here, you'll see a transparent green rectangle and nothing
else. If you uncomment-out the lower two lines, you'll see the green
rectangle and the usual "Hello World" text (writ large).
Am I'm doing something wrong? Or is this a bug?
Thanks for any help.
Regards,
Brian Wing.
SchemaSoft.
_______________________________________________
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.