• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSStringAdditions drawAtPoint
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSStringAdditions drawAtPoint


  • Subject: Re: NSStringAdditions drawAtPoint
  • From: Gerard Iglesias <email@hidden>
  • Date: Fri, 29 Jun 2001 23:29:38 +0200

On Friday, June 29, 2001, at 11:36 , Stiphane Sudre wrote:

> On jeudi, juin 28, 2001, at 11:33 PM, Tom Waters wrote:
>
>> Is there a bug in NSStringAdditions drawAtPoint: withAttributes:?
>
> I confirm the problem. I faced it while writing a ScreenSaver.

The turnaround is to use NSAffineTransform to set the local referential
for your text drawing, it will work:

NSString * string = @"Hello World";
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont fontWithName:@"Helvetica" size:24],
NSFontAttributeName,
[NSColor blueColor],
NSForegroundColorAttributeName,
nil];
NSSize strSize = [string sizeWithAttributes:dict];
NSPoint origin = {0,0};
NSPoint strCenter = NSMakePoint(strSize.width/2.0, strSize.height/2.0);
NSRect strRect = NSMakeRect(-strSize.width/2.0, -strSize.height/2.0,
strSize.width, strSize.height);
NSAffineTransform * tr = [NSAffineTransform transform];

[NSGraphicsContext saveGraphicsState];
[tr translateXBy:70 yBy:80];
[tr rotateByDegrees:30];
[tr scaleXBy:0.75 yBy:0.75];
[tr concat];

[[NSColor redColor] set];
[NSBezierPath strokeLineFromPoint:NSMakePoint(0,-10)
toPoint:NSMakePoint(0,10)];
[NSBezierPath strokeLineFromPoint:NSMakePoint(-10,0)
toPoint:NSMakePoint(10,0)];

[NSBezierPath strokeRect:strRect];
[NSGraphicsContext restoreGraphicsState];

[NSGraphicsContext saveGraphicsState];
[tr translateXBy:-strSize.width/2.0 yBy:-strSize.height/2.0];
[tr concat];
[string drawAtPoint:origin withAttributes:dict];
//[string drawInRect:strRect withAttributes:dict];

[NSGraphicsContext restoreGraphicsState];

<Attachment missing>

As you can see, not a lot of C code in this example, could be
intersting...


--
email@hidden
Ph.D. in Computer Graphics MacOS X-Cocoa to have fun
Project manager at www.visiotics.com Win32/MFC to eat


References: 
 >Re: NSStringAdditions drawAtPoint (From: Stéphane Sudre <email@hidden>)

  • Prev by Date: Initializing a string with an NSData
  • Next by Date: Re: Custom drawing and cacheing
  • Previous by thread: Re: NSStringAdditions drawAtPoint
  • Next by thread: Intercept Option-Close?
  • Index(es):
    • Date
    • Thread