Cropped Italic Letters
Cropped Italic Letters
- Subject: Cropped Italic Letters
- From: Jesse Abram <email@hidden>
- Date: Wed, 23 Feb 2005 00:05:09 -0800
I am currently working through Cocoa Programming For Mac OS X 2nd
Edition, and I've encountered a problem while working on an exercise
program. When I display an italic character in my view object, (nowhere
near the edges), it is drastically cropped on the righthand side. The
characters have a shadow as well, which is cropped slightly even when
the text is not italic. I've pasted some of my code here, if anyone
knows why this is happening, I would be very happy to hear.
Thanks!
Jesse
- (void)drawRect:(NSRect)rect
{
NSRect bounds = [self bounds];
[bgColor set];
[NSBezierPath fillRect:bounds];
[self drawStringCenteredIn:bounds];
// Am I the window's first responder?
if ([[self window] firstResponder] == self) {
[[NSColor keyboardFocusIndicatorColor] set];
[NSBezierPath setDefaultLineWidth:4.0];
[NSBezierPath strokeRect:bounds];
}
}
- (void)drawStringCenteredIn:(NSRect)r
{
NSPoint stringOrigin;
NSSize stringSize;
stringSize = [string sizeWithAttributes:attributes];
stringOrigin.x = r.origin.x + (r.size.width -
stringSize.width)/2;
stringOrigin.y = r.origin.y + (r.size.height -
stringSize.height)/2;
[string drawAtPoint:stringOrigin withAttributes:attributes];
}
- (void)prepareAttributes
{
NSShadow *shadow = [[NSShadow alloc] init];
NSFont *font = [NSFont fontWithName:@"Helvetica" size:75];
NSFont *tempFont;
NSFontManager *fontManager = [NSFontManager sharedFontManager];
if(bold)
{
tempFont = font;
font = [fontManager convertFont:font
toHaveTrait:NSBoldFontMask];
[tempFont release];
}
if(italic)
{
tempFont = font;
font = [fontManager convertFont:font
toHaveTrait:NSItalicFontMask];
[tempFont release];
}
NSSize size;
size.width = 5.0;
size.height = 5.0;
[shadow setShadowOffset:size];
[shadow setShadowBlurRadius:0.0];
[shadow setShadowColor:[NSColor blueColor]];
attributes = [[NSMutableDictionary alloc] init];
[attributes setObject:font
forKey:NSFontAttributeName];
[attributes setObject:[NSColor redColor]
forKey:NSForegroundColorAttributeName];
[attributes setObject:shadow
forKey:NSShadowAttributeName];
[shadow release];
[font release];
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden